I made a Java Application using NetBeans and I cleaned/built it my project in order to have it ready to use.
So I tried using Launch4j and it really helped me a lot, a really nice piece of software. My app uses 2 external .jars and I know that I need to specify the classpath of these .jars in the "Classpath" tab to make the project work perfectly. It works on my computer with no problems.
The thing is that it doesn't work if I want to test it on a different PC and Im guessing its because the app cant find the classes that are within the external .jars having the "AWT-EventQueue-0" java.lang.NoClassDefFoundError:" error messages.
So Im forced to transfer these jars files to the other PC and modify the XML file depending on where I copy/paste them.
So how can I resolve this if I want to share my app to my friends avoiding the transfer process of these jars files?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
These external library jars are needed, as they are not included in the execuatble built by launch4j. But you don't need to modify the XML every time, instead you have to use relative paths to these jars, so that it doesn't matter in which folder the application is installed. For example:
You could also use a dynamic classpath that is relative, like this: <cp>./lib/*.jar</cp>
As an alternative, you can create a jar manifest where the classpath is specified instead of using the launch4j classpath option. It also has to be relative. In the launch4j.jar it looks as follows:
Maybe Im doing something wrong because I can't get it to work my project.
Once I write my output file name and selecting my X.jar file, I go to the Classpath tab, from there, I click the "Custom classpath" so, in the "Main Class" box I select again my X.jar file, when I do that, down below I see my external jars that have the default path:
lib/Y.jar
lib/Z.jar
So I edit them like you suggested down below in the "Edit item" box, like this:
./lib/Y.jar
./lib/Z.jar
And I still have the error messages "AWT-EventQueue-0" java.lang.NoClassDefFoundError".
Can you post your configuration file and the outpout of yourapp.exe --l4j-debug ?
One thing you could also try is not to define the classpath at all, since you are prefilling the classpath from the jar I assume you have the mainclass and classpath defined there.
Grzegorz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did what you suggested not defining at all the classpath but I still have the same error output.
I'm attaching the configurationFile.XML and the output file.txt
When you give someone the application how does the folder structure look like? Where is the application and where are the libraries? Also run your application like this: App.exe --l4j-debug
and attach launch4j.log. The only thing that comes to my mind is that the libraries are not on the classpath specified.
Grzegorz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was just testing the App.exe on the other PCs, I wasn't including any other files. I thought that just using the executable, the app would work on other computers since the main jar has inside of it the ext. libraries.
I was trying to run my app on my PC editing the path of my external jars like you suggested using:
./lib/Jar1.jar
or
./*.jar
but it doesn't work. When it works, is when the paths are edited like this:
Were would the ext libary jars come from in the application jar? I think this is the problem. Launch4j does not put the libraries in the output executable. If you did that yourself I think you need a custom class path loader to handle such a situation. You should ship you exe and the libraries with it. Have a look at the launch4j directory, you'll see there the jar and the lib folder which has all the needed libraries. Then have a look at the launch4j.jar manifest. This is configured with relative paths, no matter in which folder you put it it'll work. You should try to do something similar.
Grzegorz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
I made a Java Application using NetBeans and I cleaned/built it my project in order to have it ready to use.
So I tried using Launch4j and it really helped me a lot, a really nice piece of software. My app uses 2 external .jars and I know that I need to specify the classpath of these .jars in the "Classpath" tab to make the project work perfectly. It works on my computer with no problems.
The thing is that it doesn't work if I want to test it on a different PC and Im guessing its because the app cant find the classes that are within the external .jars having the "AWT-EventQueue-0" java.lang.NoClassDefFoundError:" error messages.
So Im forced to transfer these jars files to the other PC and modify the XML file depending on where I copy/paste them.
So how can I resolve this if I want to share my app to my friends avoiding the transfer process of these jars files?
Hi,
These external library jars are needed, as they are not included in the execuatble built by launch4j. But you don't need to modify the XML every time, instead you have to use relative paths to these jars, so that it doesn't matter in which folder the application is installed. For example:
File structure:
app.jar
lib/
lib/looks.jar
Config:
<classPath mainClass="org.demo.DemoApp">
<cp>./lib/looks.jar</cp>
</classPath>
You could also use a dynamic classpath that is relative, like this: <cp>./lib/*.jar</cp>
As an alternative, you can create a jar manifest where the classpath is specified instead of using the launch4j classpath option. It also has to be relative. In the launch4j.jar it looks as follows:
Class-Path: . ./lib/commons-beanutils.jar ./lib/commons-logging.jar ./
lib/formsrt.jar ./lib/foxtrot.jar ./lib/jgoodies-common.jar ./lib/jgo
odies-forms.jar ./lib/jgoodies-looks.jar ./lib/xstream.jar
--Grzegorz
Thank you so much for your reply!
Maybe Im doing something wrong because I can't get it to work my project.
Once I write my output file name and selecting my X.jar file, I go to the Classpath tab, from there, I click the "Custom classpath" so, in the "Main Class" box I select again my X.jar file, when I do that, down below I see my external jars that have the default path:
lib/Y.jar
lib/Z.jar
So I edit them like you suggested down below in the "Edit item" box, like this:
./lib/Y.jar
./lib/Z.jar
And I still have the error messages "AWT-EventQueue-0" java.lang.NoClassDefFoundError".
I modified the XML file like this:
<classPath>
<mainClass>jjilexample.Main</mainClass>
<cp>./lib/*.jar</cp>
</classPath>
or like this:
<classPath>
<mainClass>jjilexample.Main</mainClass>
<cp>./lib/Y.jar</cp>
<cp>./lib/Z.jar</cp>
</classPath>
And I still have the same results, it doesn't work for me. I'm very sorry if Im asking for help to something that is really basic.
When I use it on my PC, my external jars have these paths:
and my app works fine, because if I edit them using just ./lib or ./lib/*.jar it doesn't work.
Can you post your configuration file and the outpout of yourapp.exe --l4j-debug ?
One thing you could also try is not to define the classpath at all, since you are prefilling the classpath from the jar I assume you have the mainclass and classpath defined there.
Grzegorz
Thank you again for your reply!
I did what you suggested not defining at all the classpath but I still have the same error output.
I'm attaching the configurationFile.XML and the output file.txt
When you give someone the application how does the folder structure look like? Where is the application and where are the libraries? Also run your application like this: App.exe --l4j-debug
and attach launch4j.log. The only thing that comes to my mind is that the libraries are not on the classpath specified.
Grzegorz
I was just testing the App.exe on the other PCs, I wasn't including any other files. I thought that just using the executable, the app would work on other computers since the main jar has inside of it the ext. libraries.
I was trying to run my app on my PC editing the path of my external jars like you suggested using:
./lib/Jar1.jar
or
./*.jar
but it doesn't work. When it works, is when the paths are edited like this:
C:\Users\user\Documents\NetBeansProjects\JJIL_Disertacion\dist\lib\Y.jar
C:\Users\user\Documents\NetBeansProjects\JJIL_Disertacion\dist\lib\Z.jar
Othewise it doesnt work.
This is the first time I want to share an application to my friends so maybe Im doing something wrong or forgetting something...
Im attaching the .log file and the XML file.
Thank you for your reply
Were would the ext libary jars come from in the application jar? I think this is the problem. Launch4j does not put the libraries in the output executable. If you did that yourself I think you need a custom class path loader to handle such a situation. You should ship you exe and the libraries with it. Have a look at the launch4j directory, you'll see there the jar and the lib folder which has all the needed libraries. Then have a look at the launch4j.jar manifest. This is configured with relative paths, no matter in which folder you put it it'll work. You should try to do something similar.
Grzegorz
It worked! thank you for all your help and patience.