Results 1 to 6 of 6
- 07-24-2009, 05:50 PM #1
Member
- Join Date
- Jul 2009
- Location
- Rolesville, North Carolina
- Posts
- 16
- Rep Power
- 0
Packaging all files into a single executable .jar
Ok, my problem is simply this. When I write even a simple program, netbeans gives me an executable .jar file along with another folder containing a couple more .jar files. Is there any way for me to package all these files/folders into on .jar file that will still run just by being double clicked?
Thanks.if (ichwar == offline) {
System.out.println("ichwar is busy");}
- 07-25-2009, 03:23 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I hope those addition jar files are layouts, in lib folder is it? Actually in that what i'm doing is build another jar file including that lib folder in my final jar. Most of the time I use the same folder structure in distribution.
- 07-26-2009, 02:46 AM #3
Yes, there is a way to do it. I used to add a couple lines to netbean's build script which did this automatically, sadly it no longer works and I have yet to find out exactly why. Prior to netbeans 6.5.x, you could add the following:
to Netbeans/harness/build.xmlJava Code:<target name="-post-jar"> <jar update="true" destfile="${dist.jar}"> <zipfileset src="${libs.swing-layout.classpath}"/> </jar> </target>
When this started failing, I went back to a bash shell script I wrote ages ago, which I have included below. Feel free to modify it (you'll have to unless you keep all your stuff in exactly the same folders I do).
You can however do the steps manually -- all the jar tools are included with the JDK, you can type them into the command line one by one.Java Code:#!/bin/sh cd ~/Programming/NetBeansProjects/ echo "Enter Project name" read PROJ echo "Enter Package Name" read PKG echo "Enter Main class name" read MAIN cd $PROJ/dist rm -r /tmp/rejar/ mkdir /tmp/rejar/ cp -r * /tmp/rejar/ cd /tmp/rejar/ mv lib/swing-layout-1.0.3.jar lib/swing.zip unzip lib/swing.zip rm -r lib rm -r META-INF mv $PROJ".jar" wg.zip unzip wg.zip echo "Main-Class: "$PKG"."$MAIN > META-INF/MANIFEST.MF rm README.TXT rm wg.zip jar -cmf META-INF/MANIFEST.MF $PROJ".jar" * mv $PROJ".jar" ~/Desktop/ rm -r /tmp/rejar echo "Re-Jar'ing is complete, new .jar is on Desktop."
Last edited by quad64bit; 07-26-2009 at 02:49 AM.
- 07-27-2009, 08:36 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I agreed, as far as I know that option didn't workout in NetBeans 6.5. So what we can do is keep the same structure in distribution or build a single jar file manually.
- 01-26-2010, 11:41 PM #5
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Here are some Ant targets to do this
I stumbled on this thread when googling the same problem. Here are the custom Ant targets I use for this:
For more info, see my blog post on the matter.Java Code:<target name="-unjar-and-copy-lib-jars"> <unjar dest="${build.classes.dir}"> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> <patternset> <exclude name="META-INF/**"/> <exclude name="/*"/> </patternset> </unjar> </target> <target depends="init,compile,-pre-pre-jar,-pre-jar,-unjar-and-copy-lib-jars" name="fat-jar"> <property location="${build.classes.dir}" name="build.classes.dir.resolved"/> <jar destfile="${dist.jar}"> <fileset dir="${build.classes.dir}"/> <manifest> <attribute name="Main-Class" value="${main.class}"/> </manifest> </jar> <echo>To run this application from the command line without Ant, try:</echo> <property location="${dist.jar}" name="dist.jar.resolved"/> <echo>java -jar "${dist.jar.resolved}"</echo> </target> <target depends="clean,fat-jar" name="clean-and-fat-jar"/>
- 01-27-2010, 01:31 AM #6
Thanks for the post! This is a problem I had ages ago too - hence my script. I've found that in the current versions (java 1.6 and NetBeans 6.8) the separate swing layout libraries are no longer included in the build and that the layout that was used (was it groupLayout?) is now included in the JDK for 1.6. However, unless I rebuild my old gui projects from scratch, netbeans continues to use the old separate swing layout library. Thanks for the post!
I was really irritated when my modifications to the ant build script just stopped working after 6.5 and honestly don't know anything about writing ant build scripts from scratch (or modifying them to any great degree!).
Similar Threads
-
About Executable JAR files
By paluee in forum New To JavaReplies: 4Last Post: 03-31-2009, 07:03 PM -
Merged TIF file size is more larger than the sum of single TIF files
By subrahmanyam.adapa in forum Advanced JavaReplies: 3Last Post: 01-26-2009, 01:19 PM -
executable files
By akinpam in forum Advanced JavaReplies: 10Last Post: 01-06-2009, 04:01 AM -
Packaging and accessing data files
By todd in forum Advanced JavaReplies: 1Last Post: 08-01-2007, 12:27 AM -
File Upload - Single to allow the search of .txt files
By Daniel in forum Advanced JavaReplies: 1Last Post: 06-06-2007, 04:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks