Loading classes from another jar file

I've set up my jnpl file so that it references a core jar file (contains main() function). The jnlp also references another jar file (app.jar) which contains class files that I load and instantiate dynamically (using ClassLoader). The core.jar file contains a manifest that includes a reference to app.jar.
The app works fine when I use "java -jar core.jar" from the command line.
However, when I wrap the jars using jnlp, I always get a null pointer exception because it cannot find any class that is in the app.jar file. I've tried different strategies, such as trying to load a class file that sits on the server (in a jar file and not in a jar file), but that also fails if I use jnlp (However, it works if I use "java -jar core.jar")
Any ideas what is going on?

This is the "OckCore.jar" manifest before signing:
Manifest-Version: 1.0
Main-Class: com.Ock.OckCore.OckApp
Class-Path: . OckMaths.jar
Created-By: 1.4.0-beta3 (Sun Microsystems Inc.)
Name: com.Ock.OckCore.OckApp.class
Java-Bean: FalseThis is the manifest after signing:
Manifest-Version: 1.0
Main-Class: com.Ock.OckCore.OckApp
Created-By: 1.4.0-beta3 (Sun Microsystems Inc.)
Class-Path: http://hazel/Ock/. http://hazel/Ock/OckMaths.jar
Name: com/Ock/OckCore/OckApp.class
SHA1-Digest: KRZmOryizx9o2L61nN+DbUYCgwo=I have removed a load of irrelevant stuff from the "after" manifest to keep it readable.
note that :-
The OckApp.class loads normally from webstart and tries to load a class from OckMaths.jar.
I can prove that OckApp.class does load because it creates a log file when it does.
The OckApp.class tries to load a class from the OckMaths.jar. This fails if webstart is used but works if OckCore is launched using "java -jar OckCore.jar".
The jars do exist at the location specified by the manifest.
The application launches normally if I use "java -Jar OckCore.jar"
Here is the jnlp file
<?xml version='1.0' encoding='UTF-8'?>
<jnlp
     spec="1.0"
     codebase="http://hazel/Ock"
     href="OckMaths.jnlp">
     <information>
          <title>Ock Maths Demo</title>
          <vendor>Rodentware Inc</vendor>
          <description>Demo of a ported app running as a Java Webstart application</description>
          <description kind="short">An app running as a Java Webstart application"></description>
          <offline-allowed/>
     </information>
     <security>
          <all-permissions/>          
     </security>
     <resources>
          <j2se version="1.3"/>
          <jar href="OckCore.jar"/>
          <jar href="OckMaths.jar"/>
     </resources>
     <application-desc main-class="com.Ock.OckCore.OckApp">
</jnlp> I have also signed the jars outside of a webdirectory. I get the following manifest file:
Manifest-Version: 1.0
Main-Class: com.Ock.OckCore.OckApp
Created-By: 1.4.0-beta3 (Sun Microsystems Inc.)
Class-Path: . OckMaths.jar
Name: com/Ock/OckCore/OckApp.class
SHA1-Digest: KRZmOryizx9o2L61nN+DbUYCgwo=
note that :-
The jars do exist at the location specified by the manifest.
The application launches normally if I use "java -Jar OckCore.jar".
The application doesn't launch from webstart.
I've found that cache, but the jar files have been renamed.
OckCore.jar is anOckCore.jar, etc... so I'm not sure if trying to write a cmdline will work anyway.

Similar Messages

  • Is it possible to load classes from a jar file

    Using ClassLoader is it possible to load the classes from a jar file?

    URL[] u = new URL[1] ;
    u[0] = new URL( "file://" + jarLocation + jarFileName + "/" );
    URLClassLoader jLoader = new URLClassLoader( u );
    Object clsName = jLoader.loadClass( clsList.elementAt(i).toString() ).newInstance();
    I get this error message.
    java.lang.ClassNotFoundException: ExceptionTestCase
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    // "file://" + fileLocation + fileName + "/" This works fine from a browser.
    Is there anything I am missing? Thanks for the reply.

  • ANT: Include classes from another jar

    Hi all.
    Can I add classes from another jar to be added into my jar-file?
    Other words, may I write something like this:
    <target name="jar" depends="compile">
    <jar destfile="deploy/my.jar"
    basedir="${compile.dir}"
    includes="another.jar" >
    </jar>
    </target>
    in my build.xml?
    Thanx a lot for Your tips.
    Regards, Volodymyr Shram.

    I've found some resolve:
    <target name="jar" depends="compile">
    <unjar src="another.jar" dest="another_dir"/>
    <jar jarfile="deploy/my.jar">
    <fileset dir="${compile.outdir}" includes="**" />
    <fileset dir="another_dir" includes="**" />
    </jar>
    </target>
    But is it only way? Can I add classes from another.jar to my.jar without extracting?
    Regards, Volodymyr Shram.

  • Executing .jar files from another .jar file.

    How would I run one .jar file from another .jar file. and is there anyway to call specific class arguments? Because I have one .jar file that reads a specified file and returns its contents.
    So how would I execute it and specify its arguments and how would I make it return something to the executing jar file?

    Because I have one .jar file that reads
    a specified file and returns its contents. Presumably you have a class that does that, and you have that class stored in a jar. And you want to know how to... um... do something with that class. I say "um..." because normally you don't execute a class, either, you either call its static methods or you create an instance of the class and call its instance methods.
    If you have been writing a whole lot of little classes each of which just has a static main method, then stop doing that. Write real Java classes instead. The tutorial is here:
    http://java.sun.com/docs/books/tutorial/java/index.html

  • Issues with Loading Images from a Jar File

    This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
    //app is the Japplet
    MediaTracker tracker = new MediaTracker(app);
    //jf represents the jar file obj, enum for looping through jar entries
    Enumeration e = jf.entries();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    //buffer for reading image stream
    byte buffer [];
    while(e.hasMoreElements())
    fileName = e.nextElement().toString();
    InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
    buffer = new byte[inputstream.available()];
    inputstream.read(buffer);
    currentIm = toolkit.createImage(buffer);
    tracker.addImage(currentIm, 0);
    tracker.waitForAll();
    images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
    } //while
    }//try
    catch(Exception e)
    e.printStackTrace();
    }

    compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
    InputStream is = jar.getInputStream(entry);
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    try{
    byte[] buf = new byte[1024];
    int read;
    while((read = is.read(buf)) > 0) {
    os.write(buf, 0, read);
    catch(Exception e){
         e.printStackTrace();
         return null;
    image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
    This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
    InputStream is = MyApplet.class.getResourceAsStream(strImageName);
    In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar.

  • How to combine the classes from 2 jar files into 1?

    Hi there
    I have got 2 jar files with the same name but the classes that they contain are different. So, I want to combine those 2 files into 1. Could anyone please tell me how to add the classes in a jar file to another jar file?
    Thanks for your help!
    From
    Edmund

    The jar utility allows you to extract files as well as put them into a jar. This is in the java docs.
    You might have to hand modify the manifest file if it was hand modified in the first place. All you should have to do is copy the text from one file to another. The manifest will have the same name so you will have to extract to different dirs so it isn't overwritten.
    Steps:
    -Create dir1 and dir2
    -Extract jar1 into dir1, Extract jar2 into dir2.
    -Manually examine manifests and combine if needed.
    -Copy files from one dir to another.
    -Use jar tool to create new jar.

  • Using classes from another jar?

    Hello,
    Could anybody show me an example for how to put a shared library of classes in one jar file, and put an applet in another jar while the applet can use classes in the first jar file? Is this even possible at all???
    Thanks!

    norsez, did you had a look at the Java Tutorial:
    Using the APPLET Tag
    http://java.sun.com/docs/books/tutorial/applet/appletsonly/html.html
    It says: 'You specify JAR files using the ARCHIVE attribute of the <APPLET> tag. You can specify multiple archive files by separating them with commas [...]'. I assume all listed JAR files are in the classpath then and you should have access to their classes.
    Let us know if it works!
    HTH, Markus

  • Loading images from a jar file

    Hi,
    My application displays images, until it's placed in a JAR file, then it can't display them even though the JAR file contains the images.
    I saw this problem in a previous question which was solved using
    URL url = MyClass.class.getResource("abc.gif");
    Image img=Toolkit.getDefaultToolkit().getImage(url);
    ....which btw didn't work for me either......
    This method should be made obsolete using ImageIcon, which I am using, but the images still won't appear...
    Any suggestions?

    It works fine that way (...getClass().getResource....) until I create the jar file, and then I get a null pointer exception when it tries to load the image.
    When I use
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(("/images/imageName.jpg"));
    the application works but without the images.......

  • Jar file referring to classes in another jar file

    I want to deploy my application as a WAR file. Let's say deploying it as an EAR is not an option. I have utility1.jar in WEB-INF/lib that needs classes in other utility2.jar (which is also in WEB-INF/lib) at runtime. Do I need to classpath entry in utility1.jar manifest pointing to utility2.jar? Your help is appreciated.

    When a *".war"* is loaded by the server as that application_name* , it unloads the .jar files into "classes" directory with accordence the structure of the folders/package-hierarchy implicitly.

  • How To Load Sound From Inside jar File?

    Hello There
    i've made a jar file that contains Images&Pictures But I Can't Use Them
    So I Used For Loading Images
      URL url = this.getClass().getResource("image.jpg");
             setIconImage(new ImageIcon(url).getImage());and for loading sound when i use
      URL url = this.getClass().getResource("Bond2.wav");         
           AudioInputStream stream = AudioSystem.getAudioInputStream(new File(url));there's an error That The file Constructor doesn't take url
    how can i fix it?

    First_knight wrote:
    and for loading sound when i use
      URL url = this.getClass().getResource("Bond2.wav");         
    AudioInputStream stream = AudioSystem.getAudioInputStream(new File(url));there's an error That The file Constructor doesn't take url
    how can i fix it?Remove the "new File()". There is a getAudioInputStream() method that takes a URL.
    AudioInputStream in = AudioSystem.getAudioInputStream(url);

  • Is it possible to call a class in a jar file from JNI environment?

    Hi
    Is it possible to call a class in a jar file from JNI environment?
    Thanks in advance.

    Could you explain a bit more what you are trying to do? (In other words, your question is vague.)
    o If your main program is written in C, you can use JNI to start a JVM, load classes from the jar of your choice, and call constructors and methods of the objects defined in the jar.
    o If your main program is java, and has been laoded from a jar, a JNI routine can call back into java to use the constructors and methods of classes defined in the jar(s).

  • Accessing classes in external jar files

    I have a jar file called main. I want it to be able to acces the classes in another jar file say test.jar how do i do this.
    Thank you

    ok, if i have this right...
    you have 2 directories that hold 2 .jars, right?
    plugins/ -------- build/plugins .jar
    systemModuals/ ------- DiaryUI and Loader .jar
    Your main JAR is diary?
    Diary.jar
    you want Diary to run with the jars inside plugins and systemmoduals?
    you set the "class-path:" tag like this....
    write this manifest file. save it as Manifest.txt and put it in your home dir.
    Main-Class: YourMainClass
    Class-Path: Diary.jar plugins/this.jar systemmoduals/diaryui.jar
    <make sure to hit enter, go to the next line>
    command line to your parent directory.
    jar cmf Manifest.txt Diary.jar build/main/*.class
    you should be set to go.
    use
    jar xf META-INF/MANIFEST.MF
    to read the present manifest that netbeans has created
    if necessary

  • How to load all the classes in a JAR file at runtime?

    Any clues o:
    "How can I force JVM to load all the classes in a specified JAR at once?"
    Thanx!
    -Rajeev

    Well I was thinking may be there exists an option with "java", when I
    am starting an application from a jar file, I could force it to load all
    the classes in the JAR. I don't want to do it programically. Is there such
    an option available?? Or in other words can I ask JVM to not do the dynamic
    loading for the JAR??
    Thanx.
    List all JarEntries and convert the paths to fully
    qualified class files
    e.g file in jar
    [1] /com/mycompany/proj/X.class
    should become
    [2] com.mycompany.proj.X
    then for each entry issue
    Class.forName( [2] );

  • Can't load any classes from infobus.jar (WL 6.0 SP1)

    Hi,
    I am deploying an .ear file, which has one .war file in it. The war file, has
    infobus.jar, inside it under \WEB-INF\lib. Whenever in my servlet code I try to
    load a class from infobus.jar, I get the following exception :
    About to load class javax.infobus.InfoBusDataConsumer<<<<<<<<<<java.lang.ClassNotFoundException: InfoBusDataConsumer
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:178)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:45)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:120)
    at XDILoginForm.init(XDILoginForm.java:99)
    at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:638)
    at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:581)
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:526)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1078)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:1022)
    at weblogic.servlet.internal.HttpServer.loadWARContext(HttpServer.java:499)
    at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:421)
    at weblogic.j2ee.WebAppComponent.deploy(WebAppComponent.java:74)
    at weblogic.j2ee.Application.deploy(Application.java:175)
    at weblogic.j2ee.J2EEService.deployApplication(J2EEService.java:173)
    at weblogic.management.mbeans.custom.Application.setLocalDeployed(Application.java:217)
    at weblogic.management.mbeans.custom.Application.setDeployed(Application.java:187)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.management.internal.DynamicMBeanImpl.invokeSetter(DynamicMBeanImpl.java:1136)
    at weblogic.management.internal.DynamicMBeanImpl.setAttribute(DynamicMBeanImpl.java:773)
    at weblogic.management.internal.DynamicMBeanImpl.setAttribute(DynamicMBeanImpl.java:750)
    at weblogic.management.internal.ConfigurationMBeanImpl.setAttribute(ConfigurationMBeanImpl.java:256)
    at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1356)
    at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1331)
    at weblogic.management.internal.ConfigurationMBeanImpl.updateConfigMBeans(ConfigurationMBeanImpl.java:318)
    at weblogic.management.internal.ConfigurationMBeanImpl.setAttribute(ConfigurationMBeanImpl.java:259)
    at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1356)
    at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1331)
    at weblogic.management.internal.MBeanProxy.setAttribute(MBeanProxy.java:291)
    at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:173)
    at $Proxy7.setDeployed(Unknown Source)
    at weblogic.management.console.pages._panels._mbean._application._jspService(_application.java:303)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:213)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:1265)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1622)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    But if I put the infobus.jar on system classpath , everything works out fine.
    Can somebody tell me, what is going on

    Gseel is right: you try to instantiate an EJB with the BDK.
    Enterprise Java Beans are totally different from graphical/GUI beans. EJBs are thought for dealing with business logic like accessing a database, ldap directory and so on. They run on a application server (simply speaking - a java enabled webserver) and do some processing to handle user requests. Enterprise Java Beans usually don't interact directly with the user, they only do the work in the background and forward their results, which are then rendered for the user. Typically they are employed for handling web requests (a user with a browser), but they can also be used for awt/swing applications. Though - let me repeat - they don't appear visually on the screen.
    The only similarities between those two bean types are the following: they have getter/setter methods for their properties, they implement Serializeable (or a sub-interface like Externalizable, Remote) and they have a default no-argument constructor.
    If you want to run your been you need an application server (your bean is pre-packaged for the Bea Weblogic app-server). If you want to do something graphical, you'll need to search for GUI beans.
    dani3l

  • How to call inner class method in one java file from another java file?

    hello guyz, i m tryin to access an inner class method defined in one class from another class... i m posting the code too wit error. plz help me out.
    // test1.java
    public class test1
         public test1()
              test t = new test();
         public class test
              test()
              public int geti()
                   int i=10;
                   return i;
    // test2.java
    class test2
         public static void main(String[] args)
              test1 t1 = new test1();
              System.out.println(t1.t.i);
    i m getting error as
    test2.java:7: cannot resolve symbol
    symbol : variable t
    location: class test1
              System.out.println(t1.t.geti());
    ^

    There are various ways to define and use nested classes. Here is a common pattern. The inner class is private but implements an interface visible to the client. The enclosing class provides a factory method to create instances of the inner class.
    interface I {
        void method();
    class Outer {
        private String name;
        public Outer(String name) {
            this.name = name;
        public I createInner() {
            return new Inner();
        private class Inner implements I {
            public void method() {
                System.out.format("Enclosing object's name is %s%n", name);
    public class Demo {
        public static void main(String[] args) {
            Outer outer = new Outer("Otto");
            I junior = outer.createInner();
            junior.method();
    }

Maybe you are looking for

  • SSO and Form 10g, Setting RAD of OID for DB users identified externally

    Please Help! Current environment: - All users were created with identified externally in Database (OPS$) - SSO was setup correctly according to OID admin guide Ch 43 and SSO admin guide ch 8 for App10g. (user login orasso without seeing basic auth/ss

  • New to Accessibility and have run into problems I can't seem to find answers to.

    At my job I've been trying to learn how to make files accessible for a client. I've watched many videos and scoured forums but there are some issues and can't seem to resolve and was wondering if anyone would be able to assist. 1.Table tagging- all t

  • Bookmarks and MS Word

    I want to maintain a working document in Word and convert it to PDF anytime there is a change. How do I set it up so that I don't have to set up the bookmarks each time once it's in PDF?

  • XSLT: how to increment a counter

    How do I increment a counter defined in XSLT? i.e <xsl:variable name="counter"/> //global var? <xsl:for-each select="...."> <!--How do I assign $counter+1 to the variable counter defined above??? --> <xsl:assign???? name="counter"> <xsl:value-of sele

  • Missed call Notification

    When I receive a missed call, a notification is displayed in the lock screen (normal) When I try to use the notification (sliding the notification itself) to call the person back, it calls back normally. But then the notification doesn't go away.  I