Netbeans 551: Include all libs in project jar file. Possible?

Is it possible to manually, or automaticly, include the /dist/lib directory into my "GonioLabt,jar" to make it more 'stand alone', file wise.
Netbeans generates this dist/README.TXT
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "GonioLab.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* If the classpath contains a folder of classes or resources, none of the
classpath elements are copied to the dist folder.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

Yes it is possible. The same question has been
killing me all day. Here is how I did it.
(I'm on Mac OS 10.4, but this should work anywhere)
Netbeans produces the following:
dist/myJar.jar
dist/lib/swing-layout-1.0.jar
I would prefer to have only:
dist/myJar.jar
But, as you know, myJar.jar requires the class files
stored in swing-layout-1.0.jar. I unpacked the jar
files and examined the manifest files. Here is how to
unpack and repack the jar files into a single jar
file:
First, I renamed myJar.jar to myJar.zip and let OS X
unarchive the jar for me. I did the same for
swing-layout-1.0.jar.
I then dropped the MANIFEST.MF file from
MyJar/META-INF/ into a new folder on my harddrive
Then, I dropped the package (its a folder full of
class files) from MyJar/ into the same new folder on
my harddrive.
At this point, the new folder contains:
/newFolder/MANIFEST.MF
/newFolder/myPackage/
Then, I grabbed /dist/lib/swing-layout-1.0/org/ and
dropped that into the new folder.
We now have in the new folder:
/newFolder/MANIFEST.MF
/newFolder/myPackage/
/newFolder/org/
Almost done:
Open the MANIFEST.MF file with a text editor. Mine
looked like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_07-87 ("Apple Computer, Inc.")
Main-Class: ohm.GUI
Class-Path: lib/swing-layout-1.0.jar
X-COMMENT: Main-Class will be added automatically by
build
I replaced the ENTIRE contents of the file with
this:
Manifest-Version: 1.0
Main-Class: myPackage/Main
Where 'myPackage' is the folder containing my class
files, and 'Main' is the class containing the
'main(String[] args) method.
Save the file and we're ready to repack the archive.
Open the command line (in OS X this is the Terminal)
I assume the syntax is the same in windoze; Navigate
to the new folder you created.
In OSX: cd /newFolder
in windoze: cd \newFolder
Then use java's jar command:
jar cmf MANIFEST.MF MyJar.jar *
What this does:
jar is the command. cmf are flags: the 'c' is for
creating a new jar archive, the 'm' is to specify a
premade manifest file, the 'f' tells jar to write the
results to a file. MyJar.jar is the name you have
chosen for the resulting .jar file. the '*' is a
wildcard character that tells jar to put every file
in the present working directory into the new .jar
Thats it! This produced myJar.jar which worked fine
by itself, as it included all the classes from
swing-layout-1.0.jar. It would be a trivial matter to
write a shell script to do all this for you, unless
of course you use something silly like windows, in
which case you'll have to write a batch file or use
python or something. Good luck, I hope this saves
others time, drop me a e-mail if this was at all
confusing! [email protected]
You should be aware that doing this may well violate the licensing terms for third-party libraries
By the way, what's silly about using Windows? Are you saying you don't develop for Windows because it's "silly"?

Similar Messages

  • How do I list all classes in a Jar file?

    How do I list all classes in a Jar file?

    Its no problem if the jar file contains classes, but I have an EAR file, which contains a jar-file, and I want to list all classes in that jar-file.
    I would like to do something like this:
    java.util.jar.JarFile jarfile = new java.util.jar.JarFile( new File("/meYear.ear"), true );
    java.util.jar.JarEntry jar = jarfile.getJarEntry( "myJar.jar" );
    // Cast it to a new JarFile:
    java.util.jar.JarFile newJar = (java.util.jar.JarFile)jar;
    But the method getEntry returns something like jarFile$JarEntry, if I try to class cast it I get an classCastException.

  • Referencing an image in my projects jar file

    I don't seem to be able to reference an image in my netbeans project. Here is what it looks like in netbeans:
    http://picasaweb.google.com/cendrizzi/JavaStuff/photo#5068570476760118770
    Here is my code that I'm using to reference one of these images:
                URL imageURL = this.getClass().getResource("images/clock.png");
                Image image = Toolkit.getDefaultToolkit().getImage(imageURL);I'm really new at this so I'm not sure what I'm doing wrong. I've tried "images/clock.png" as shown and just "clock.png" . Neither seems to find it there.
    Thanks!

    Since you provided a relative URL to the getResource method, you need to know that it is relative to the package of the class that called the method. So if your class was in package org.bananarama, you would be looking for the path /org/bananarama/images/clock.png in your jar file.
    If you wanted to look for the absolute path /images/clock.png then specify that absolute path.

  • Including a .jad and a .jar file in presentations

    Hi:
    I did an application using the last version of the Sun Java Wirelless Toolkit 2.5. And now I have a .jad file and a .jar file. I need to include both in a power point presentation to be able to show the application. I dont want to do a link because I'm not gonna use my computer to do the presentation. Do I need to do something special in the deployment step to be able to do this ?
    I have tried to include the program this;
    Insert --> Object
    But it doesn't work.

    Hey listen what you want to do is possible but not in the way you want to do...
    if you want to demonstrate the functionality of your application or how it works then you can use use
    any screen recording software such as: Screen Recorder Gold, Qarbon's Viewlet Builder or ViewletCam
    such software help you to record the activity of screen then you can export the recorded screen shots to multiple formats and include them to your PP presentation...

  • How to include images/icons for a jar file

    Hi,
    I need to create a jar file which will contain my application. My source code (.java) files are in "app" folder. I compiled that using javac -d . *.java and one package("appl") was created. I have all icons and images related to my application are in the folder named "icons" in the directory where source files are located i.e; app folder - "app/icons". I am accessing the images in the icons directory as "icons/book.gif".
    I created a jar file from source file directory with the option
    jar cvf app.jar app
    and i added this jar file to my classpath also.
    I have created a batch file to execute this application and set that batch file to "path" environment variable.
    It is running from any directory but no icons are appearing in that application if i try to run the application out side the "app" folder.
    Can any body give suggessions to solve this problem?

    Thanks for the added info, now let's get started.
    To use files in jars, you need to refer to them via a URL, so you'll need to modify your code a little bit first.
    URL imgURL = ClassLoader.getSystemResource("icons/BOOK.gif");
    setIconImage(Toolkit.getDefaultToolkit().getImage(imgURL));Next, you'll need a manifest. Using any text editor such as notepad, create a file called manifest.txt and put two lines in it. The first line will specify the class (w/o .class on the end) that contains your public static void main method, the second line is just an empty line (just press return).
    Main-Class: main
    (a blank line)
    Save this file with your class files (e.g. in Exam folder).
    Next build your jar. We want the jar to contain the package folder and your icon folder as well. So use this:
    jar cmf Exam/manifest.txt myJar.jar Exam/*.class icons
    And you should now have an executable jar. You can run it from dos with:
    java -jar myJar.jar
    or you can double-click it from windows.
    -Ron

  • Include command line args in jar file

    If I make and executable jar file, how can I make it so that when it runs certain comman line arguments are included

    If by "executable jar" you mean that you want to click the jar and run the program (and are using Windows), then you would have to alter the Windows file association for jar files that Java created, adding those options to the javaw command. Note that that would affect all jars that are run this was.
    If you're willing to use the "javaw -jar" command, then just add the options to the javaw command.

  • Import a BPM project .jar file in jedevloper

    Hi,
    Can we import a BPM .jar file in jdeveloper, to regenrate the underlying code. this jar is having the BPM and SOA code.
    << the actual case is to import the deployed BPM .jar file project in jdeveloper. >>
    thanks,
    rps

    You can unjar the file in your machine so that you have the source code.
    Create a new BPM Application (make sure you name the project & process similar to what you have in the JAR).
    After that copy & replace the unjared contents into the folder under <applicationName>/<projectName> except for <projectName>.jpr (since this is not in the jar).
    try opening it from Jdev .. I could compile using a similar approach and open the BPM process too.
    You would need to deploy and test the functionality to be sure that this works.

  • How to list all filename in excuteable jar file?

    Hi there,
    i've been googling around for hours, but found no good answer :(
    i want listing all file name in my excuteable jar file
    Firstly, i use
    File f = new File("/sounds");
    String[] filenames = f.list();
    and use these filenames to load some resouces from url
    //ex
    URL url = getClass().getResource("/sounds/"+filenames);
    No problem occurs when i run it normally
    but when I put it in excuteable jar file, NullPointerException appears
    i think it's because : "File f = new File("/sounds");" doesn't work in jar file (somehow, i don't know why too)
    is there any alternative way to listing all filename in this situation?
    thanks in advance

    There are jar handling classes in the standard library under java.util.jar. I think JarFile is the one you want.
    Hower it's not good practice to list jar contents in order to read resources. It's better to have some kind of resource file in the jar which lists your sounds or whatever. A simple text file with one file name per line suffices.

  • Including web service jaras in final jar file

    Hello all.
    Im using netbeans 4.0. I have used JAXB code in my program, ie. Ive used a few packages I created with the XJC compiler so i can unmarshall some XML documents. I have included the four JAXB Jar files from the Java Web Services Developer Pack in my project by including them in the projects "Classpath for compiling sources". This works fine when running in netbeans. But when I try running the project outside netbeans by double clicking on the generated JAR file I get a
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    Im guessing this is because it can't see the jaxb jar files when not run from within netbeans. How would I include the jaxb jars in the jar file that netbeans generates?
    I know this is partly an IDE related question but I thought it must be a fairly common problem when creating JAR files so i posted it here.
    Any help is appreciated.
    thanks

    Im guessing this is because it can't see the jaxb jar
    files when not run from within netbeans. How would I
    include the jaxb jars in the jar file that netbeans
    generates? You wouldn't include them in that jar file. You would include Class-Path entries (which refer to the jaxb jars) in the manifest of the jar file that Netbeans creates.
    Don't ask me how to do that, I don't use Netbeans. I assume that Netbeans must support it somehow, but if you can't find out how then a Netbeans forum would be a good place to ask.
    I know this is partly an IDE related question but I
    thought it must be a fairly common problem when
    creating JAR files so i posted it here.

  • Unable to run jar file without lib folder containing swing-layout-1.0.jar

    I have done my project through NetBeans 5.0. Eventhough I have copied my lib foloder containing swing-layout-1.0.jar inside my project.jar, I am still unable to run my project.jar in other systems, it is creating an error as Could not find the main class. Program will exit. But if I copy the lib foloder containing swing-layout-1.0.jar in the same path as the project.jar, then my project.jar is running.
    But I want to give only the project.jar for other users and not also lib foloder containing swing-layout-1.0.jar each time.
    Could someone please help me with this.

    When you develop GUI applications using the Netbeans you may endup using netbeans specific jar files in your auto generated code.
    And when you build jar files with netbeans it copy the third party jar files used in a application in to a lib folder in the same directory as the jar file of your project. And then set a class path entry to those jar files in your project jar file's manifest file.
    So if you want to redistribute the package you have to redistribute your jar file and every thing in the lib folder in with the same directory structure.
    If you want to change the structure you will have to change the class path to suit the new structure.

  • Adding jar file in my gerareted jar file using netbean 4.0

    Hi,
    I write an application de process XML file using JDOM. I add the JDom package jar file to my project and everything work fine. But when I generate, my project jar file using netbean 4.0, my generated jar, is not working with the XML files anymore. Everything seems like it didn't include the JDOM jar file?
    Thanks for any help to fix the problem.

    I find that you can not use command-line such as java -classpath add classpath
    it can not work, I use netBeans4.0 i don't whether because of netbeans or java itself.
    you can add classpath in jar's Manifest.mf file
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.2
    Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
    Main-Class: chat.Main
    // add this line
    Class-Path: dir\*.jar //(jar file name)
    X-COMMENT: Main-Class will be added automatically by build

  • Netbeans IDE and the Jar file

    I can't find the jar file compiled by Netbeans anywhere. In the preferences it says the "dist" folder, but that returns nothing when I search my computer.
    I'm using the Mac OS X release, if that helps at all.

    I've just had a look at NetBeans (on a Windows machine). The jar file is not created until I choose "Build Main Project". At that point a helpful message appeared saying:To run this application from the command line without Ant, try:
    java -jar "C:\Documents and Settings\pbrockway.WXPD6OFF\WhereAmI\dist\WhereAmI.jar"The jar file also appears in the "Files" tab (under dist). There doesn't seem to be any way of running the jar file from the NetBeans IDE - or at least, I couldn't find it: others might be more knowledgable about this.

  • JAR files under WEB-INF but not in lib directory

    I am working with JDeveloper 10g and I have several jar files under WEB-INF/lib and other under WEB-INF/libEst.
    I have add this libraries to Project properties > Paths and it works fine when I run my aplication in local environment, but it fails when I deploy and run in the server.
    I have configured our deploy file to include these WEB-INF/libEst jar files, but when I deploy to our server, it seems to be that this classes included in these jar files are not reachable and they cannot be loaded and throw a ClassNotFoundException.
    Is it possible to have jar files under any WEB-INF subdirectory distinct of /lib?
    Why is it working in local but not in server?
    If someone can help me to configure this in order to deploy in server, I will be very grateful.
    Thanks a lot,
    Antonio.

    Hi Antonio,
    I think this document is what you are looking for: http://www.oracle.com/technology/tech/java/oc4j/htdocs/how-to-servlet-warmanifest.html
    .. your manifest entries would look like
    Class-Path: WEB-INF/libExt/<jarName1>.jar, WEB-INF/libExt/<jarName2>.jar, ...
    Let me know if this works for you.
    thanks,
    Harsha

  • Jar file from netbeans won't run when doubleclicked

    Hello,
    I've just completed my first java application using netbeans (just a simple "hello world"), it runs fine in the netbeans ide, but when I located the .jar file and double clicked it, nothing happens. I've already verified that the file extension .jar is associated with javaw.exe so that's not the problem.
    Anyone how to fix this problem?
    Thanks!
    Edited by: b-rad311 on Jul 14, 2010 8:44 AM

    My guess is he posted something and then edited it and put in nvm for NeVer Mind.
    In NetBeans I would try this to make sure the main class setting is fully saved with new version of NetBeans
    press Ctrl+1 to go to projects tab
    Right click your project click Properties
    on left click Run
    Make sure you don't have anything in Arguments or VM Options because javaw will read use either of these settings.
    Click Browse next to Main Class and click your class again and click Select Main Class. Then click OK to rewrite the settings.
    Right click your project and do "Clean And Build".
    Let us know if this works or not

  • Can all macs run .app files or .jar files?

    Hi everyone,
    I'm very confused concerning .app and .jar files. Do all macs natively have the capability to run .jar files?
    If not, could i use the jar bundler to create an .app file (would that run on all macs)?
    thanks

    .jar files are Java files. They may or may not run on most Macs because most Macs do not have Java installed. But one can bundle the Jave interpreter so that Java need not be present on the target computer.
    .app files are true executable applications.

Maybe you are looking for