Run *jar with other jars in classpath...

Hey,
I am writing a little tool in Java and I exported it into a jar file. My tool uses a jar from somebody else. A second jar so to say...!
My Jar's path is: ~/Desktop/project/dist/lib/MyTool.jar
The other jar is located in: ~/Desktop/project/lib/help.jar
I call the java vm from: ~/desktop/project/exe/
with:
java -cp ../lib/help.jar -jar ../dist/lib/MyTool.jar
Now the tool starts running and everything works fine up to the moment when it is supposed to use one of the classes from the help.jar.
Then I get a java.lang.NoClassDefFoundError.
What am I doing wrong here?
I tried to copy help.jar into the /exe/ dir. --> Did not work!
I tried to copy all of the file into one folder and start the tool from there. --> didn't work.
It would be great if somebody could point my in the right direction on how to solve my problem.
THX
Martin

Hey,
I am writing a little tool in Java and I exported it
into a jar file. My tool uses a jar from somebody
else. A second jar so to say...!
My Jar's path is:
~/Desktop/project/dist/lib/MyTool.jar
The other jar is located in:
~/Desktop/project/lib/help.jar
I call the java vm from: ~/desktop/project/exe/
with:
java -cp ../lib/help.jar -jar
-jar ../dist/lib/MyTool.jar
Now the tool starts running and everything works fine
up to the moment when it is supposed to use one of the
classes from the help.jar.
Then I get a java.lang.NoClassDefFoundError.
What am I doing wrong here?
I tried to copy help.jar into the /exe/ dir. --> Did
not work!
I tried to copy all of the file into one folder and
start the tool from there. --> didn't work.
It would be great if somebody could point my in the
right direction on how to solve my problem.The classpath argument is ignored when you are running a jar using java -jar some.jar. You have to specify the class path from within the Manifest.
Basic JAR tutorial:
http://java.sun.com/j2se/1.4.1/docs/guide/jar/jar.html
Tutorial about the extension mechanism:
http://java.sun.com/products/jdk/1.2/docs/guide/extensions/spec.html

Similar Messages

  • Running iSight with other programs?

    I am trying to figure out if there is a way to play a DVD while using iSight to record. I have a DVD with a prompt on it and need to watch this and also capture my video of the response. Can I do them both on the same computer? I have been using a TV/DVD player to watch and then a camcorder to record, but iSight, if it will work, seems simpler.

    Welcome to Apple Discussions, anselu
    If I understand what you want to do correctly, you could use an external iSight to record your computer monitor. Of course, you would need some way to mount your iSight so it is pointed where you want it. You would also need some application that can record movie or video clips. You could use iRecord, iMovie, QuickTime Pro, or one of the other clip/movie recording apps linked in Some Applications You Can Use With iSight.
    If you are looking for higher quality recordings or want an alternative that does not require the use of iSight, you may find that SnapZ Pro, which is also linked in the "Some Applications..." page, is a better alternative for recording what is displayed on your Mac's monitor.
    You do not say which Mac you use. If your Mac has a built-in iSight, SnapZ Pro will offer much more convenience than trying to rig some way to record what is on your display with a built-in iSight.
    Jim

  • Running Jars with other Jars

    Hello people, let me tell you a little stroy
    I'm using netbeans IDE to wrtie a program that uses the mysql connector package to interface with a database. Every time I compile in the IDE, it gives me a nice little command line executable to try. (Something along the lines of
    "To run this application from the command line without Ant, try:
    java -jar "C:\...path to my jar"
    ... so I go ahead and try it ...
    I'm getting a class not found error. the class its not finding is the connector:
    com.mysql.jdbc.Driver
    thus, im wondering what the syntax would be to include that in the command line call .... or if there's a better way to run my application with all of the extensions it needs without the IDE.
    Thanks in advance ..

    Sorry, but we have heard that story before...
    To run an Java application use:
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:<value>
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:<libname>[=<options>]
    load native agent library <libname>, e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
    load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
    load Java programming language agent, see java.lang.instrument

  • Help with a question about making/running .jar files.

    First i have a question, can i make a .jar file that can run on a computer without JRE installed. And if i can, how do i make it. I have tried to make it on my computer, that has JRE but i keep getting the error when i run it: Exception in thread "main" java.lang.NoClassDefFoundError: Sample\FileSearchAnd im using the command:
    jar cvfm jarname.jar directory\manifest.txt directory\FileSearch.class directory\FileNode.classIt says it creates the .jar but is unable to run it.

    dford425 wrote:
    First i have a question, can i make a .jar file that can run on a computer without JRE installed. No, not unless you package the JRE with your dist. Hence the name JRE (Java Runtime Environment).
    And if i can, how do i make it. I have tried to make it on my computer, that has JRE but i keep getting the error when i run it: Exception in thread "main" java.lang.NoClassDefFoundError: Sample\FileSearch
    That simply means your not pointing the runtime to the classes. Set your CLASSPATH environment variable correctly and it will run (given you have a JRE which it appears you do).
    And im using the command:
    jar cvfm jarname.jar directory\manifest.txt directory\FileSearch.class directory\FileNode.classIt says it creates the .jar but is unable to run it.

  • Problems with running jar on linux

    Are there any known problems when running jar files on linux, that were compiled on windows?
    http://turkeybot.info/DuckHunt.jar
    The images directory that is in that refuses to load under linux, but there's no problem with windows (it's using System.getProperty("file.separator") to get hte correct file separtor to refer to the image directory).

    Java code should run in all JVMs. But if you did something Windows-specific (such as looking for a file named C:/something/or/other) in your code then you can't expect it to run in other environments.

  • Got exception with p13n_app.jar and p13n_system.jar into classpath for 9.2

    Hi, Portal guru:
    I installed wls9.2&portal9.2, and put p13n_app.jar and p13n_system.jar into classpath from startWeblogic.cmd.
    then looks portalApp can not be loaded due to the following exception:
    java.lang.Error: Clonable is not clonable: java.lang.CloneNotSupportedException: com.bea.p13n.expression.operator.c
    omparative.Equals: 4138928
    com.bea.content.expression.PropertyRef: 4138900
    java.lang.String
    cm_nodeName
    java.lang.String
    CmxControlUniqueKeysFolder
    : com.bea.content.expression.PropertyRef
    at com.bea.content.expression.Search.clone(Search.java:568)
    at com.bea.content.manager.internal.SearchOpsImpl.createSearchForRepo(SearchOpsImpl.java:376)
    at com.bea.content.manager.internal.SearchOpsImpl.searchRepository(SearchOpsImpl.java:203)
    at com.bea.content.manager.internal.SearchOpsImpl.search(SearchOpsImpl.java:159)
    any know what is the problem?
    Thanks in advance.

    I don't think it's supported to have app-scoped class in the system
    classpath. I'm surprised your 814 app worked that way.
    It might be that changes in 9.2 have caused some of the classes the
    system classloader is hitting to now try to load other classes that are
    only available in an application classloader, which the system
    classloader cannot access.
    http://e-docs.bea.com/wls/docs90/programming/classloading.html has
    information about the classloader hierarchy in WLS/WLP.
    One way to have a system-classloader class access an
    appliation-classloader is via the
    Thread.currentThread().getContextClassLoader(), and then either use
    reflection or have the class implement an interface available in the
    system classloader. This allows code at the system classpath level to
    access implementation classes loaded up as part of an application,
    rather than relying upon the built-in classloading which can't see
    classes in children classloaders. However, this would entail having a
    system classpath jar and an application jar, which is why WLP has
    p13n_system.jar and p13n_app.jar.
    Greg

  • Packages in separate Jars causes classpath error

    For the purposes of easy-updating and allowing developers to work on one part of a system without interfering with others, I have created separate Jar files for the main packages in my application. So;
    com.me.pack1 is in Pack1.jar
    com.me.pack2 is in Pack2.jar
    An ant build takes care of building and packaging these up. The Jar files have the correct directory structure i.e.;
    jar $ $JAVA_HOME/bin/jar tf /users/jmcparla/jar/Pack1.jar
    META-INF/
    META-INF/MANIFEST.MF
    com/
    com/me/
    com/me/pack1/
    com/me/pack1/MainClass.class
    jar $ $JAVA_HOME/bin/jar tf /users/jmcparla/jar/Pack2.jar
    META-INF/
    META-INF/MANIFEST.MF
    com/
    com/me/
    com/me/pack2/
    com/me/pack2/OtherClass.classHowever when I run it;
    jar $ $JAVA_HOME/bin/java -cp /users/jmcparla/jar/Pack2.jar -jar /users/jmcparla/jar/Pack1.jar
    Entered main
    Created MainClass instance
    Exception in thread "main" java.lang.NoClassDefFoundError: com/me/pack2/OtherClass
            at com.me.pack1.MainClass.main(MainClass.java:13)The classes are;
    MainClass.java
    package com.me.pack1;
    import com.me.pack2.OtherClass;
    public class MainClass
        public static void main(String[] args)
            System.out.println("Entered main");
            new MainClass();
            System.out.println("Created MainClass instance");
            new OtherClass();
            System.out.println("Created OtherClass instance");
    }OtherClass.java
    package com.me.pack2;
    public class OtherClass
    }and the build file is;
    build.xml
    <project name="JarProblem" default="buildJars" basedir=".">
      <property name="classdir" value="classes"/>
      <target name="compile" depends="clean" description="compile the code">
          <mkdir dir="${classdir}"/>
          <javac debug="on" debuglevel="vars,lines,source" srcdir="."
                 destdir="${classdir}" encoding="ISO-8859-1">
          </javac>
      </target>
      <target name="buildJars" depends="compile" description="build the jar files">
        <antcall target="buildPack2"/>
        <antcall target="buildPack1"/>
      </target>
      <target name="buildPack2" description="build the Pack2 jar">
        <tstamp>
          <format property="time" pattern="hh:mm aa dd/MM/yyyy"/>
        </tstamp>
        <jar destfile="Pack2.jar" update="false">
          <fileset dir="${classdir}">
            <!-- Only include the package we're building -->
            <include name="com/me/pack2/*"/>
          </fileset>
          <manifest>
            <attribute name="Built" value="${time}"/>
          </manifest>
        </jar>
      </target>
       <target name="buildPack1" description="build the Pack1 jar">
        <tstamp>
          <format property="time" pattern="hh:mm aa dd/MM/yyyy"/>
        </tstamp>
        <jar destfile="Pack1.jar" update="false">
          <fileset dir="${classdir}">
            <!-- Only include the package we're building -->
            <include name="com/me/pack1/*"/>
          </fileset>
          <manifest>
            <attribute name="Main-Class" value="com.me.pack1.MainClass"/>
            <attribute name="Built" value="${time}"/>
          </manifest>
        </jar>
      </target>
      <target name="clean" description="clean up the compiled source files">
        <delete verbose="false" failonerror="false">
          <fileset dir="${classdir}"/>
        </delete>
      </target>
    </project>The build completes with no problems. So why can't the java command see OtherClass?

    johnmcparlald wrote:
    However when I run it;
    jar $ $JAVA_HOME/bin/java -cp /users/jmcparla/jar/Pack2.jar -jar /users/jmcparla/jar/Pack1.jar
    Entered main
    Created MainClass instance
    Exception in thread "main" java.lang.NoClassDefFoundError: com/me/pack2/OtherClass
    at com.me.pack1.MainClass.main(MainClass.java:13)
    I can't help you with ant but I can tell you that the command you entered looks wrong. If you use the -jar option with the java command, the only classpath that is used is the one specified by the Class-Path entry in the manifest - other classpaths are ignored.
    So you either need to leave off the -jar, include the Pack1.jar file and specify the main class, or include the Class-Path: Pack2.jar entry in the manifest. (At least, it looks to me like there is no Class-Path in the manifest.)

  • Problem running jar files of java in Linux

    I cannot run jar files in java/jdk1.3.1_01/demo in Readhat Linux 6.2
    The command is :--
    [root@localhost Notepad]# java -jar Notepad.jar
    java.lang.NoClassDefFoundError: javax/swing/JPanel
    at java.lang.Class.forName(Class.java:33)
    at kaffe.jar.ExecJarName.main(ExecJarName.java:58)
    at kaffe.jar.ExecJar.main(ExecJar.java:61)
    [root@localhost Notepad]#
    My ~/profile setting is :---
    PATH="$PATH:/usr/X11R6/bin:/usr/java/jdk1.3.1_01/bin:/usr/java/jdk1.3.1_01/jre/bin:/usr/java/jre/lib"
    export JAVA_HOME=/usr/java/jdk1.3.1_01
    export NPX_PLUGIN_PATH=/usr/java/jdk1.3.1_01/jre/plugin/i386/ns4

    [root@localhost Notepad]# java -jar Notepad.jar
    java.lang.NoClassDefFoundError: javax/swing/JPanel
    at java.lang.Class.forName(Class.java:33)
    at
    at
    at kaffe.jar.ExecJarName.main(ExecJarName.java:58)
    at kaffe.jar.ExecJar.main(ExecJar.java:61)
    [root@localhost Notepad]#
    My ~/profile setting is :---
    PATH="$PATH:/usr/X11R6/bin:/usr/java/jdk1.3.1_01/bin:/u
    r/java/jdk1.3.1_01/jre/bin:/usr/java/jre/lib"
    export JAVA_HOME=/usr/java/jdk1.3.1_01
    export
    NPX_PLUGIN_PATH=/usr/java/jdk1.3.1_01/jre/plugin/i386/n
    4Add the line:
    export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar
    Then, run the command "source ~/.profile" and then the jar file should be able to run.
    Bhav

  • Java error when trying to run .jar program---help?

    I have a Java program that runs fine on a Windows box.
    When I run it with the GUI "Jar Launcher", the program name appears at the top of the screen very briefly but then the program crashes. When I run it using Terminal, I get the following errors:
    +Exception in thread "AWT-EventQueue-0"+
    +java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group+
    +at PPBSOjdb.PPBSOjdbApp.startup(PPBSOjdbApp.java:20)+
    +at org.jdesktop.application.Application$1.run+
    (Application.java:171)
    +at java.awt.event.InvocationEvent.dispatch+
    (InvocationEvent.java:209)
    +at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)+
    +at java.awt.EventDispatchThread.pumpOneEventForHierarchy+
    (EventDispatchThread.java:269)
    +at java.awt.EventDispatchThread.pumpEventsForHierarchy+
    (EventDispatchThread.java:190)
    +at java.awt.EventDispatchThread.pumpEvents+
    (EventDispatchThread.java:184)
    +at java.awt.EventDispatchThread.pumpEvents+
    (EventDispatchThread.java:176)
    +at java.awt.EventDispatchThread.run(EventDispatchThread.java: 110)+
    When I run "java -version" (Terminal again) I get:
    +java version "1.5.0_16"+
    +Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-275)+
    +Java HotSpot(TM) Client VM (build 1.5.0_16-132, mixed mode, sharing)+
    The programmer believes it should run under Java 1.5 as well was 1.6, but he develops on Windows.
    Any suggestions on how to get this program to run?
    Thanks!

    Thanks. Crud.
    Am I just out of luck or is 1.6 available on the Mac? Is Apple just slow getting 1.6 out (since my computer is all Software Updated)?
    Is there someplace that explains the relationship between Java SE 6, J2SE, version 1.6/1.5?
    I'm very new to Java.
    Apple says that "Java for Mac OS X 10.5 Update 2 delivers improved reliability and compatibility for Java SE 6, J2SE 5.0 and J2SE 1.4.2 on Mac OS X 10.5.4 and later. The release updates Java SE 6 to version 1.6.0_07, J2SE 5.0 to version 1.5.0_16, and J2SE 1.4.2 to 1.4.2_18."
    (Apple has since come out with Update 3, but it's not mentioned on the developer.apple.com/java/ page for some reason.)
    It seems like "version 1.6.0_07" would be version 1.6 but apparently it's still 1.5! (Bizarre.)
    Thank you!

  • Error messege when run jar file

    when i run jar file of my project give me that error(Fatel exception occured.program will exist)
    what is the reason of that error

    "can't get that path". Sounds like requisite classes aren't on the classpath.
    Please paste the ENTIRE error message that it's producing into your next reply. You have probably forgotten to include necessary classes - perhaps a JDBC driver - in your JAR file.

  • Impossible to run jar file

    Hi! I've got a problem is getting me crazy. I'm using JDK 1.1.8 to develope a consulting application in java. Everything works well, but I need to create a jar file to distribute the program to other PCs. I install the JRE 1.3.1 to simply click on the file and run it, but it doesn't work. The problem is the famous "Could not find main class", I've already read about it in other threads. But there is one curious thing. If I run the jar file with c:\jre...\bin\java -jar MyJar.jar this exception ocurred:
    Exception in thread "main" java.lang.ClassFormatError: Consulta (Illegal method modifiers: 0x402)
    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)
    and "Consulta" is not my main class, my main class is another one.
    What is the reason of this error? How could I create a jar file and run it with double-click?
    Thanks a lot!!

    Yes, I've defined the main class.
    I've just solved the problem. I think it was related with a private method I had defined in the class "Consulta". I changed it to public and it works. A bit strange....
    Thanks anyway for your response! See you!

  • Console not display when run jar file

    i run jar file with command javaw -jar test.jar or double click on jar file, it's console app, it just run well but console not display, can i made console display and when i close console, it's stop jar file too?
    thanks

    i got it, javaw = no console window, i tried java command and i got error: can not access jar file?

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • Set java path to run jar in command prompt

    i have installled only jre.. i dont have jdk..
    Is it possible to run jar command in command prompt.
    if possible please give me jar command...
    thanks in advance

    i have installled only jre.. i dont have jdk..ok
    Is it possible to run jar command in command prompt.Please, read java tutorial before posting such question
    if possible please give me jar command...Please, read java tutorial before posting such question

  • Run jar-exe on windows systems.

    Hi. I`m trying to find a way to run jar files on Windows systems. The key is to do so without having installed "explicity" the jre (1.5 or higher) sun installation program. I mean, I want to users be able to run my .jar executable programs on machines where jre isn`t set. I know how to create executable jar programs, but I have no idea about how to change Windows behaviour to instantiate the java virtual machine.
    Help and comments wil be welcome, Thanks and regards.

    Are you trying to run .jar executable on Windows system without JRE installed? Remember, executable jar file contains java classes and they need a JVM/JRE in order to run themselves.
    In plain you cann't run a jar executable without jvm/jre installed.
    Now, on another note, if you are trying to provide user the ability to run jar file without downloading/installing JRE, this forum entry might interest you:
    http://forum.java.sun.com/thread.jspa?threadID=695898

  • Updating a running JAR file without using JDK

    Hi guys, I have been stuck on this problem for days. I have a program that allows the user to log in and encrypt/decrypt files. This program must be stored on the removable drive and it should work on any operating system without requiring any installation of files. In order to store their login data, I wrote it to a shadow.txt file. My idea was to pack this shadow file into the JAR file so as not to create unnecessary files. I understand that in order to update JAR files, all I need to do is to do
    Runtime.getRuntime().exec("jar uf login.jar shadow.txt");However, here's the problem. I cannot assume that every user PC has JDK installed. As JRE doesn't have jar.exe, that command won't work anymore. Furthermore, the JAR is currently in use. So even if the user has JDK, windows will never allow this command to go through. Anyone has any ideas?

    I had similar requirement, except that, i used a war file.
    Had a client.war file in JBoss deploy directory, and i needed to update client.jnlp file present in it.
    But as jar.exe comes only with jdk, could not use jar -uf command.
    But not sure if it works with other application server too,
    in jboss we can explode the war file, meaning we can create a directory "client.war" in deploy directory and extract your client.war contents to it. Now when server starts, it considers the extracted directory as web archive application.
    This extraction can be done with out using jar.exe. can be done using jarinputstream aswell.
    Once the contents are extracted , the files in it can be modified with out jar.exe.
    For my case it worked as my client.war file is not signed, although the resources inside are signed.

Maybe you are looking for