I have a Java application and a build file which, among its tasks, has one task to create a jar file from the application and one to run the application
<!-- ===== Create An Executable Jar target ======-->
<target name="jar-task" depends="compile-task">
<mkdir dir="${jar.dir}"/>
<jar destfile="jar/Guix.jar" basedir="${gui_bin.dir}">
<fileset dir="${basedir}">
<include name="img/**/" />
</fileset>
<manifest>
<attribute name="Main-Class" value="sys.deep.cepu.Start"/>
</manifest>
<filelist dir="${basedir}" files="user.properties"/>
</jar>
</target>
<!--
============ Run target ===================
-->
<target name="run-task" depends="jar-task">
<java classpath="${basedir};jar/Guix.jar;CK-DASP-2.0.0.jar;library/*;user.properties;img/* " classname="sys.deep.cepu.Start" fork="true">
</java>
</target>
The build file runs perfectly, the jar is created and the application runs. I would like to allow the user to start the application by clicking on a single file (jar or batch file). I tried to click on the generated executable jar file but nothing happens. Is it normal? Can someone give me an help on how to execute the program from this jar or from a batch file? Thanks!
Alternate ways to run a jar file
java -jar jar-file
java -cp jar-file MainClassNameFullyQualified
When building you jar file you already specify the
Main-Class
. But you did not specify the required libraries in the manifest file, only in the ant file when running the application.Write another manifest attribute into the ant-file. The
name
should beClass-Path
, the value a space separated list of libraries. Look here (Wikipedia) for an example.After that your application should start when entering
Then follow the step described in this question to make it startable with a double click.
Yes, this is normal. You have to start it from command line or via batch script. Try using as a batch script (if you have a MANIFEST.MF) added to your jar.
or otherwise: