Results 1 to 3 of 3
  1. #1
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Jar within a Jar

    I have been working with some Jar file inception and I cannot find the answer to my problem. I think I am close, but I am missing a step. Right now, I want to place all of my library files (external jars) inside of my main jar for my program to use. Making one big happy jar to contain others and some compiled code. My plan of attack is to use a ClassLoader. My class loader looks like this:

    Java Code:
    import java.io.*;
    import java.net.*;
    
    public class NewLoader {
     
        static public void main(String... args) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
            File file1 = new File("easyogg.jar");
            File file2 = new File("jogg-0.0.7.jar");
            File file3 = new File("jorbis-0.0.15.jar");
            URL url1 = file1.toURI().toURL();
            URL url2 = file2.toURI().toURL();
            URL url3 = file3.toURI().toURL();
            URL[] urls = { url1, url2, url3 };
            ClassLoader loader = new URLClassLoader(urls);
            Class OggC = loader.loadClass("org.newdawn.easyogg.OggClip");
        }
    }
    Now, my problem is, I am trying to create a new instance of the Class OggClip and turn it into an Object so I can use it's methods. Like:
    Java Code:
    OggClip ogg = new OggClip();
    As if it were a class file in my directory.
    But I cannot figure out how to get to this point. I have loaded the class using loader.loadClass(); but this is where I cannot go any further.

    If anyone could help, I would appreciate it. Also, if there is a simpler way of doing this, please tell me.

    Cross posted on: http://www.coderanch.com/t/593297/St...in-Jar#2703385
    Last edited by kammce; 09-23-2012 at 05:27 PM. Reason: adding cross post
    My API:
    Java Code:
    cat > a.out || cat > main.class

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Jar within a Jar

    As far as I understand, standard Java does not support nesting of jar files, but having said that, I believe that there are 3rd party libraries available that do. If this were my problem, I'd Google -- Java nested jar files -- and inspected the search results.

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Jar within a Jar

    Thank you Fubarable. After some searches and some advice from my cross post, I have gotten more incite on my issue. I am having great difficutlty implementing the code that I am finding. And example:Cerebrum Abandon: An embedded jar classloader in under 100 lines. I am a little inexperienced in this, and I am working blindly. But I will continue to look for a solution.
    My API:
    Java Code:
    cat > a.out || cat > main.class

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •