Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
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 6050 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.

music and music apps:
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: 508
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.

music and music apps:
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.

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...

Julien Gouesse | Personal blog | Website | Jogamp
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  

Riven (463 views)
2019-09-04 15:33:17

hadezbladez (5322 views)
2018-11-16 13:46:03

hadezbladez (2249 views)
2018-11-16 13:41:33

hadezbladez (5597 views)
2018-11-16 13:35:35

hadezbladez (1164 views)
2018-11-16 13:32:03

EgonOlsen (4600 views)
2018-06-10 19:43:48

EgonOlsen (5474 views)
2018-06-10 19:43:44

EgonOlsen (3138 views)
2018-06-10 19:43:20

DesertCoockie (4033 views)
2018-05-13 18:23:11

nelsongames (4782 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 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‑
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!