Lately I had to build a executable jar with many other dependencies jars; Failed with 2 solutions, same as Simon Tuffs, then I decided to use what he offered, the OneJar.
Copy and paste the follow code snippet to build onejar and execute the one jar file; Dont forget to edit main jar file location and lib jar file locations to fit the main Ant build
Thanks Simon Tuffs!
Ant build xml in Gist
More Example: http://one-jar.cvs.sourceforge.net/viewvc/one-jar/one-jar-log4j/
Other Ref:
http://j2stuff.blogspot.com/2011/07/onejava-example.html
Here are the Steps used in Mac 10.10, Eclipse IDE 3.7
Ref: http://obscuredclarity.blogspot.com/2011/05/java-one-jar-example-using-ant-and.htmlOne time OneJar Load in IDE
- Downloaded one-jar-ant-task-0.97.jar
- Copied the file into /Applications/Eclipse/plugins
- In Eclipse IDE (3.7), Preferences -> Ant -> Runtime, in right side window, click on 'Ant Home Entries (Default)'; Then use 'Add External JARs...' to add the newly added one-jar-ant-task jar file.
Ant Build Changes
NOTE: Assuming the project build is successful, and you have to create the new exec bundled onejarCopy and paste the follow code snippet to build onejar and execute the one jar file; Dont forget to edit main jar file location and lib jar file locations to fit the main Ant build
<taskdef name="one-jar" classname="com.simontuffs.onejar.ant.OneJarTask" onerror="report" />
<target name="onejar" depends="jar">
<!-- Construct the One-JAR file -->
<one-jar destfile="${ant.project.name}Exec.jar">
<manifest>
<attribute name="One-Jar-Main-Class" value="${main-class}"/>
</manifest>
<main jar="${ant.project.name}.jar" />
<lib>
<fileset dir="${lib.dir}" />
</lib>
<fileset dir="${src.dir}" includes="log4j.properties"/>
<fileset dir="${src.dir}" includes="log4j.properties"/>
</one-jar>
</target>
<target name="run onejar" depends="onejar">
<java jar="${ant.project.name}Exec.jar" fork="true" />
</target>Thanks Simon Tuffs!
Ant build xml in Gist
More Example: http://one-jar.cvs.sourceforge.net/viewvc/one-jar/one-jar-log4j/
Other Ref:
http://j2stuff.blogspot.com/2011/07/onejava-example.html
No comments:
Post a Comment