Loading library from jar file

Hi all,
My question is can we load library from jar file using System.load() method.
ex:
myJar.jar
|
|----com.test.common.Util
which conatins a method to load library from jar file itself, before that i used to load from File
|---libraries/MozillaParser/......
Iam able load from Local system,
File parserLibraryFile = new File("libraries/MozillaParser" + EnviromentController.getSharedLibraryExtension());
File mozillaDistBinDirectory = new File("libraries/mozilla.dist.bin."+EnviromentController.getOperatingSystemName());
MozillaParser.init(parserLibraryFile.getAbsolutePath() , mozillaDistBinDirectory.getAbsolutePath());
but i am unable to load from jar file
URL url = ClassLoader.getSystemClassLoader().getResource("libraries/MozillaParser" + EnviromentController.getSharedLibraryExtension());
URL url1 = ClassLoader.getSystemClassLoader().getResource("libraries/mozilla.dist.bin."+EnviromentController.getOperatingSystemName());
MozillaParser.init(url.toString(), url1.toString());
Thanks in advance.

That's a really confusing post.
The easiest way to make sure you can use the classes in a jar file is to copy the jar file to the "/jre/lib/ext" subfolder of your JDK. These classes will be visible to all applications.

Similar Messages

  • Load library from JAR file

    Could I ask you guys a stupid question, please?
    I have a library as an JAR file. I build my application as another JAR file, which includes that library file.
    My manifest file is:
    Manifest-Version: 0.1.0
    Class-Path: lib/mysql-connector-java-3.0.17-ga-bin.jar
    Main-Class: com.myappand the build command:
    jar cvfm hello.jar mymanifest -c com  -c libThe result hello.jar file built OK. But when I run it, I have to copy library file to the same folder to the app file.
    Could you tell me how to load the lib file from hello.jar, instead of the lib file?
    Thanks in advance!
    Best regards,
    Lehoanq

    am I right in thinking you've put the mysql jar inside your application jar? jars don't work like that, I'm afraid. it is possible to write a classloader that will load classes from within a jar-inside-a-jar, but it gets rather complicated and messy and isn't worth the hassle to be honest, anyway. we go to some lengths to keep our software modular and separate. imagine, for instance, that a bug is exposed in the mysql driver you're using, and a new release is needed to fix it. the dependency is rooted inside your application, so the whole shebang has to be re-packaged and re-deployed, whereas if your dependencies were inside a lib folder, all that would be needed is to drop the new version of the mysql driver into the lib directory. think "don't put all your eggs in one basket"
    what you want to do is possible, and there are tools around to do it for you, too, but IMHO it's not worth the effort

  • Problem loading image from jar file referenced by jar file

    First, I searched this one and no, I didn't find an answer. Loading images from jar files has been pretty much done to death but my problem is different. Please read on.
    I have my application, a straight up executable running from Eclipse. It uses a jar file, call it JarA. JarA launches a GUI that is located in another jar file. Call it JarB. To recap:
    My application calls JarA -> JarA loads classes from JarB -> JarB looks for images to place in a GUI it wants to show on the screen
    When JarB goes to load an image the following happens:
    java.lang.NullPointerException
         at sun.misc.URLClassPath$3.run(URLClassPath.java:316)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:313)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:290)
         at sun.misc.URLClassPath.findResource(URLClassPath.java:141)
         at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
         at java.lang.ClassLoader.getResource(ClassLoader.java:977)
         at org.cubrc.gmshell.gui.MainWin.preInit(MainWin.java:152)
         at org.cubrc.gmshell.gui.MainWin.<init>(MainWin.java:135)
    The code from JarB that loads the image looks like this:
              URL[] oSearch = {Main.class.getResource("images/")};
              URLClassLoader oLoader = new URLClassLoader(oSearch);
              imgIcon = new ImageIcon(oLoader.getResource("icon.gif"));
              imgMatchRunning = new ImageIcon(oLoader.getResource("gears.gif"));
              imgMatchStill = new ImageIcon(oLoader.getResource("gears-still.gif"));
              imgMagnify = new ImageIcon(oLoader.getResource("magnify.gif"));This looks right to me and JarB certainly has an images directory with those files. But I'm in hell right now because I don't know where to place the images to make this work or if you can even attempt to load images with a dependency chain like this.
    Any help very appreciated!

    Have you tried to move your image-files out of the jar file and place them in the sam folder as the jar-file? I think that would help.
    When you try to load the image-file you get the NullPointerException because the program tries to read a file it can't find. Remember that a jar file IS a file and not a directory.
    If you want to read somthing inside the jar-file you need to encode it first.
    Have you tried to read the jar-file with winRar. It makes it easy to add and remove files in your jar-file.

  • Problem loading Applets from Jar files on 64 bit machine

    I am developing an applet (extends Applet but uses swing components) using JDK 1.6 (Though these problems still happen in JDK 1.7) and I am unable to get the applet to load on a 64 bit machine in most cases. The web server(s) are running on localhost and I am connecting on the same machine using a local network ip address (such as 192.168.*.*)
    Below are all of my test results. Can someone provide a suggestion for repairing this? The Windows Server machine is a clients computer I access to it via remote desktop but I can't do much with it though I do have administrator rights. The Windows 7 machine is my development platform so I have been able to do extensive testing on it.
    This problem is presenting in the following environments when trying to load an applet from JAR files in a HTML document using the Applet or Object tag.
    Windows Server 2008 (Intel Chipset)
    Tested Browsers:
    Internet Explorer 9 (32 bit) - Shows it is blocked by default then simply shows an x when loaded from a web page, same result when loading from local drive.
    Windows 7 Home Premium (AMD Chipset)
    Tested Browsers:
    Firefox 6.0.1 (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    Internet Explorer 9 (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    Internet Explorer 9 (64 bit) - Java logo shows with spinner and most of the windows desktop manager freezes, keyboard is the only thing that responds so you can alt-tab to another app to regain control of the desktop.
    Chrome (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    The only way I have been able to get a Java applet to run on a 64 bit machine are the following ways.
    Firefox 9 nightly (64 bit) works perfectly! Go Firefox!
    Internet Explorer 9 (32 bit) loading directly from drive (c:\...)
    Chrome (32 bit) loading directly from drive (c:\...)
    Firefox 6.0.1 (32 bit) loading directly from drive (c:\....)
    Can someone please help! I've been fighting with this bug for over a week and I can't find anything that will solve it, I have noticed that in some cases if my jar has very little code in it than it will run on the server, but the minute I start adding things to it the jar won't load anymore.

    jschell wrote:
    rritoch wrote:
    I am developing an applet (extends Applet but uses swing components) using JDK 1.6 (Though these problems still happen in JDK 1.7) and I am unable to get the applet to load on a 64 bit machine in most cases.
    To clarify...
    1. You have tried it on 32 bit machine? Exactly which OS?I tested this on Windows Vista Business which is in 32 bit mode and the applets run without any problems
    >
    2. Your only 64 bit tests have involved 2008/Win7?
    If so then I would suspect something with windows not java. Probably permissions.
    The web server(s) are running on localhost and I am connecting on the same machine using a local network ip address (such as 192.168.*.*)
    Yes, I haven't tried running the jars on other operating systems.
    >
    I don't understand that. If you are running on localhost then you should connect to localhost. If running on an IP then you should connect to that. Perhaps you meant that you have tested using both of those?I'm testing using the lan ip address but I'm connecting from the same machine. I've tried localhost and that didn't work so I tried lan ip since that will likely have a different java security context than localhost. At first I was blaming the IIS server but I downloaded the jar directly and using HTTP fox was able to verify that the jar is being sent with the correct mime-type and that the server can upload the jar file without a problem. This leaves me to believe the problem is with Java.

  • 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.

  • Loading icons from jar file

    Hello,
    i am trying to load ALL imagefiles from my jar file. i do the following:
    Class clazz = Class.forName("com.xxx.IconSelectionDialog");
    String me = clazz.getName().replace(".", "/") + ".class";
    dirURL = clazz.getClassLoader().getResource(me);
    if (dirURL.getProtocol().equals("jar")) {
    String jarPath = dirURL.getPath().substring(6, dirURL.getPath().indexOf("!")); //strip out only the JAR file
    JarFile jar = new JarFile(jarPath );
    Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
    while (entries.hasMoreElements()) {
    JarEntry nextEntry = entries.nextElement();
    String jarEntryName = nextEntry.getName();
    this works fine with my debug local jws installation. when i try to run it online starting i get an error:
    java.io.FileNotFoundException: xentis.jar (Das System kann die angegebene Datei nicht finden)
         at java.util.zip.ZipFile.open(Native Method)
         at java.util.zip.ZipFile.<init>(ZipFile.java:114)
         at java.util.jar.JarFile.<init>(JarFile.java:133)
         at java.util.jar.JarFile.<init>(JarFile.java:70)
    how can i load ALL icons from a jar (without knowing the filename) ?
    is there a generic way to iterate over all entries of a jarfile ?
    thank you
    michael

    Look at "Loading Images Using getResource" on this page
    http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
    It should provide some ideas.

  • Problem While Loading mp3 From Jar File?

    Hello There
    I've Made a jar File That Contains mp3 file That Should be Played When the jar is opened
    but the file doesn't play?
    and my code snippet to load from the jar
    URL url=getClass().getResource("/file.mp3");
    MediaLocator ml=new MediaLocator(url);
    final Player player = Manager.createRealizedPlayer(url);
    I don't Know where's The Error
    Could any one Help?

    First_knight wrote:
    Hello
    -Yes I Use NetBeans 6.1 To create The Jar With The Following Steps:
    First I've Add The Sound File To a Package In NetBeans 6.1
    And Then Called The Sound From The Package And The Program Runs Okay Then I Made The jar
    and after making the jar now i have to call the sound file from the jar by the code mentioned above
    i used it and run the program it run okay but when i try to open the jar i hear no sound????????????
    I Don't know whyyyyyyyyy This seems to indicate that your app is finding the mp3 file. You would probably get a null pointer exception if the file wasn't found. Something else seems to be going on.
    -How are you launching the jar outside of NetBeans?...By Double Click On It
    I suggest trying to launch the jar using the command promptjava   -cp   YourJarFile.jar  YourMainClassAnd if that works, try java   -jar   YourJarFile.jarAnd if that works, your computer's file association is not set up correctly.

  • PJC - Loading Images from JAR Files

    I'm developing a PJC class that involves loading images. I would like to be able to find and use an image contained in a JAR file just like the built-in Forms items do; not the JAR file where my class is contained but any external ones defined in the server archive settings.
    I have seen the loadImage method in the demo RolloverButton class but this only loads images from the class's JAR and not any others.
    Is there a VButton method or an Oracle loader class for finding image resources from the defined JAR archives? If not, could someone supply some code for achieving this.
    Thank you.

    Hi,
    the jar file name the images are in shouldn't matter for the code as long as the package name is preserved. If you want to see it with your own eyes, do the following
    1. Back up demo90.jar
    2. Create a copy of it and call it demo90img.jar
    3. Open demo90.jar in winzip and remove all images
    4. Open demo90img.jar and remove all Java classes
    5. add ,/forms90demo/jars/demo90img.jar to the archive_jini tag of a demo you want to test this on
    6. Run the application and see the images despite the fact they are now in a separate jar file. Note in the Jinitiator console that the new jar files are downloaded and replace the existing, cached, jars
    7. Run an application that doesn't have demo90img.jar configured to see that the images are missing.
    Frank

  • How to load class from jar file dynamically?

    After I run my Java applicatoin, I need configuring the classpath of jvm to load some classess inside a jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know where the jar file is, what the jar file name is. All depends on the user to tell the jvm the details through some UI. I've tried to write: System.setProperty("java.class.path", "c:\myClass.jar");Class.forName("MyClass"); but failed.
    Can you tell my why and how?
    Thx

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • Problem loading URL from .jar file

    I encounter problems while loading a MsAccess DB contains within a .jar file. This is the following codes I used,
    try
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        java.net.URL url=getClass().getResource("MSAccessDB\\SavingApp DB.mdb");
        DBURL+=url.getFile();
    catch(Exception e)
    { System.err.println(e.toString()); }

    Could I ask that, if I stored the MsAccess or any other DBs, will the DB able to do basic operations (Create Update Retrieve Display)?
    As the DB is not like a normal Text file.
    What I did is that, I didn't include the MsAccess into the .jar file. I just put it beside. The disadvantage is that user ables to open the DB and might do some changes. ;-(

  • Loading images from jar file

    i use the instruction below to load image contained in my jar file for distribution application but the image doesn't appear
    icon = new ImageIcon("images/logo_tunisiana.GIF");
    the jar file contain the image under a subdirectory called images.
    Witch code sample have i to use ?
    thanks in advance

    I have an applet that is packaged in a jar file with images. I can access the images using:
    aIcon = new ImageIcon(KeyboardApplet.class.getResource("images/keyimages/a.jpg"));

  • Unable to load classes from jar files inside APP-INF/lib in EAR.

    Weblogic version: 10.3.3
    Platform: Linux x86-64 bit
    We deployed an ear packaged with all the common library jars inside APP-INF/lib. Deployment was successful.
    for some reason, it is always giving ClassNotFoundException for the classes inside the jars. This does not happen
    in 10.3.2 version of weblogic.
    We tried to add them to domain/lib directory (instead of APP-INF/lib) but still it is not able to resolve the classes.
    Any pointers would be appreciated.

    try using prefer-web-inf-classes in the weblogic.xml file in your WAR file
    or using prefer-application-packages in the weblogic-application.xml file in your EAR.

  • How to load an applet jar file?

    Hello everyone,
    I have an applet that uses my own jar file and approximately 6 third party jar files. I set up jar indexing (jar -i) which will download the jar files when they are needed. All seems to work well, but now I want to manually load the jar files which I cannot get working.
    When the applet starts, about 1/2 of the jar files are downloaded (because they are needed at startup). I then want to load the additional jar files in the background, after the gui is initialized. I have tried this using the below thread which is executed from within the applet's start method:
    // Try to load additional jar files in background by loading a class from each jar file.
    Thread loadClass = new Thread() {
      public void run() {
        System.out.println("Loading classes...");
        try {
          // Tried loading classes this way, doesn't work.
          getClass().getClassLoader().loadClass("pkg1.Class1");
          getClass().getClassLoader().loadClass("pkg2.Class2");
          getClass().getClassLoader().loadClass("pkg3.Class4");
          getClass().getClassLoader().loadClass("pkg4.Class4");
          /* Loading classes this way doesn't work either.
          Class.forName("pkg1.Class1");
          Class.forName("pkg2.Class2");
          Class.forName("pkg3.Class3");
          Class.forName("pkg4.Class4");
        catch(ClassNotFoundException e) {
          // First attempt to load a class (pkg1.Class1) throws exception.
          System.out.println("Can't find class: " + e.getMessage());
    loadClass.start();As you can see from above I am trying to load a class from each of the jar files so that the jar files would load into memory/cache. Unfortunately, it cannot find the classes. These are the errors from the java console:
    Loading classes...
    Loading: pkg1.Class1
    Connecting http://my.server.com/my_dir/pkg1/Class1.class with no proxy
    Connecting http://my.server.com/my_dir/pkg1/Class1.class with cookie "JSESSIONID=some_big_long_char_list"
    Can't find class: pkg1.Class1
    So it appears the jar file is not being downloaded. When I take away the dynamic jar loading (removing the "jar -i" & adding them all to the applet archive list) the thread executes correctly. So I know the class names, etc, are correct. How does one load an applet jar file?
    Any help/suggestions are appreciated.

    The above error I posted was because I forgot to index the jar files. That is why it couldn't find the jar file. I thought I was getting farther along with my problem, but I apparently just forgot to index the jars. I am now getting the problem that I got yesterday...
    The applet freezes/hangs when it hits the thread. The GUI never opens (even though I'm running this thread right after the gui shows). The java console quits responding and the applet just stays the grey screen. I also tried the invoke later that you suggested.
    public void start() {
      // ...initialize gui...
      // Applet freezes and remains grey, also the java console freezes.
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          System.out.println("Loading classes...");
          try {
            // When I comment out the below forName calls, the thread will still run evidenced through the done print statement.
            Class.forName("pkg1.Class1");
         Class.forName("pkg2.Class2");
         Class.forName("pkg3.Class3");
         Class.forName("pkg4.Class4");
            System.out.println("...Done loading classes");
          catch(Exception e)     {
            System.out.println("Can't find class: " + e.getMessage());
    }

  • Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:

    Hallo everybody :-)<br /><br />i've installed Workflow-Server + ARES + FormManager. When i call localhost:8080/adminui i can log in and the browser loads the next site --> it fails and says:<br /><br />org.apache.jasper.JasperException: Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:/C:/Adobe/LiveCycle/jboss/server/all/tmp/deploy/tmp56414LiveCycle.ear-contents/admi nui.war/WEB-INF/lib/jsf-impl.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: com.sun.faces.taglib.FacesTagExtraInfo<br />     org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:5 0)<br />     org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)<br />     org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:183)<br />     org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181)< br />     org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)<br />     org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)<br />     org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)<br />     org.apache.jasper.compiler.Parser.parse(Parser.java:126)<br />     org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)<br />     org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)<br />     org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)<br />     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)<br />     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)<br />     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)<br />     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)<br />     javax.servlet.http.HttpServlet.service(HttpServlet.java:810)<br />     com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)<b r />     com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)<br />     com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)<b r />     com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)<br />     com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)<br />     javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)<br />     com.adobe.framework.SecurityFilter.doFilter(SecurityFilter.java:177)<br />     com.adobe.idp.um.auth.filter.PortalSSOFilter.doFilter(PortalSSOFilter.java:106)<br />     com.adobe.framework.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter .java:161)<br /><br />Any idea what' wrong?<br /><br />Thanks,<br />Valerio

    Hi Howard,
    thank you for your post.
    I actually new about the problems with the jvm version. Still i wanted to ask, cause there are different reports on this `java problems` and even though the 1.4.2_08 seems to be the best version (by the way this version is not to be downloaded any longer *sig*), there are people getting all installed with other versions. I couldn't find any regularity in the misbehavior of the servers while installing.
    I finally achieved and got everything working ... but very slow. Loading the adminui or BAM features takes very long time (over one minute). Have you already had this delay. Any hint?
    Thanks again,
    Valerio

  • How do I restore iTunes library from Backup files on External Hard Drive?

    How do I restore iTunes library from Backup files on External Hard Drive and keep the new iTunes library on the External Hard Drive. I have all the media and playlist and .xml .itl files, just want the iTunes to recognise the content.
    I backedup my iTunes content by dragging to External Hard Drive. Formatted and reinstalled OS. My iTunes content is so large, that I wish for the Library and content to remain on the External Hard Drive. I have all the music files and playlists, I just cannot get the iTunes application to display all the content. Hoping to Not have to drag and drop all the content to be recopied into new iTunes organised files.
    Troubleshooting this by researching other conversations on the web, I have come stuck for a solution. One Troubleshoot told me to hold down the Command key and then lauch iTunes and a dialogue box will appear to Choose a new library, however when I try this, no Dialogue box appear to give me the option!?

    It sometimes has that funny switch symbol on it too.  
    tt2

Maybe you are looking for

  • External Drive crashed-how to restore from Time Machine?

    I've been using TM to back up my internal, as well as an external drive. The external has been acting a bit flaky the past week or so, and I think it just bit the dust. How do I go about just restoring the data that was on it to a new external HD? I

  • Skype won't sign in.

    When ever I try to sign in with my account with skype, it sticks at the moving circle, then it says Skype can't connect. I've tried >Re-Installing. >Resetting Internet Explorer & Updating. >Installing a old version of Skype. >Disabling fire-wall. >Re

  • Weird battery issue

    Hello here, I have an iBook 12" G4 @1.2GHz which is around 2.5 years old. Now, it's about 2 weeks that the battery doesn't charge more than 44%, I tried to discharge it completely then recharge it but to luck, it keeps stopping charging at 44%. Any i

  • Appleworks Formula error on import to Numbers

    I have devised a spreadsheet for my VAT and TAX in Appleworks (6.2.9 It has worked fine for years. I recently decided that I should try and get it working in Numbers (09) to future proof it. I am having a problem with one of the formulae: =IF(X4Y4+AA

  • Cheque Script Main window question

    Hi, in Main window of F110_PRENUM_CHCK there are numbers in bold like 510-1 512 etc. Can you explain me what do they mean? Thank you, Vitaly