Jar files and Main-Class attribute

Sorry, I know there are other topics regarding this argument but none of them helped me solving my problem.
I've tried a thousand time in every possible way, but I still can't run my application from a jar file. I've got a package called client, whose main class is called Client. The package contains a sub-package called Icons. I've put everything into a jar file and added this manifest:
Manifest version: 1.0
Name: client/
Sealed: True
Main-Class: client.Client
But it won't work. I've tried to erase the Sealed part, I've tried "Main-Class: Client" and also "client/Client", I've tried putting into the jar the client directory and I've tried omitting it, but the answer is always the same:
Failed to load main-class header etc.
Can anyone help me? Please, I'm almost desperate!
Thanks

Here's the verbose-mode description of what I did.
jar -cfv client.jar clientaggiunto manifesto
aggiunta in corso di: client/(in = 0) (out= 0)(archiviato 0%)
aggiunta in corso di: client/.nbattrs(in = 767) (out= 310)(compresso 59%)
aggiunta in corso di: client/Client.class(in = 533) (out= 340)(compresso 36%)
aggiunta in corso di: client/Client.java(in = 288) (out= 140)(compresso 51%)
aggiunta in corso di: client/ClientForm$1.class(in = 691) (out= 383)(compresso 44%)
aggiunta in corso di: client/ClientForm$10.class(in = 678) (out= 380)(compresso 43%)
aggiunta in corso di: client/ClientForm$11.class(in = 689) (out= 385)(compresso 44%)
aggiunta in corso di: client/ClientForm$2.class(in = 686) (out= 379)(compresso 44%)
aggiunta in corso di: client/ClientForm$3.class(in = 686) (out= 381)(compresso 44%)
aggiunta in corso di: client/ClientForm$4.class(in = 686) (out= 380)(compresso 44%)
aggiunta in corso di: client/ClientForm$5.class(in = 686) (out= 383)(compresso 44%)
aggiunta in corso di: client/ClientForm$6.class(in = 718) (out= 399)(compresso 44%)
aggiunta in corso di: client/ClientForm$7.class(in = 718) (out= 400)(compresso 44%)
aggiunta in corso di: client/ClientForm$8.class(in = 718) (out= 399)(compresso 44%)
aggiunta in corso di: client/ClientForm$9.class(in = 718) (out= 398)(compresso 44%)
aggiunta in corso di: client/ClientForm.class(in = 33070) (out= 13510)(compresso 59%)
aggiunta in corso di: client/ClientForm.form(in = 131398) (out= 4521)(compresso96%)
aggiunta in corso di: client/ClientForm.java(in = 73435) (out= 6863)(compresso 90%)
aggiunta in corso di: client/Icons/(in = 0) (out= 0)(archiviato 0%)
aggiunta in corso di: client/Icons/brick.gif(in = 1044) (out= 1049)(compresso 0%)
aggiunta in corso di: client/Icons/corpo.gif(in = 4011) (out= 3400)(compresso 15%)
aggiunta in corso di: client/Icons/door.gif(in = 1092) (out= 1097)(compresso 0%)
aggiunta in corso di: client/Icons/floor.gif(in = 1102) (out= 1107)(compresso 0%)
aggiunta in corso di: client/Icons/mappa.gif(in = 20901) (out= 20575)(compresso 1%)
aggiunta in corso di: client/Icons/paesaggio.gif(in = 18962) (out= 18603)(compresso 1%)
aggiunta in corso di: client/Icons/sole.gif(in = 7063) (out= 6546)(compresso 7%)
aggiunta in corso di: client/Icons/trap.gif(in = 1062) (out= 1067)(compresso 0%)
aggiunta in corso di: client/Icons/void.gif(in = 842) (out= 847)(compresso 0%)
aggiunta in corso di: client/Listener.class(in = 1869) (out= 1136)(compresso 39%)
aggiunta in corso di: client/Listener.java(in = 2296) (out= 708)(compresso 69%)
aggiunta in corso di: client/manifesto.txt(in = 62) (out= 58)(compresso 6%)
aggiunta in corso di: client/ScorciatoieDialog$1.class(in = 740) (out= 391)(compresso 47%)
aggiunta in corso di: client/ScorciatoieDialog$PopupListener.class(in = 1579) (out= 773)(compresso 51%)
aggiunta in corso di: client/ScorciatoieDialog.class(in = 3524) (out= 1638)(compresso 53%)
aggiunta in corso di: client/ScorciatoieDialog.form(in = 8500) (out= 910)(compresso 89%)
aggiunta in corso di: client/ScorciatoieDialog.java(in = 5676) (out= 1222)(compresso 78%)
jar umf mainclass.txt client.jar[NOTE: mainclass.txt only contains the line "Main-Class: client.Client"]
java -jar client.jarFailed to load Main-Class manifest attribute from
client.jar
I've also tried to manually create a MANIFEST.MF file that only contained the following lines:
Manifest Version: 1.0
Main-Class: client.Client
guess what was the result?
java -jar client.jarException in thread "main" java.io.IOException: invalid manifest format
at java.util.jar.Manifest.read(Manifest.java:193)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at java.util.jar.JarFile.getManifest(JarFile.java:158)
>
the same procedure with the addition of "Name: client/" before the main-class attribute generated the usual "Failed to load Main-Class manifest attribute" result. So now what?!? I'm getting crazy....

Similar Messages

  • Jar files and Main-Class headers

    I think I already posted this, but I can't find it on the forum...my apologies if it's already there and I'm just blind or something.
    I have a bunch of classes in the directory C:/chess/server , and I want to make a .jar file with these classes. The class with the main method is server/ChessServer.class . From which folder should I create a jar file with these classes, and how exactly should I label the Main-Class header in the manifest file? Also, what's the purpose of the "Name:" header?
    I know the topic is posted a lot, but I've tried many different ways and I can't get this to work. I get many variations on the "NoClassDefFoundError". I know the classes themselves are fine because they work perfectly when they're not in a .jar file.
    Thanks in advance!

    I tried that, and it still doesn't work. I used the command C:\chess> jar 0cmf manifest.mf MuChess.jar server . Manifest.mf is:
    Main-Class: server.ChessServer
    Sealed: true
    When I try to run it with C:\chess> java -jar MuChess.jar , I get:
    Exception in thread "main" java.lang.NoClassDefFoundError: server/ChessServer (w
    rong name: ChessServer)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    3)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    When I unpack the file with my excraction utility, I get get two folders: One is "server", and contains all the files it should--including ChessServer--, and the other is "META-INF" and contains the following MANIFEST.MF file:
    Manifest-Version: 1.0
    Sealed: true
    Created-By: 1.4.1_03 (Sun Microsystems Inc.)
    Main-Class: server.ChessServer
    Any ideas?

  • Manifest file and main class location problem

    my main class is in not in the root of the jar file, it is down a package tree structure, and whenever I run the jar it says
    Failed to load Main-Class manifest attribute from
    xxxxx.jar
    How do I specify the location of the main class? like this??
    Main-Class: com/Utilities/visual/Model
    thanks for your help.

    It should be
    Main-Class: com.Utilities.visual.Model
    and make sure your manifest file has an empty line at the end of your file (i.e. press enter after the last line in your manifest line).

  • ANT - Jar File include another Jar file and importing classes

    Here is the directory structure i have set up:
    FTPGetter
      \src
        \com
          \abc
            \ftpgetter
              - GUI.java
              - FTPGetter.java
              - Login.java
      \classes
      \include
        - ftpClient.jar
        - info.xml
      \jar
        - FTPGetter.jarThe code compiles file and can create a Jar file without errors. But when I execute the Jar file, I get
    java.lang.NoClassDefFoundError: com/abc/ftpclient/FTPwhich is a class that I import from the ftpClient.jar file in FTPGetter.java
    What gives?
    Here is my necessary build.xml code:
    <?xml version="1.0"?>
    <project name="FTPGetter" default="all">
      <property name="src.dir"        value="src"/>
      <property name="package.name"   value="com.abc.ftpgetter"/>
      <property name="package.dir"    value="${src.dir}/com/abc/ftpgetter"/>
      <property name="classes.dir"    value="classes"/>
      <property name="include.dir"    value="include"/>
      <property name="jar.dir"        value="jar"/>
      <property name="javadoc.dir"    value="docs"/>
      <property name="javadoc.title"  value="FTPGetter"/>
      <property name="javadoc.header" value="FTPGetter - By ABC XYZ [2005]"/>
      <property name="run.classname"  value="${package.name}.FTPGetter"/>
      <target name="init">
        <mkdir dir="${javadoc.dir}" />
        <mkdir dir="${classes.dir}" />
        <mkdir dir="${jar.dir}" />
      </target>
      <target name="all" depends ="compile,jar" />
      <target name="compile" description="Compile Java code" depends="clean, init">
        <javac srcdir="${package.dir}" destdir="${classes.dir}">
          <classpath>
            <!-- use the value of the ${classes.dir} property in the classpath -->
            <pathelement path="${classes.dir}" />
            <!-- include all jar files  -->
            <fileset dir="${include.dir}">
              <include name="**/*.jar"/>
            </fileset>
          </classpath>
        </javac>
      </target>
      <target name="clean" description="Clean up">
        <delete dir="${javadoc.dir}" />
        <delete dir="${classes.dir}" />
        <delete dir="${jar.dir}" />
      </target>
      <target name="jar" depends="compile">
        <jar jarfile="${jar.dir}/FTPGetter.jar" update="false">
          <fileset dir="${classes.dir}" includes="**/*.class" />
    <!-- Include xml file to read.-->
          <fileset dir="${include.dir}" includes="info.xml" />
    <!-- Include ftpClient in the jar file.-->
          <fileset dir="${include.dir}" includes="ftpClient.jar" />
          <manifest>
            <attribute name="Main-Class" value="com.abc.ftpgetter.FTPGetter" />
            <attribute name="Class-Path" value="include/ftpClient.jar"/>
          </manifest>
        </jar>
      </target>
    </project>

    nevermind I got that fixed now:
    had to get the build.xml code for the <target name="jar" depends="compile">so that it looks more like:
      <target name="jar" depends="compile">
        <jar jarfile="${jar.dir}/FTPGetter.jar">
          <zipfileset dir="classes" prefix="" />
          <zipfileset src="include/ftpClient.jar" />
          <zipfileset dir="${include.dir}" includes="info.xml" />
          <manifest>
            <attribute name="Main-Class" value="com.abc.ftpgetter.FTPGetter" />
          </manifest>
        </jar>
      </target>Keyword would need to be zipfileset.

  • Jar files and Inner classes..

    I am trying to compile a java source file of a class that has an inner class.. using GNU Make. I am not sure if the .jar file is packing properly, because I get an error :
    Exception in thread "main" java.lang.NoClassDefFoundError: Airport$PortCode
            at Airport.getCode(Airport.java:133)
            at Airport.test1(Airport.java:228)
            at Airport.run(Airport.java:241)
            at Airport.main(Airport.java:255)where Airport.class is the main class and Airport$PortCode is an inner class of it (it is not static and is declared public)
    it works when I use it via "java Airport" but again i get the above error when I run with "airport.jar"
    thanks for you help

    I tried to test it on UNIX, but it replied to my
    commandUh, I am not so lucky to have a UNIX license (and don't see the need). Possibly the find on UNIX is different from GNU's find.
    find: path-list predicate-listUse backticks: The output of the command between backticks is used as the value for the shell variable. Possibly it could be the case that your find program does not allow the omission of the path list, then just make it:
    CLASSES=/home/here/there/project/classes
    `find $CLASSES -name "*.class"`Execute this command and the output of the command executed can be used as a return value.
    -name "*.class"look for all files ending on name.
    You can always do:
    $ man find (man is great)
    or
    $ info find>
    >
    >
    JARCLS    = `find -name "*.class"`

  • Clarification of JAR file and separate classes

    Hi all,
    I wanted to clarify a basic question. When do we club all classes to make a JAR file? For instance, in a web app with servlets, had all the servlet classes been put into a single JAR file, would that work? I know that woudn't but why?
    Is JAR file like a single executable (.exe) file? So, when (which type of applications) do we need single JAR and when separate classes?
    thanks much

    Thanks, I've gone thru it. So, sounds like JAR file can be used for invoking app thru command line or from some other app or even running applet in a browser. It can not be used for a servlet or jsp application. Am I right?

  • Want to package a class file and a jar file in main jar file

    hello folks,
    i have a class named launch.class
    and a jar file named First_Sample2.jar
    First_Sample2 is an application that i have made which requires more memory than is generally allocated by the JRE. so, launch.java file just contains code to execute the command:
    javaw -Xms128M -Xmx256M -jar " + path + "First_Sample2.jar"
    where path variable refers to a directory which contains First_Sample2.jar
    problem is that the only way i can use this code is by keeping two separate JAR files, one is launch.jar, the other is First_Sample2.jar and then execute launch.jar, which will in turn call First_Sample2.jar (which means I have to provide anyone with 2 separate files if they want to use my application)
    is there any way in which i can combine both these jar files into one?

    Well there is a couple ways you can achieve this, but I am telling you that packaging a JAR within a JAR will not work because classes within the internal JAR will not be recognized on the classpath.
    The easiest way to get the user to run your program with a simple double click would be to hide the two JAR files from them completely, having them reside in a folder somewhere on the user's computer. I would use a batch file (Windows environment) or an .sh file (Unix) that would set up your classpath variable and then call java to execute the main class in your main JAR.
    For instance:
    cd [Where java.exe resides]
    set CLASSPATH=[semi-colon delimited absolute file paths pointing to your two JAR files and any other JAR files that they reference]
    java -cp %CLASSPATH% [main class]
    The user would have access to this batch file, perhaps on their desktop, where they can double click to execute teh program just as if it were an EXE file. This is the best way because it hides the JAR files from the user.
    If you would like to combine the two JAR files however, you would need to extract the contents of the secondary JAR file and then include them in with the contents of the main JAR file. That is the only other way that all classes are visible on the classpath.

  • Problem in file association and main-class in JWS

    Hello , all
    I have a problem in JWS with file association and main-class. I have a java application that has two entry classes, one is appmain.class that is required to launch from web, and the other is player.class that is required to launch when user double-click the .abc extension file.
    In JWS 5.0+, there is a association element in JNLP syntax that can be used to make the file association with .abc extension. But how can I declare the main-class in JNLP file?
    If I declare the application-desc element as <application-desc main-class="player">, the player.class will be launched from web. But if I declare it as <application-desc main-class="appmain">, the .abc extension wil be associated to the appmain.class.
    Does anyone know how to solve this problem? Thank you for your kindly help.

    One way is to define a third main that refers
    to the other two, as appropriate. E.G. if the
    web based main does not include -open as
    its arguments, it is easy.class WebStartSpringboard {
      /** Call web based main unless args include -open. */
      public static void main(String[] args) {
        if (args[0].equals("-open") ) {
          OpenFileBasedClass.main(args);
        } else {
          WebBasedClass.main(args);
    }Other measures might be taken for a situation
    where the web based version does include a
    -open argument.

  • Encryption/decryption through jar file and classes

    Hi,
    My application uses tomcat as web server.
    I am doing encrytion and decyption.
    i fetch encypted data from database and then decrypt it
    If i use calsses in webapps -> WEB-INF -> classes folder, i place classes in that ,
    In other case i use jar file and place that file in WEB-INF -> lib folder in the webapps directory.
    There is huge performance difference.
    While using classes performance is great while using jar file performance is very disappointed.
    I am using a file for encryption /decryption also.

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

  • Help with creating jar file and running it ?

    Hey guys,
    I have a program with a package called classes and a sub-package called classes.mainLib.
    I am trying to create a JAR file of the class files in mainLib. There is only one class file in classes and that contains the main method. So this is what i am doing:
    1. create a manifest file with: Main-Class: classes.Cars
    2. from within the mainLib directory (./program_name/classes/mainLib/) i do this:
    jar cvf mainLib.jar manifest ./*.class
    3. Then i move this jar file to ./program_name/lib and change directory to ./program name/
    4. try to do this: java -jar ./lib/mainLib.jar
    But it errors with:
    gary@linuxbox:~/java/cars$ java -jar ./lib/mainLib.jar
    Failed to load Main-Class manifest attribute from
    ./lib/mainLib.jar
    Any ideas why this is happening. the manifest is included in the jar'ing
    Thanks.

    At a glance, it looks like you are placing only the
    class files in the jar and trying to navigate your
    classpath to run it. Instead, you have to place ALL
    the package folders into the jar from the root of
    your package hierarchy and the jar runs anywhere, in
    any folder. The packages are INSIDE the jar.
    also I see cars/classes in a path you describe ...and
    the program seems to wnat classes/Cars ??? Could
    this be an additional issue (or am I missing seeing
    something about your package structure)?Firstly, i believe all my spelling and cases are correct.
    I have the following strcuture:
    Cars.class (contains main) : package classes in ./classes directory
    All other classes : package classes.mainLib in ./classes/mainLib
    I would like to jar ALL files in mainLib but not the class that contains the main method. Is this possible?
    I'm not sure how clear i was earlier, hope this is more understandable.

  • JRockIt Deleting JAR files - Error loading class

    Hi there,
    Customer is facing a very weird issue. Their application has an application that contains some EJBs and Web applications that, apparently for no reason, it starts to unload classes and delete JAR files and WAR files from the Weblogic's "extract" directory. If I bounce the application, everything starts working fine until a moment where the issues starts again.
    I thought this was any kind of memory issue that was not allowing the JVM to free enough resource for loading the classes again after unloading it. But we gave enough memory for the JVM and it stills happening.
    Thoughts? Any idea that might help us on troubleshooting is very welcome at this time.
    Thanks in advance,
    Davi

    e-blade wrote:
    Manifest-Version: 1.0
    Class-Path: lib/tools.jar
    Created-By: 1.6.0_18 (Sun Microsystems Inc.)
    Main-Class: MainThe line in bold means: when app.jar will be run, it will look for additional classes in <same OS directory as itself>/lib/tools.jar.
    It does not mean that it will look inside itself in the JAR directory /lib/tools.jar.

  • Update jar file with modified class files

    hi all,
    I'm developing a jar utility for updating a jar file with modified class files as of now i have reached a point where in i can browse files and set it to required location
    i.e i have developed a swings GUI application using JfileChooser and browse the files ..now my requirement is to update the jar files with modified class file
    GUI looks like below
    ....enter the modified class file ----> d:\c.class
    ....enter the jar file path ---> d:\a.jar
                                                          update button now i have the requirement as
    1> when i click on the update button ,my jar file (a.jar) should get updated with the latest class file (c.class)
    can u help me to achieve this requirement.???
    im stuck with this,,,if u can provide me wit the code for updating jar file with latest class file...it will really be helpful
    if u can help me with the code on click on update button it will be really helpful
    Thanks and expecting a faster response from u all java experts....

    Please find my query in bolds...i have written the partial code now,i need some help now
    hope u guys can help me out...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    public class FileExplorer extends JDialog implements ActionListener
         JTextField txtLocation_class;
         JButton btnBrowse_class;
         JLabel label_class;
         JTextField txtLocation_jar;
         JButton btnBrowse_jar;
         JLabel label_jar;
         JButton updatebutton;
         public FileExplorer()
                   setSize(600,300);
                   //for class files
                   label_class = new JLabel("Please select Modified Class File");
                   txtLocation_class= new JTextField(20);
                   btnBrowse_class = new JButton("Browse");
                   btnBrowse_class.addActionListener(this);
                   //for jar files               
                   label_jar = new JLabel(" Please select the Jar file");
                   txtLocation_jar= new JTextField(20);
                   btnBrowse_jar = new JButton("Browse");
                   btnBrowse_jar.addActionListener(this);
                   ActionListener updateListener = new ActionListener(){
                    public void actionPerformed(ActionEvent ae){
                     if(ae.getActionCommand().equalsIgnoreCase("Update")){               
                      System.out.println("ae.getActionCommand() :: "+ae.getActionCommand());
                      System.out.println("Update Button is pressed");               
                    *//Query :how do i access FilePath and FilePath1 here which*
    *                // has been set in public void actionPerformed(ActionEvent ae)*
    *                //method below*
    *                // FilePath  ---??*
    *                // FilePath1  ---??*
    *                // how do i access the above 2 parameters*
    *                //Query :on click of update button i have to pass*
    *                //two parameters FilePath and FilePath1 to*
    *                //perform some functionality. please help me*
    *                //to achieve this..how do i access Filepath and Filepath1*
    *                //here which has been set below.*
                     } // end of if               
                   } // end of actionPerformed
                };// end of ActionListener
                  updatebutton = new JButton("Update");
                  updatebutton.addActionListener(updateListener);
                   //adding to the panel               
                   JPanel pnl = new JPanel();
                   pnl.add(label_class);
                   pnl.add(txtLocation_class);
                   pnl.add(btnBrowse_class);
                   pnl.add(label_jar);
                   pnl.add(txtLocation_jar);
                   pnl.add(btnBrowse_jar);
                  pnl.add(updatebutton);
                   getContentPane().add(pnl);                         
         public void actionPerformed(ActionEvent ae)
              Object obj=ae.getSource();
              if(obj==btnBrowse_class)
                   final JFileChooser fcstudent = new JFileChooser();
                   int rtrnval = fcstudent.showOpenDialog(this);
                   if(rtrnval==JFileChooser.APPROVE_OPTION)
                        try
                             File file=fcstudent.getSelectedFile();                         
                             String path = file.getPath();
                             System.out.println("This is Path:"+path);
                             txtLocation_class.setText(""+path);
                             String FilePath=txtLocation_class.getText();
                             System.out.println("FilePath is ::"+FilePath);                                        
                        catch(Exception ex)               
                             ex.printStackTrace();
              }else if(obj==btnBrowse_jar){
                             final JFileChooser fcstudent = new JFileChooser();
                             int rtrnval = fcstudent.showOpenDialog(this);
                             if(rtrnval==JFileChooser.APPROVE_OPTION)
                                  try
                                       File file=fcstudent.getSelectedFile();                         
                                       String path1 = file.getPath();
                                       System.out.println("This is Path:"+path1);
                                       txtLocation_jar.setText(""+path1);
                                       String FilePath1=txtLocation_jar.getText();
                                       System.out.println("FilePath is ::"+FilePath1);                                        
                                  catch(Exception ex)               
                                       ex.printStackTrace();
         public static void main(String arg[]){
                   FileExplorer Exm= new FileExplorer();
                   Exm.setVisible(true);
    }

  • Decompiling jar file and then run

    Dear Members,
    I have a jar file and I have decompiled that jar file and converted into class file,
    now I want to run/edit using source code ,I am unable to run source code with out put whatever coming in jar file running,
    I am trying with class in which
    public static void main(String[] args)
    function defined,
    I am using Jcreater1.5 and from command prompt also running but unable to run and edit the programm,
    how to run these class file in complete project that output will come as running jar file
    regards
    SACHIN

    It sounds like you have unpacked the jar.
    To edit the source you need to decompile the classes to .java files.
    [http://www.google.co.uk/search?q=java+decompiler]

  • JAR files and getResource()

    Hello i have the following piece of code in class x.y.z.Tester:
    String rootPath = this.getClass().getResource("/").getPath();          
    System.out.println(rootPath);which prints the path where the x.y.z.Tester class is located on my FS.
    for example if my class is store at:
    C/folder_1/bin/x/y/z/Tester.class
    the returned path would be:
    C:/folder_1/bin
    Now, when I bundle this class (along with others) in a JAR file and set the x.y.z.Tester as the main class and run it, i get this error:
    Exception in thread "main" java.lang.NullPointerException
    at com.nortelnetworks.productsupportability.netrx.service.report.generator.Tester.<init>(Tester.java:9)
    at com.nortelnetworks.productsupportability.netrx.service.report.generator.Tester.main(Tester.java:35)
    On line 9 is the first line of code above.
    On line 35 is the call to the method that has line 9.
    However, the funny thing is that when I unzip (or extract) the contents of my JAR file, the it works fine and returns the path where the x.y.z.Tester is stored.
    Now, I would like to have this work without having to unzip the JAR file. does anyone know if any issues or why the "getResource()" method returns a NullPointerException if it's JAR'ed.
    thank you,

    Not sure what your goal is, but try this.
    import java.net.URL;
    import java.security.CodeSource;
    import java.security.ProtectionDomain;
    public class CodeSourceExample {
        public static void main(String[] args) {
            CodeSourceExample object = new CodeSourceExample();
            Class cls = object.getClass();
            ProtectionDomain domain = cls.getProtectionDomain();
            CodeSource source = domain.getCodeSource();
            URL location = source.getLocation();
            System.out.println(location);
    }

  • 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

Maybe you are looking for

  • Analysis Authorization Issue 7.3

    Hello Friends, System BW 7.3, Currently there are 80 odd analysis authorization objects We want to introduce a new info object (GL Account) to be authorization relevant, ( there are few objects in the system which are already authorization relevant i

  • HT1386 I can no longer sync my books to my iPod touch.

    Okay someone help me out, PLEASE! My daughter and I bought new e-books and wanted to put them on our iPods to read with iBooks. First I tried with my daughter's. I added her books to her iTunes account. Her settings are set to sync all books, rather

  • Can I create a page border using Adobe Acrobat Pro 9?

    I'm making a certificate of completion and would like to create a page border.  Is there any way to do this is Adobe Acrobat Pro 9?

  • Exports slightly out of synch?

    Seems like when I export my edits (shot in HD) the audio is out of synch with the video by just a couple of frames. Not usually a big deal, but ruins the precision of my faster paced edits. Tip?

  • Quicktime Gamma problem when applying fliters

    Any help would be greatly appreciated: When I add a video filter to a quicktime movie in final cut, the image will get significantly darker. Thanks in advance!