Execution from JAR files and Classpaths -- Help

I am confused about how classes are resolved when running from within a JAR file, and why this is different than running a class that is not inside a JAR file.
I have an application that uses classes from a third party library stored in a JAR file (biojava.jar) . If I run the app from the class file it works as expected and is capable of finding the external classes when the path to the biojava.jar is on my classpath. It also works if biojava.jar is instead placed in the extensions folder jre/lib/ext folder without an explicit path entry in my classpath.
However when I package all my application classes up in a JAR file and try to execute the application from the JAR file it will ONLY work if I add a manifest entry to myApp.jar ... Class-Path: biojava.jar AND I place the file biojava.jar in the SAME directory as the Packaged JAR application. I would like to find a way to make this JAR file work for anyone who has biojava.jar in their classpath or ext directory. In other words I don't want my user community to have to copy the biojava.jar file when I email them myApp.jar. This community will already have biojava.jar on their CLASSPATH.
How can I make my app within a JAR recognize either the user's CLASSPATH or ext folder? I have tried reading the documentation and many experiments but the only way it works is as described above.
I am running Running Windows 2000.
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
Here are the results of my experimentations:
The following Works:
Manifest: Main-Class: org/biojava/app/SequenceSpiral
Manifest: Class-Path: biojava.jar
Place biojava.jar in the same directory as SequenceSpiral.jar
java -jar SequenceSpiral.jar
This works perfectly
NONE of the following work
0) Placing biojava.jar in my jre/lib/ext directory instead of the same dir as SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter
(this is the first class referenced from biojava.jar)
1) Just see if it will find the proper jar on my classpath
Manifest: Main-Class: org/biojava/app/SequenceSpiral
I have biojava.jar on my classpath but not in same directory as SequenceSprial.jar
java -jar SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter
2) Specify the name if the jar in the Manifest Classpath and see if it will find the proper jar on my classpath
Manifest: Main-Class: org/biojava/app/SequenceSpiral
Manifest: Class-Path: biojava.jar
I have biojava.jar on my classpath but not in same directory as SequenceSprial.jar
java -jar SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter
3) Specify the path of the jar in the Manifest Classpath
Manifest: Main-Class: org/biojava/app/SequenceSpiral
Manifest: Class-Path: d:/biojava/biojava.jar
I have biojava.jar on my classpath (D;\biojava\biojava.jar) but not in same directory as SequenceSprial.jar
java -jar SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter
(note that in this case it is not fnding my main even though the Main-Class is specified)
4) Specify current directory and biojava.jar in the Manifest Class-Path
Manifest: Main-Class: org/biojava/app/SequenceSpiral
Manifest: Class-Path: .;biojava.jar
I have biojava.jar on my classpath (D;\biojava\biojava.jar) but not in same directory as SequenceSprial.jar
java -jar SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter
5)Specify current directory and the URL of biojava.jar in the Manifest Class-Path
Manifest: Main-Class: org/biojava/app/SequenceSpiral
Manifest: Class-Path: . d:/biojava/biojava.jar
I have biojava.jar on my classpath (D;\biojava\biojava.jar) but not in same directory as SequenceSprial.jar
java -jar SequenceSpiral.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/biojava/bio/seq/FeatureFilter.
Thank you very much for any help or suggestions,
David Maynard

I did some more testing and I think I now understand what is going on.
I don't like it, but at least I understand it.
The problem: I have an app packaged into a JAR file, myApp.jar. It has a dependancy upon an external JAR file extern.jar.
extern.jar is on my Classpath (and also in jre/lib/ext)
1) For some reason (bug?) java -jar myApp.jar does NOT use the classpath or the jre/lib/ext mechanisms to find .jar files needed to resolve references to external classes. This seems to be true even if you add an explicit -classpath argument on the command line!
thus
java -jar -cp c:\\absolutePathToMy\extern.jar myApp.jar
also fails as does
java -cp c:\\absolutePathToMy\extern.jar -jar myApp.jar
2) Inside the myApp Jar file you can specify a URL to an jar extension jar file but the URL IS RELATIVE TO THE PATH WHERE THE myApp.Jar is executed from! If I add the Manifest item Class-Path: ..\..\..\myexterndir\extern.jar then
java -jar myApp.jar
works correctly and resolves the external references.
This is why several people have reported that this class-path mechanism works ONLY when the extern.jar file is in the SAME DIRECTORY as the myApp.jar file when they had added a Class-Path: extern.jar to the Manifest.
However together these two items make it IMPOSSIBLE to distribute myApp.jar to others and have it work since the path names statically encoded inside the jar are relative to where the jar gets executed from. If I move myApp.jar to a different location on my hard drive it may also fail.
In my case I know all my customers already have extern.jar (5MB) installed on their classpaths and I would like to just send them the myApp.jar ( .5MB ).
However I don't see how to do this given the current specification of a JAR file, and the bug that makes all -jar file act like they have the Sealed=true property.
I tried explicity setting Sealed=false in the manifest but this didn't seem to have any effect.
I hope that this will save others the many hours of time it has taken be to determine that JARS are not well suited for deploying apps with dependenncies on external libs.
I also hope that someone can show me how execute a JAR and specify a classpath that doesn't get IGNORED my the classloader used in loading the jar classes.
This is using java version:
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
Does any one know this bug is fixed in a later release?
David Maynard

Similar Messages

  • Jar file and classpath problem

    I0m writing a program that use the kunststoff.jar Look&Feel.
    Now I would like to put all I'm writing into a jar file but I always have a NoClassFoundException when I try to start my application.
    here is a MANIFEST:ME I'm using:
    Manifest-Version: 1.0
    Created-By: 1.4.2-beta (Sun Microsystems Inc.)
    Main-Class: JListaR.JListaR
    Class-Path: kunststoff.jar img\ .why this don't work?

    Unfortunately you can't embed jars within a jar and
    expect them to be referencable for the classpath from
    outside the main jar. The "Class-Path" attribute in
    the manifest is used to refer to other jar files
    outside of your jar file.
    The usual approach to solve this problem is to unpack
    the jar files you want to embed and then rejar
    everything together in one big jar file again. This
    isn't always a great approach though, I know I'm
    looking for an alternative. So far my only alternative
    is dynamic class loading using a classloader, however
    this isn't great if you need to refer to several
    hundreds or even thousands of classes.thank you very mach...now I understand because it dosen't work correctly!

  • Jar file and classPath

    Hi,
    I have created a jar file using jar cvmf manifest classes.jar *.* in a directory under wich I can have put all my class files.
    When I run the class containing the main program, everything works fine. However, when I run the executable jar file, I get access to the main method (which calls a swing JFrame which shows a menu), but the classes called by the JButtons on the menu do not react. I seem to be having a problem in my classpath. I am working in NT4, and have included in my classpath the full pathname (d:\classes\classes.jar). Can anyone help please?

    Are you getting any error messages? Have you put debugging code in those classes to see what is happening?

  • Jar files and classpath

    Hello
    i have built a console application in jbuilder which depend on some jar file as libraries (example log4j ....)
    when i run it from jbuilder i have no problem... but when i try from console i get the following error
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout
    at fluxpromo.clsMain.main(clsMain.java:45)
    i know its a classpth issue but iam not able to fix it .. anyone can help me out with this
    thx

    i did using java -classpath D:\log4j.jar -jar
    app.jar
    but still have the same error, any idea why?When you use the -jar option, the only classpath that is used in the Class-Path in the jar. So you need to use either -classpath or -jar, but not both. For example,
    java -classpath d:\log4j.jar;app.jar;another.jar main.package.MainClass

  • How to Add JAR files and Config files to CLASSPATH at runtime?

    QUERY:
    During runtime, I need to load the JAR files and relevant config files( .cfg files and .properties file) into CLASSPATH and run a specific java program from one of the JAR which is available in CLASSPATH.
    Please advise me any relevant Java API details or a sample java program to implement the above use case.
    Thanks in advance.

    During runtime, I need to load the JAR files and relevant config files( .cfg files and .properties file) into CLASSPATH and run a specific java program from one of the JAR which is available in CLASSPATH.
    Please advise me any relevant Java API details or a sample java program to implement the above use case.
    You don't add to YOUR classpath once your app is launched.
    You create a NEW process for the app you want to run and provide the proper environment for it to run in - including any PATH or CLASSPATH environment variables.
    The Java API for the ProcessBuilder class has a simple example that shows how to create the arguments and launch an external application.
    ProcessBuilder (Java Platform SE 7 )
    There are also PLENTY of other examples of using ProcessBuilder; just search the net.

  • How to extract html file and folder from jar file

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

  • Please help: Example how to peploy application from jar file step by step

    Please help: Example how to peploy application from jar file step by step.
    All help appreciated
    Mike

    Thanks I will try these links
    Mike
    "Slava Imeshev" <[email protected]> wrote:
    Hi Mike,
    These links could be useful:
    http://e-docs.bea.com/wls/docs61////adminguide/appman.html
    http://e-docs.bea.com/wls/docs61////quickstart/quick_start.html
    http://e-docs.bea.com/wls/docs61//////ConsoleHelp/application.html
    http://e-docs.bea.com/wls/docs61///programming/environment.html
    Regards,
    Slava Imeshev
    "Mike" <[email protected]> wrote in message
    news:3ca0e94c$[email protected]..
    Please help: Example how to peploy application from jar file step bystep.
    All help appreciated
    Mike

  • Help! Read raw Image data from a file and display on the JPanel or JFrame.

    PLEASE HELP, I want to Read Binary(Raw Image)data (16 bit integer) from a file and display on the JPanel or JFrame.

    Hey,
    I need to do the same thing. Did you find a way to do that?
    Could you sent me the code?
    It's urgent, please.
    My e-mail is [email protected]

  • Hi everybody,please someone help me,i had a 3gs last year and i bought a 4,but itunes doesn't synch videos from photos file and it crashes,every time i try to synch photos it stacks when videos try to synch and crashes,what to do please?

    hi everybody,please someone help me,i had a 3gs last year and i bought a 4,but itunes doesn't synch videos from photos file and it crashes,every time i try to synch photos it stacks when videos try to synch and crashes,what to do please?

    hi i had the same problem today when i updated my itunes to latest version. however, i have just found my songs in the 'itunes media' folder. this was accessed through 'my music'  then keep clicking through until you find itunes media and all my library songs were in there and i then just added these files to my library and all were restored however, i have lost all my playlists but at least my 700 songs are back. very dissapointed with apple that they have let this happen with their latest update, the previous version was miles better than this one . hope you find them. stevo

  • Hello i need a help about script to export translatable text strings from ai files and import them back

    Hello i need a help about script to export translatable text strings from ai files and import them back after editing, thanks in advance

    Lanny -
    Thank you for taking the time to help with this problem. Can I just say however that as someone who has posted a first comment here and quite clearly never used a forum like this before, your comment unfortunately comes across as very excluding. It makes me feel there are a set of unwritten rules that I should know, and that I don't know them shows that the forum is not for me. In short, it's exactly the kind of response that stops people like me using forums like this.
    I'm sure it's not intended to be received like this and I am sure that the way you have responded is quite normal in the rules of a forum like this. However, it is not normal for those of us who aren't familiar with forums and who only encounter them when they have a genuine problem. This is why I hope it is helpful to respond in full.
    The reason I posted here is as follows. I was directed here by the apple support website. The original comment seemed to be the only one I could find which referred to my issue. As there is no obvious guidance on how to post on a forum like this it seemed perfectly reasonable to try and join in a conversation which might solve more than one problem at once.
    Bee's reply however is both helpful and warm. This could in fact be a template for how new members should be welcomed and inducted into the rules of the forum in a friendly and inclusive way. Thank you very much indeed Bee!

  • Target to execute multiple junit tests from jar file

    I have written a custom selenium framework using JUnit and Selenium, problem I am having right now is our team wants to run the tests inside HP Quality Center (I have no idea or any experience with Quality Center) but if I provide a jar file the them they can execute it inside the Quality Center (Reason to run it in Quality Center is for reporting purpose).
    Problem is that I have created my framework in away that You can create multiple JUnit base test files for different tests also keep in mind that these classes dont need main method (This is where the problem when it comes to jaring up ). I have introduced following ant target to run all the test cases.
         <target name="test.selenium" depends="jar" description="target to execute all the selenium tests.">
              <junit printsummary="yes">
                   <classpath>
                        <path refid="classpath"/>
                        <path refid="application"/>
                   </classpath>
                   <batchtest fork="yes">
                        <fileset dir="${src.dir}" includes="**/Test*Selenium.java"/>
                   </batchtest>
              </junit>
         </target>above ant target runs without any problem, but when you jar it up you need a manifest and main class, is there away I cant introduce some attribute that can execute all my tests without adding main method to each of them.
    Here is my ant target for jar
         <target name="jar" depends="compile"
                   description="Generates final jar">
              <copy todir="${build.jar}">
                   <fileset dir="lib" excludes="**/*.java"/>
              </copy>
              <jar jarfile="${build.jar}/yukonSelenium.jar"
                        basedir="${build.classes}">
                   <manifest>
                        <attribute name="Main-Class" value="com.somepackage.selenium.test.TestAuthenticationSelenium"/>
                        <attribute name="Class-Path"
                             value=". /c:/build/jar/log4j-1.2.15.jar /c:/build/jar/junit-4.6.jar /c:/build/jar/selenium-java-client-driver.jar /c:/build/jar/dom4j-1.6.1.jar"/>
                   </manifest>
              </jar>
         </target>And this is how the Test Class looks like, I have added main method in this but once i do this after jaring java -jar myJarfile.jar will only execute just the class i have main method init.
    public class TestAuthenticationSelenium extends SomePrivateFrameWorkClass {
         private void init() {
              start();
         @Test
         public void testProductNav() {
                //somecode
         @Test
         public void multipleLogin() throws FileNotFoundException, InterruptedException {
                             //Some Code
         public static void main(String[] args) {
              org.junit.runner.JUnitCore.main("com.somepackage.selenium.test.TestAuthenticationSelenium");
    }Please let me know if i should put the entire ant build file.
    Thanks for any help.
    anuradha.uduwage
    Edited by: Tilter on Aug 24, 2009 10:05 PM
    Edited by: Tilter on Aug 24, 2009 10:06 PM

    What i mean is if i have 3 class files in my jar file, and each one of those classes has a main method, how will i be able to execute a class of my choice from that jar file. In manifest files, you specify the main class, but how would i specify multiple classes with main methods, or achieve my objective here.

  • Jar file problem , please help

    Hi guys , i am not sure if i am in the right place to have this post in so i'll give it a try
    i know my explanation might be a shot in the dark but i'll try my best
    i have made a program using eclips , to send emails using my email , on certain conditions
    so when that codition happenes on some class in my program
    this class will call the email class and send an email to someone
    now the problem is not in the program , because as along as this program is in eclips and i run the program in eclips , everything goes fine , No errors what so ever
    but , if i make jar file , using eclips "export"
    once i run the program , the program would run , but once the same condition that ihave specified previously happenes , the current class never calls the email class , and no emails would be sent
    i am very confused wether
    1) it throws a class not found for some wierd reason
    2) or the external library that i used to send emails , is not exported
    i tried to check the CLASSPATH file and i think everything seems to be fine , so i dont know what the problem is
    so in short
    if the program is in eclips , every thign goes fine
    if the program is a jar file , then it would work fine but once it needs to send an email , it never does and i can still work on the program , but no emails will be sent
    thanks please some one help me out with this

    for more information here is the senario
    because i see that you guys are some how lost because i am not providing enough information
    so this is a detailed info of the problem
    i have 3 classes
    1) mybankmain (jframe)
    2) mybankbody (all labels and buttons and events included here)
    now: within some events in my program ,
    it calls a class called.....
    3) myEmail
    this class imports two things that are comming from an external jar file , so in short , if the external jar file is not available the program would complain
    i run this on windows xp (SP2)
    now: if this program runs on eclips , it would do everything it is supposed to do and all kind of calculations will be done and emails will be sent on the conditions that i have specified within the program
    if i make a jar file on windows , and i run the jar file , the file would work , all functionalities will work
    EXCEPT: sending an email
    - either my class is not found
    - or external jar file is not found which causes my class not to be able to perform its tasks
    i did only one test
    which is that i switched the main and i made myEmail as a main and i tried to export the jar file
    Result: jar file doesnt work
    the way i view whatever inside my jar file , i use Winrar and it would view everythign in the jar file and i see that all my classes are included there
    if i open my CLASSPATH , i see that there is a pointer to the external jar file
    if i open my manifest : i DO NOT see the exrernal jar file in there but i do see that its pointing to my main class
    class main : mybankmain
    and there is only the version and signiture
    i hope all these additional details would help in determining the problem that ihave been trying to solve for 2 weeks now

  • Finding the source code from Jar file

    Hi,
    I am a beginner java programmer but have been entrusted with learning our company's Java application. The architect of the application is not forthcoming in sharing information and so I need help in tracing the source code for the application. I know where the .jar files are stored but I don't know where the actual .java or .class files are stored.
    In the .profile file, I see the classpaths set to various jar files. eg.
    CLASSPATH=$PATH:/eaid01_apps/merc01/libs/tools/java/drivers/bin/eaiRun.jar
    When I view this jar file with command "jar tf eaiRun.jar", it displays all the files under it. Onc such listing is as following:
    citi/eai/EAI.class
    citi/eai/Interface.class
    I want to go to that specific directory on our file system which is storing these .class or.java file. From what I have learned about packages, I should find some folder called 'citi' ,'eai'.
    However I am not able to find these folders anywhere on file system. Is there a way I can find where the actual souce code is by looking at the jar files.
    Please help. Let me know if you need more information.
    thanks,
    Anand.

    Is there a way I can find where the actual souce code is by looking at the jar files.No, in general you can't, you should ask the architect that you mentioned earlier. The name of the source file is sometimes stored in the .class file for debugging purposes but that's unlikely going to help you find the files.
    You should also ask if he/she has got any documentation of the system. It's often a lot easier to follow documentation written in human language than program code written in a programming language. There could be documentation in a format similar to this: http://java.sun.com/j2se/1.4.2/docs/api/

  • J2SE 1.4 cannot import from JAR files

    Windows 2000
    J2SE 1.4.0
    Textpad (IDE)
    Everytime I attempt to use a package from a JAR file, I get a "package _name_ does not exist" during compilation. If I un-jar the package, then the compilation runs normally.
    I am putting the JAR files in c:\program files\j2sdk1.4.0\lib and my classpath is set to .;c:\program files\j2sdk1.4.0\lib. I don't think its a classpath problem though, because it only occurs with JAR files.
    Textpad performs the following command to compile: javac filename. Manually compiling does not help, nor does using the -classpath option.
    It is as if javac is not looking in the JAR files, and like I said if I un-jar the package, everything compiles normally. This has been driving me crazy for a couple of months now, and I would really appreciate any hints anyone can give me as to what might be causing this.
    Thanks,
    Jeremy Figgins

    I just decided to check if it was possibly a bad installation; the problem occurs on my other Win2k machine as well, so that precludes that possibility. The directory structure on the other machine is slightly different as reflected by its CLASSPATH:
    .;C:\Program Files\java\lib
    Thanks,
    Jeremy Figgins

  • Cannot load component from JAR file.

    I got the message : cannot load component ... from JAR file. The class must be compiled and must be on the classpath of the project...
    I just add a javabean from a JAR file from Palette manager, then drag and drop it, then got this message.
    Can anyone tell me what i was wrong ? Thank you.

    Hi,
    You should paste your error log here to easy for other to help you.
    For your scenario, it is a big chance you didn't include the jar file into your classpath, please check.
    Thanks.

Maybe you are looking for

  • Dual channel problems?

    Hi all, I purchased an 8GB set of 10666 GSkill memory for my dv7t-3300 CTO core i7 laptop in December of last year. I first posted in the G.Skill support forums and they recommended I try HP, I will copy over my entire post there as it is detailed as

  • How to change Switch between open documents keyboard shortcut (default Control + Tab or Cmd + ~)

    I use Control + Tab and Control + Shift + Tab or Cmd + ~ and Cmd + Shift + ~ to switch between tab back and forth alot how do I change the shortcut to something else? On Photoshop CC 2014 mac

  • HDMI audio and video problems on new DV6t se

    Just received my HP Dv6t laptop and i immediately upgraded to Windows 7 ultimate. I am facing two problems, Firstly, if i disconnect and reconnect the HDMI cable the sound only comes from the speakers and not the monitor (works fine with my HP HDX16t

  • Downloaded Itunes, will not open!

    I ha downloaded Itunes twice .  It will not open!

  • Password History Depth

    Hello, Re:  password history depth, SAP note 2467 (dated: 7-12-06) states:  “ The size of the password history is static (5) and cannot be customized.”  Is SAP considering making this value configurable? Thanks in advance for any responses.