I just created a JAR file that contains external dependencies in it so that I would just have one JAR file. I did this by using FatJar. When I did this my Jar worked fine, and I was able to run it with no problems. Then I used ikvm to convert my Jar to an exe. When I try to run the exe I get this error:
Exception in thread "main" java.lang.IllegalArgumentException: Unable to locate
com.simontuffs.onejar.Boot in the java.class.path: consider using
-Done-jar.jar.path to specify the one-jar filename
So the first thing I thought of was to check if there was a Manifest file that specified the classpath. There was indeed a Manifest file and this was it's contents:
Manifest-Version: 1.0 Created-By: Fat Jar/One-JAR Eclipse Plug-In
Main-Class: com.simontuffs.onejar.Boot
I'm assuming this is correct because I'm able to run the JAR fine, and this was also created by FatJar.
I'm not really sure what to do next, and I'm not sure what -Done-jar.jar.path is. Anyone have a clue of what the problem may be?
I think the issue is that the ikvmc compiler isn't seeing the JAR files embedded within the single executable JAR file you are creating.
You probably want to treat the creation of a single executable JAR file and the creation of a single Windows exe as separate processes. The Fat Jar plugin will create an executable JAR for you with no problems.
To create a Windows exe you'll probably need a batch file or ant script which invokes ikvmc on your code, and all of the JAR dependencies. I think you can provide a list of JAR files to convert on the ikvmc command line, and tell it to produce a single exe as its output. This will probably give you what you want!
Related
I have created a jar file abc.jar. I want my jar to be converted to .exe file using the native-image command of graalvm. The jar needs some dependencies(external jars) to work.
So my command looks like:-
native-image -jar abc.jar output -cp "abc.jar;C:\lib\*"
The exe is generated and works on my machine. Nevertheless, when I ship it to a different matching and try to run the same it doesn't work unless I place all libs under C:\lib folder(the very same folder where I placed the external dependent jars). How can I create an executable with the jars included as part of exe file.
I tried the following specified in the documentation and no luck.
Regards.
How can i export a jar file in eclipse with libraries? Executable jar wont work for me so that is out of the question. There is no option to do that when i try to export it..
If the jar is not running try to run it using a CLI for example command prompt java -jar <name>.jar and see the errors.
When you export the .jar there are 3 options .
One and two produces the .jar with the libraries inside.
Third option is producing a .jar (executable) with the libraries added
a different folder[ which has the same name as the jar file and it
must be named like it].
Mention that:
You may have serious problems and your executable will not run if your application has duplicate entries. So most of the time the third bullet is the best solution.
Sample image:
If you are trying to create a .jar to add it as a library to other projects then you should follow the below:
I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html
I have a java desktop application in netbeans. I have created an executable jar file for the project using clean and build command provided by the netbeans. By using this command the executable jar file gets created under netbeansProjects//dist/.jar. I am able to execute this jar file from command line using java -jar .jar from within project path. But the problem is that when i move this jar outside of netbeans projects folder, say to desktop and run the jar file, it is giving error of type "Exception in thread "main" java.lang.NoClassDefFoundError". How to solve this problem and make the jar file executable from any location of the system.
Complete instructions may be found in dist/README.TXT:
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Ensure that the manifest inside of the jar file contains the necessary classpaths. If you are unfamiliar with the concept, go here: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Netbeans has probably included any external projects/libraries/Jars in the dist/lib folder.
In order to run the application, you must include all the files in the dist folder when you copy the application
Check if in your projects Manifest.mf file has the Attribute
"Main-Class" set to your projects current main Class file.
I used eclipse to create executable jar. It relies external other jars.
In Eclipse, It is simple that you just need to choose Extract required libraries into generated JAR.
You can create an executable jar. It can be executed any places where jre is installed.
But If I use command line to compile jar.
javac -classpath [external jars] *.java
jar cfm [a name].jar manifest *.class [external jars]
It can generate jar. But the jar can only be executed in the directory where it is produced.
If I put it into another directory or machine, it complains NoClassDefFoundError.
So, my question is that how I can generate executable jar using command line as Eclipse.
A jar file cannot have its dependency jars inside. In case of Eclipse, it will unpack all the classes from the dependency jars and will bundle it into your single jar along with your class files. If not in the eclipse way, you need to
1) Create a manifest file which lists all the dependency jars
Manifest-Version: 1.0
Main-Class: Your Main class
Class-Path: dependency1.jar dependency2.jar dependency3.jar
dependency4.jar dependency5.jar
2) Create your jar with your class files using the class path including all the dependency jars and using the above created mainfest file.
3) In this same folder where you created your jar, place all the dependency jars.
Now your folder will look like this,
yourjar.jar (With the manifest file you created above)
dependency1.jar
dependency2.jar
dependency3.jar
dependency4.jar
dependency5.jar
4) Now if you want to share this, you need to share this folder and you can launch your jar from this folder. This is your executable folder and you can run it from anywhere.
Eclipse use Ant to package jar file, you can save the ant script that eclipse use to generate the jar checking the checkbox Save Ant File in the export window :
so, you can generate the Ant Build.xml script and then execute it using ant directly from the command line without using eclipse anymore if you want.
My preferred method for creating an executable jar is to use a utility called one-jar. I have a blog post discussing how to use it in maven and ant: my one jar blog post