Executable Jars and their Classpath

I have made a java application that takes requires several libraries to run. I am using netbeans 4.0 but have reached the stage where I'd like it to become a standalone application.
I have editted the projects properties in netbeans to use the correct libraries for compilation and set the correct arguments to run it. It runs fine in netbeans. However, when i try to execute the jar file that netbeans generates with the command...
    java -jar  PeerPressure.jari get the error...
  Exception in thread "main" java.lang.NoClassDefFoundError: net/jxta/pipe/PipeMsgListenerI have tried to modify the manifest.mf file to (it has 2 enters at the end)....
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Main-Class: Main
Class-Path: /lib/jxta.jar /lib/bcprov-jdk14.jar /lib/javax.servlet.jar /lib/log4j.jar /lib/org.mortbay.jetty.jarbut i get the same error. I've also tried the command...
  java  -classpath \lib\jxta.jar;\lib\log4j.jar;\lib\bcprov-jdk14.jar; -jar PeerPressure.jarI'm not sure what else i could try. I've already looked through loads of tutorials and forums posts but still havent got any further. Any help would be great.
Cheers

Tried it and still no luck :(
I tried executing the jar that netbeans 4.0 generates with a project that doesnt require the classpath to be set and that works fine. Also, looking at the stack trace, I've noticed that the executable jar file that i'm having problems with does actually execute. But when it reaches a class that implements the PipeMsgListener it stops.
C:\Documents and Settings\Scottie\PeerPressure\dist>java -classpath ..\lib\jxta.
jar;..\lib\log4j.jar;..\lib\bcprov-jdk14.jar;. -jar PeerPressure.jar
Exception in thread "main" java.lang.NoClassDefFoundError: net/jxta/pipe/PipeMsg
Listener
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at peerpressure.Main.main(Main.java:26)i get the same error when i try
java -jar PeerPressure.jarMy first thought was that the class that implements the PipeMsgListener was at fault. But when i run the project through netbeans it works fine!
Not sure whats going on really. Does anyone know how to find out the command that netbeans is using to execute a project? If i could find out what it is i could use it to execute my jar.
cheers :)

Similar Messages

  • Create executable jar and run it

    hi ,
    I want to create an executable jar file for my Swing application in windows environment and I want to run that jar file by double clicking on it. What should I do?

    I can't beleive I'm saying this given that I didn't like it only 3 months ago but if you change your development environment to Eclipse rather than JCreator/JBuilder or whatever, it saves all that creating manifest files by having one menu item, "Export". You should take a look at minifest files though and at least understand them, they aren't complex at all.

  • Running executable jar with additional classpath

    Hi,
    I have specified a classpath entry in my manifest file for library.jar and a main class entry for main.class in my myapp.jar archive.
    I can run myapp using
    java -jar myapp.jar
    when the library.jar is in the same directory like myapp.jar.
    Is there a way to put library.jar in another directory and still run myapp with something like
    java -classpath /path/to/library.jar -jar myapp.jar
    Background:
    I want to share library.jar for different jars in different locations and do not want to copy it to all those locations...
    Nils

    Is there a way to put library.jar in another
    directory and still run myapp with something like
    java -classpath /path/to/library.jar -jar myapp.jar
    When you use the -jar option of the java application launcher, the only Classpath that is used is the jar file or the Classpath specified by the Class-Path line in the mainifest of the jar.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html
    But, instead of using the -jar option, you can use the -classpath option and include all of the jars, including the jar with the main-method class.
    java -classpath /path/to/library.jar;path/to/myapp.jar myapp.jar.MainClass

  • Executing JAR file ignores classpath

    I have recently been working with JAR files, and manifest.mf files. I have discovered that the only classpath that the jar file will ever use is the one defined in the manifest file.
    Apparently, specifying the classpath on the command line, or through the CLASSPATH environment variable is ignored by the JAR file.
    Can anyone explain why this is the behavior for jar files?

    Can anyone explain why this is the behavior for jar
    files?Because the Class-Path parameter in the jar's manifest file is the value that controls where Java looks for your classes.

  • Executing jar files - why classpath is so rigid ?

    If someone gives me a jar file with a Main in it and some supporting
    library jar files, the Manifest.mf will contain information on what
    the Main class is and also the location of supporting library jars
    RELATIVE to the application jar file. But once I get the jar, I want
    to move the supporting jar files to some other convenient directory.
    But If I do that, the application jar file will not be able to locate
    the supporting classes since the Manifest file has the supporting jar
    paths pretty much HARDCODED ! How do I override the hardcode and give
    it a different search path so that it can start looking at the new
    directory ? This rigidity makes it so painful during times of
    distribution. Please help.

    Well, actually I was not meaning this, though it could work as well...
    There is some classpath in the manifest pointing to some other (external) jar. (Whoever did that, forced this kind of problem to come up!)
    So you don't need to replace the -jar switch but to append the supporting jar-file to your CLASSPATH, so that it can be found together /w the programm itself.
    But then the questioner said, that wouldn't work.. hmmm.
    Maybe a merge of ulf's and my suggestion?
    Remove the -jar switch and append both jar files to the CLASSPATH:
    - the supporting one
    - your own
    Start the program like ulf suggested before.
    Regards, tom

  • Including jars into executable jar

    Hello
    I want to create an application in one application even if this application depends by many other jar libraries.
    So , my development process resulted into one library: myapp.jar
    This application depends by other jars: lib1.jar, lib2.jar, lib3.jar,
    If I'll create one big jar archive with my classes and these libraries doesn't work (even I'll specify in manifest file all tags:
    Class-Path: lib1.jar lib2.jar lib3.jar
    Main-Class: com.snt.xdoc.MyApp
    So, it is possible to create one single JAR archive including all resources (my interesting point is to include jar libraries) and executable class to know where are these resoures (to establish corectly the classpath)?
    Thank you

    Hello Stefan
    Other topics about this problem can be found here:
    http://forum.java.sun.com/thread.jsp?forum=22&thread=405160&tstart=0
    http://forum.java.sun.com/thread.jsp?forum=4&thread=432114&tstart=0
    But you might want to take a look at META JAR UTILITIES : http://www.yagga.net/java/metajar/
    "Three classes with full source code and documentation that allows to extract resources from a file, from inside a JAR file that is currently executing (java -jar foo.jar), from a JAR that is included in the aforementioned executing JAR and to define a classLoader that can work with JARs, even if those JARs are JARred inside the currently executing JAR."
    MetaJarUtilities are being distributed with full source code under GNU's General Public License.
    For the moment being a JAR structured like this works:
    FOO.jar
    +- SuperMetaJarTest.class (uses BootstrapJarClassLoader.class)
    +- net/
    | +- yagga/
    | +- util/
    | +- BootstrapJarClassLoader.class
    |
    +- metatest.jar (content below)
    | +- net/
    | | +- yagga/
    | | +- util/
    | | +- Meta Jar Utilities classes here...
    | +- jars/
    | | +- test.jar
    | +- TestmetaJar.class
    | +- text.txt
    |
    +- jars2/
    +- test2.jar
    Good luck!

  • Executable JAR witn anoter JAR

    Hello, I need some help to be able to create an Executable JAR from a project containing already one JAR
    Here is the situation :
    I've made a program who acceses Oracle DB and therefore I have integrated an External JAR (ojdc14_g.jar) in my project so I can get access to the classes needed to synchronize with the DB.
    I'm using Eclipse so I was able to generate automatically an auto-executable JAR. But the problem is that obviously the import statement :
    import oracle.jdbc.*;
    that I'm using to access the classes in the oracle External JAR is not undersood by the auto-executable JAR and I get :
    A fatal exception occured - Program will Exit
    Anyone an idea ??
    PS: the generation of auto-executable JAR with eclipse works perfectly with my other projects
    I'm using j2sdk 1.4.2.05
    Thanks in advance

    Hi guys!
    Sorry for the dot, I had missed that :(
    But still doesn't work.....
    I have been trying the following :
    Class-Path: . ./JarLibrary/ojdbc14_g.jar
    Class-Path: . /JarLibrary/ojdbc14_g.jar
    Class-Path: . JarLibrary/ojdbc14_g.jar
    Class-Path: . .\JarLibrary\ojdbc14_g.jar
    Class-Path: . \JarLibrary\ojdbc14_g.jar
    Class-Path: . JarLibrary\ojdbc14_g.jar
    and even
    Class-Path: . .JarLibrary.ojdbc14_g.jar
    Class-Path: . JarLibrary.ojdbc14_g.jar
    But I always get NoClassDefFoundError
    any ideas ? Could it be my java version ? I'm working with 1.4.2_05
    or any other ideas to be able to double-click on a Icon to run an Java application ?
    Hope I can give you those 10 Dukes soon

  • Problem with executable jar file

    Hi,
    I wrote a simple little xml based app in eclipse, it had xalan and xerces in build path. I created an executuable jar that ran fine on my machine; I was able to move it to different directories and launch it successfully, but when I put the jar file on a network directory and asked a coworker to try running it, they got a message that said it couldn't find the main class.
    how do you deal with that?
    thanks,
    bp

    they got a message that said it couldn't find the main class.
    Are you sure?
    If you are sure then none of the other responses will help.
    That error suggests one of the following
    1. The jar you moved is not the jar that you are running.
    2. Your co-workers did not execute it correctly.
    3. You do not have an executable jar (and you are not testing it correctly on your box.)
    How exectly did they run it?
    The standard double click will give an error about "Main-Class" with that specific text when you attempt to run a jar that is not in fact an executable jar.
    That error is NOT the same as the standard class not found error.

  • Executable Jar file

    How do I bundle my .class files into a .jar that I can execute directly...
    Basicly I'd like to make it so my classes are all packaged together and that someone can type just the file name to execute, can this even be done?
    Thanks

    How do I bundle my .class files into a .jar that I can
    execute directly...
    Basicly I'd like to make it so my classes are all
    packaged together and that someone can type just the
    file name to execute, can this even be done?
    ThanksAt the top of this page is a search button. If you type "executable jar" and hit search you'd probably find about 100 answers to this question.
    Let us never speak of this incident again.

  • Adding a jar to the classpath of an executable jar (mixing -jar and -cp)

    Hello,
    frankly I hesitated over posting this to "New to Java"; my apologies (but also, eternal gratefulness) if there is an ultra-simple answer I have overlooked...
    I integrate a black-box app (I'm not supposed to have the source) that comes packaged as an executable jar (with a Manifest.MF that specifies the main class and a bunch of dependent jars), along with a few dependent jars and a startup script. Long story short, the application code supports adding jars in the classpath, but I can't find a painless way to add a jar in its "classpath".
    The app's "vendor" (another department of my customer company) has a slow turnaround on support requests, so while waiting for their suggestion as to how exactly to integrate custom jars, I'm trying to find a solution at the pure Java level.
    The startup script features a "just run the jar" launch line:
    java -jar startup.jarI tried tweaking this line to add a custom jar in the classpath
    java -cp mycustomclasses.jar -jar startup.jarBut that didn't seem to work ( NoClassDefFound at the point where the extension class is supposed to be loaded).
    I tried various combination of order, -cp/-classpath, using the CLASSPATH environment variable,... and eventually gave up and devised a manual launch line, which obviously worked:
    java -cp startup.jar;dependency1.jar;dependency2.jar;mycustomclasses.jar fully.qualified.name.of.StartupClassI resent this approach though, which not only makes me have to know the main class of the app, but also forces me to specify all the dependencies explicitly (the whole content of the Manifest's class-path entry).
    I'm surprised there isn't another approach: really, can't I mix -jar and -cp options?
    - [url http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html]This document (apparently a bible on the CLASSPATH), pointed out by a repited forum member recently, does not document the -jar option.
    - the [url http://download.oracle.com/javase/tutorial/deployment/jar/run.html]Java tutorial describes how to use the -jar option, but does not mention how it could play along with -cp
    Thanks in advance, and best regards,
    J.
    Edited by: jduprez on Dec 7, 2010 11:35 PM
    Ahem, the "Java application launcher" page bundled with the JDK doc (http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html) specifies that +When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored+
    So this behavior is deliberate indeed... my chances diminish to find a way around other than specifying the full classpath and main class...

    I would have thought that the main-class attribute of the JAR you name in the -jar option is the one that is executed.Then I still have the burden of copying that from the initial startup.jar's manifest. Slightly less annoying than copying the whole Class-path entry, but it's an impediment to integrating it as a "black-box".
    The 'cascading' behavior is implicit in the specification
    I know at least one regular in addition to me that would issue some irony about putting those terms together :o)
    Anyway, thank you for confirming the original issue, and merci beaucoup for your handy "wrapper" trick.
    I'll revisit the post markers once I've actually tried it.
    Best regards,
    Jérôme

  • Problems with CLASSPATH in a executable jar file

    Hi there
    I'm having a problem that I don't know how to solve. My generalq uestion is:
    "Why isn't my CLASSPATH (java.class.path) forwarded into ar unnable class inside a jar file?"
    The situation is:
    I have made a runnable jar file containing an ant build.xml file, a jar file containing some patch files, and a class called AntLoader.class. AntLoader are the file that are executed (inserted into the manifest). This works. The class are executed, but it can't find the package needed for starting ant.
    ant.jar is in my CLASSPATH, and therefore everything works fine if I'm running AntLoader outside the jar file.
    I know that I can use different ClassLoader classes for dynamicly loading of a class, but then I need a path to where ant.jar is located. And then again my system wont be general. The jar file is supposed to be distributed as a system patch to customers. And their location of where ant is installed will not be the same.
    So what I'm looking for is a way to pass my CLASSPATH from my environment on to a jar file. Is that possible?
    running java -classpath "${CLASSPATH}" -jar cpc.jar doesn't help at all. The java.class.path is still set to cpc.jar when I'm executing the AntLoader class inside cpc.jar.
    Can anyone please help me?
    Brgds
    Jakob

    've found the solution to the problem. You have to use the -Xbootclasspath/a parameter when running java.
    Example on unix:
    java -Xbootclasspath/a:${CLASSPATH} -jar test.jar
    Brgds
    Jakob

  • Executable jar files and manifest file

    Hi,
    I have the following files in a folder named: Test
    a.jar
    b.jar
    c.jar
    Driver.class
    Driver.mf
    Here, MainClass is the main executable class that uses a,band c.jar files. This is how my MainClass.mf file looks:
    Manifest-Version: 1.0
    Main-Class: Driver
    Class-Path: a.jar b.jar c.jar
    Now I use the following command to make one executable jar file:
    jar cmf Driver.mf DriverMain.jar *
    It creates an executable jar file named : DriverMain.jar
    Now I copy the executable jar file (DriverMain.jar) into a different folder named: RunTest
    and double click it, doesn't work.
    my question is:
    what am I doing wrong? Any special characters needed in my Driver.mf file (space/newline/etc)?
    What I am trying to get is: One execuatble jar file so I can just double click to run it, and that single executable jar file will have all the necessary jars in it (i.e. a.jar, b.jar, c.jar in this case)
    Anyone please help!
    Thanks
    -Ron

    Rony,
    Sorry to disappoint, but you can not use embeded jar/zip files within an executable jar. The JDK sadly for some reason decided this was not a useful idea, so developers like me who want to distribute plugins with thier own dependencies have one of two choices. You either have to unzip the jar file that contains the embeded jars to a directory, then run your primary exectuable jar, OR you have to write a custom classloader that your "launcher" creates then loads the embeded jar files.
    The best thing to do is either jar up a, b, c and driver into one jar, so that it works, if you can legally do this. A lot of 3rd party libraries may not allow this per their license. Otherwise, another choice is to use a free installer or buy an installer that allows you to distribute a single exectuable installer program that will properly create the dir structure you need.
    As for the way it works, if you declare:
    Class-Path: a.jar b.jar c.jar
    the JAR loader code in the JDK looks in the root dir where your application was started for a/b/c jar files. They have to be on disk.
    If you want to place them in /lib, for example, you would havd a jar file like:
    Driver.class
    Driver.mf
    lib/a.jar
    lib/b.jar
    lib/c.jar
    When unzipped, your "root" dir would look exactly like the above, and your manifest would have Class-Path using ./lib/a.jar ./lib/b.jar ./lib/c.jar
    Anyway, there thus far isn't any way around this issue of embeding jar files in an executable jar file. You MIGHT be able to not specify any classpath, then in your Driver.class, create a new custom classloader that dervies from URLClassLoader, but in the findClass(), you get a ref to the .jar file that the classloader class is inside of, and from that use it to find the lib/*.jar files and add them to the classpath. For this to work, however, your Driver.class code should ALSO be contained in an embeded jar file that is loaded by this custom loader. The only thing Driver.class would contain (and I would rename it to something like Launcher) is the code to create the custom classloader.
    It's fun stuff, but a little bit of work to make it work. You can infact make it work! I may yet one day take our plugin engine custom loader and create a way for this to work!

  • Projects and executable jars

    I'd like to distribute single executable jar files, but share (the source's of) some packages.
    Netbeans 4.1 however refuses to add the same directory with sources to mutiple projects. Under packaging standard projects, the help files only tells how to suppress or rename/relocate jar files, and under creating dependencies between projects only about setting the classpath. Has anybody a hint?
    Jo

    I think if you create a separate project, then that project (including source) can be imported into multiple projects.
    But I'm using version 5, and this is from memory, so. . .

  • Setting classpath to execute jar file.

    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
          ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
            at utility.tpc.generate.Tpc.generate(Unknown Source)
            at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
             utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?

    baskark wrote:
    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
    ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
    at utility.tpc.generate.Tpc.generate(Unknown Source)
    at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
    utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?The jar command is specified to work as you have shown. That is, when you use "java -jar..." the system or command line classpath is ignored. The only classpath that can be used with "java -jar..." is the Class-Path in the manifest. You need to separate the different paths using space characters, not ; or : and the paths need to be relative to the jar file. (I am not sure if "./" will work and it is not needed to specify relative to the jar file.)
    Edited by: atmguy on Dec 14, 2009 8:42 AM

  • Download and execute jars without using javaws

    Hi
    I need to download and execute jars from remote computer. I hava jnlp file, but I strongly need to execute jars without using java web start.
    What is the best way to do this task?
    Thanks in advance :)
    Edited by: joekidd on Aug 3, 2009 5:55 AM

    joekidd wrote:
    The easiest the best:)The easiest way is to hire the programmers who made the Jar, to consult on your behalf to install the program, or advise on its installation. BTW - you said earlier.. "strongly need to execute jars without using java web start." Why? What advantage does that provide?
    So I download needed jars, add them to classpath and run my application (I get all information from jnlp file and pass them to vm and my application).
    But following exception occurs "Exception in thread "main" java.lang.NoClassDefFoundError: javax/jnlp/ServiceManager". What should I do?Get in contact with those programmers, because this app. is dependant(1) on functionality that is only available to web start apps.
    (1) Unless they put that call in there, just to ensure no one can run the app. outside web start. ;-)

Maybe you are looking for

  • 10.2.1 update

    After i did the 10.2.1 update, whenever i go on snapchat or watch instagram videos once, the second time i try doing so, the camera bugs out.. When it bugs, i can't open my camera and i cant watch videos.... until i restart the phone

  • Change/Delete Existing Pricing Condition Type

    Hello I have a manu Pricing Condition Type and a rate(obtained from custom source) was inserted pro-grammatically into this line item whenever the new line item was added into the basket using CRM_ISA_BASKET_ITEMS badi. When the user changes the Qty

  • VISTA Support for Multiple Dual Quad Core Processors

    Sorry if I missed this in my search. Does Windows Vista Home Basic support dual quad core processors? Windows Help & Support: Under System, you can view the processor type and speed, as well as the number of processors installed, if your computer use

  • Who wants a black Audigy Platinum faceplate

    Ok, as far as I could tell, Creative teased us with the promise of a black faceplate that we could purchase separately, but then never actually made it available. They just had their next generation products include them, hoping we'd fork out some ex

  • Include measurement in report

    So I have a pretty easy question that I can't find an answer to.  I have a bunch of VIs that have numeric outputs that I need to write in the measurement column in the report, and, try as I might, I can't get them in there.  I tried creating a variab