NetBeans-generated JAR Doesn't Run Outside the IDE
A java program Calculator which I've developed, and which runs flawlessly within NetBeans IDE 4.1, creates a JAR file in the /dist directory as expected. The resulting created file has location .../dist/Calculator.jar. Now, when I click on the Calculator.jar file, nothing happens, i.e. it doesn't run. Inspection of the file with WinZip shows the system-built manifest.mf file which contains the line, Main-Class: Calculator as expected. This class, incidentally, has a main method.
Does anyone know why the distribution JAR file created by NetBeans IDE 4.1 for a file that executes within the IDE doesn't run when opened or double-clicked on?
The curious thing is, another program which had its distribution JAR file created by NetBeans IDE 4.1 when clean and build is run does run when double-clicked. ?
Any suggestions would be appreciated.
I admit that I never managed to create a jar file that is really "executable".
Therefor I currently use exe4j to create the executable.
exe4j is trialware. Its use is not time limited (Evaluation warnings are removed after
purchasing an exe4j license for 69$).
I did not purchase an exe4j license : the evaluation warning does
not disturb me. Using the "slpashscreen"-option, I even don't have to
click on a button to pass the warning message.
If you have any problem using exe4j please tell me.
Hope this helps.
Download :
http://www.ej-technologies.com/download/exe4j/files.php
Here is an example how I use exe4j :
1. Welcome: Next
2. Project type: Next
3. Application Info:
Short name of your application:
any name you like
for example: testjar
Distribution source directory:
project folder
for example: C:\Documents and Settings\Uhres Andr閈NetBeansProjects\TestJar
Next
4. Executable Info:
Executable name:
any name you like
for example: TestJar
Next
5. Java invocation:
Class path:
the path to your jar file
for example: .\dist\TestJar.jar
Main class:
after you specified "Class path", what you just did,
you only have to click on ... to discover the project's main classes.
Select the class that should start first and click "OK"
for example: jardemo.TestJar
Next
6. JRE:
Java version:
Minimum version: 1.5
Advanced options: Search sequence
+
Directory
...
..\..\..\..\Program Files\Java\jdk1.5.0_03
select it and move to top using arrow button
Next
Preferred VM: Next
7. Splash screen:
General: Show slpash screen
...
select any image file you like
for example: C:\Program Files\Java\jdk1.5.0_03\jre\lib\images\cursors\win32_MoveDrop32x32.gif
Finish
Finished:
Click here to start the application
Exit
Yes
type any name for your executable (for example: TestJar)
Save
an information message tells you where the exe4j file is placed
for example: C:\Documents and Settings\Uhres Andr閈NetBeansProjects\TestJar\TestJar.exe4j
The same folder contains your exe file (for execution outside of NetBeans)
If you want to copy your *.exe file to an other folder, you must also copy the "dist" folder containing the *.jar file
> Does anyone know why the distribution JAR file
> created by NetBeans IDE 4.1 for a file that executes
> within the IDE doesn't run when opened or
> double-clicked on?
>
Try executing the jar from the command line - it should give you an error message if it doesn't run. The command would be something like "java -jar Calculator.jar"
First, clean and rebuild the project - then click the jar.
If that doesn't help, then
1) Check the source files, do they have a package statement? (If they do, then the source files should also be in a directory structure under the "src" directory that corresponds to the package statement.)
2) Use WinZip to examine the Manifest.mf file. It should have a line
Main-Class: <package name.><class name>
Where <package name> is what was specified in the package statement, and <class name> is the name of the class that contains
the public static void main(String[] args) method.
(I have seen once or twice where the Main-Class was out of date (probably due to my changes) and a clean/rebuild corrected it.)
Also make sure that the project's main class is set - goto project properties | run | main class.
Your advice is certainly valuable and correct. As for me, I continue to prefer
exe4j because it is extremel easy to use and you can test the results
even without leaving the tool. So, if something is wrong you see it at once
and you can correct the error easily, all in the same tool.
Nevertheless I have tried again to create an executable JAR file based on
your advice, but did not manage. In contrast, when I used exe4j for the very
first time, I experimented with the tool for an hour or so, to learn the possibilities.
After that I no longer had any problem to create an executable!!!
I followed your suggestion, downloaded the exe4j Windows XP program and used your information to create an executable from the distribution JAR. When I click on the executable, I receive the warning that the program was created with an evaluation version of the software, the program doesn't run, and I receive the following in an error.txt file that is created:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout
at my.calculator.pkg.Calculator.initComponents(Calculator.java:65)
at my.calculator.pkg.Calculator.<init>(Calculator.java:21)
at my.calculator.pkg.Calculator$38.run(Calculator.java:727)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Any suggestions?
Hello Java_Heaven.
Please open again the .exe4j file that you have created.
In the left panel, select "5. Java Invocation".
Click the green "+".
Click "..." ( near the "Archive:"-field ).
Select "..\..\..\..\Program Files\netbeans-4.1\ide5\modules\ext\AbsoluteLayout.jar"
"OK".
"Finish".
Click "Click here to start the application".
if it's OK, click "Exit", "Save", "OK".
If it's not yet OK, you don't need to leave the exe4j session,
you can fix all errors in one session !
As for the evaluation warning, see what I told you already in previous postings.
Best Regards
Andre
Your last assist worked like a charm. Thank you so much for all your help!
> I did not purchase an exe4j license : the
> evaluation warning does
> not disturb me. Using the "slpashscreen"-option, I
> even don't have to
> click on a button to pass the warning message.
TIP: If the warning message on the slpashscreen disturbs you,
you may choose an oversized picture (larger than screen size) and set it
as your splashscreen. In that case the warning message is hidden
because it is outside the visible area.