Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Failure exporting runnable JAR [SOLVED]  (Read 1649 times)
0 Members and 1 Guest are viewing this topic.
Offline N1G3L2

Senior Newbie





« Posted 2012-07-28 22:53:40 »

Hi. In the process of learning Java I have mainly been making very simple programs. But now I actually have a project, still in progress, that I am very proud of so far. Anyways I would like to export it as a runnable JAR (its a game), but I seem to be failing to do so. What I do is, File> Export> Runnable JAR and this comes up:


and I click finish.. Seems pretty straightforward. I get a popup saying "JAR export finished without warnings" and everything seems good. But when I try to run it, I get this error: "Could not find the main class:...Program will exit"
I have searched a few forums with people having the same problem, but non of their solutions have seemed to work for me (or I am just doing something wrong). One thing I read is that it could be something with the Environment Variables path. I am aware of how to edit it, but I am not exactly sure what I would need to change (or if it even really matters). The program I am trying to export also uses images and reads info from a txt file. Not really sure if thats a big deal either. Also uses no external libraries or anything like that, just pure Java.

As you can probably tell I am a total n00b and if anyone can walk me through what I should do in the simplest possible way, I would really really appreciate it. Thanks people! =)
Offline Phased
« Reply #1 - Posted 2012-07-29 00:34:08 »

I Found this was a problem with suing the JDK 7, switch it back to 6, and it should be perfect Smiley

IF I remember right:

Right click your project > properties > Build (something,build path, build options something like that (just woke up))

then switch it back to JDK 6
Offline philfrei
« Reply #2 - Posted 2012-07-29 03:10:52 »

I don't recognize your IDE screen. (Not surprising, since I only know my version of Eclipse.) What IDE are you using?

I had a similar problem with Eclipse at first. In my version (now Indigo) there is a branch prior to the screen you are showing. At that branch I can choose either:

1) JAR file
2) Javadoc
3) Runnable JAR file

as the destination for the export.

I've NEVER been able to get the "Runnable JAR file" to work, but have had success with the first "JAR file" option. Since that works for me, I never bothered to get to the bottom of why the third option was failing.

After selecting "JAR file", there are requirements to specify the destination file location, and the opportunity to tree down into the project packages and click on the exact java files you wish to include.

The last big step (important!) is to specify which java file has the "main" that you want to run when the JAR is clicked. The screen you are showing doesn't give you the option, nor a "next" to go to. So that probably has something to do with why, when clicked, the JVM doesn't find a main(). There must be some expectation built into this "Runnable JAR" option that handles this, but I don't know what it is.

Anyway, if you can go back a step and export to JAR file rather than Runnable JAR file, you might have your solution.

And once that works for you, be warned that getting resources -- e.g., images -- to be included in the JAR is also a bit of a headache to get right the first time. But once you get it, you'll be good to go.

"It's after the end of the world! Don't you know that yet?"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-07-29 03:12:39 »

Watch out for Launch Configuration if it's your desired project. On Library Handling if you use any try option two, it mostly works although the jar will be fat. I always use this Runnable export and it works.

Offline N1G3L2

Senior Newbie





« Reply #4 - Posted 2012-07-29 03:20:48 »

I don't recognize your IDE screen. (Not surprising, since I only know my version of Eclipse.) What IDE are you using?

Im also using Indigo (Version: Indigo Service Release 1) but this is the Runnable JAR option so I guess thats probably why it doesn't look familiar. I did also try just exporting a regular JAR, and chose the option "Generate manifest file" and specified the main class, but still got the same error: cannot find main class.

I should also add that when I run it through the command line, everything loads fine
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-07-29 04:48:19 »

There is no point to even use Runnable Jar option. Just export as a normal JAR that has a Main-Class specified in its Manifest, which is set in the last screen of the wizard.

Offline philfrei
« Reply #6 - Posted 2012-07-29 06:15:29 »

Sorry my idea didn't help.
Probably someone at Eclipse can, though, if someone here doesn't come through first. I've had excellent help at the "Newcomers" forum.

http://www.eclipse.org/forums/


"It's after the end of the world! Don't you know that yet?"
Offline N1G3L2

Senior Newbie





« Reply #7 - Posted 2012-07-29 07:22:01 »

Sorry my idea didn't help.
Probably someone at Eclipse can, though, if someone here doesn't come through first. I've had excellent help at the "Newcomers" forum.

http://www.eclipse.org/forums/


That is an excellent idea I should have thought of that. Thank you I'll give it a try =)
Offline gouessej
« Reply #8 - Posted 2012-07-29 18:43:57 »

Using runnable fat JARs is a bad idea, I already explained that it can completely fail to run when WinRAR is installed for example...

Offline ReBirth
« Reply #9 - Posted 2012-07-30 02:08:44 »

The reason why I'm never fail it because I use 7zip, which leaves .jar untouched.

However sometimes fat jar export can be picky. You need to reference all libs even they're not used anymore. Sometimes I need to see the exported jar and remove them manually. But for simple use it's okay.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!