Access jar file from in-memory classes...

I have some classes that I compile to memory and everything works fine until one class that must access some external jar files. I have been unable to access those jar files from disk after trying every suggestion using URLClassLoader. I even tried someone's example to hack the SystemClassLoader which properly adds the jar file paths, but still they can't be seen. The only way it works is if I put the files in the jdk/jre/lib/ext directory. Then everything works fine. There must be a way to load the jar files in memory as well as the class files so they can be accessible. Has anyone done anything like this? Is it possible? Even though the class files are in memory, why would the jar files not be seen even when they are added to the same URLClassLoader's URL's. Thanks.

Sorry that wasn't clear. What I mean is that the classes are compiled to byte code directly to memory and no physical .class file is created. Yes, I'm using my own ClassLoader that extends URLClassLoader and I'm setting the parent to ClassLoader.getSystemClassLoader(). I also should mention that I'm doing this inside a Netbeans module that is part of a Netbeans Platform application. I don't know why that should matter though, since I'm trying to do everything in memory without creating the physical files. Thanks.

Similar Messages

  • How to call a jar file from oracle forms (6i)

    Hi,
    I'm working with oracle 6i. I want to know that how to call a .jar file from forms menu. when I use HOST('<path>\test.jar') it is working in 'Client Server' any way. but the problem is I use application server in order to run my form. so my form is in the server and I run the form via clients web browser. in that case above solution will not work. if any body knows how to overcome this problem please reply.
    thanks.
    duminda

    I created a bean area and set the class name as implementation class. within that java bean class I called to a bat file which consists of the execution command of the jar file ( because i don't know how to call .jar file from my bean class directly).
    then i tried to run it in application server. its still not running.
    can you tell me what i have to do within my bean class? or can you suggest any solution?
    thank you.

  • How to access additional supporting jar files from EJB JAR?

    Hi,
    How can we access additional supporting jar files as part of my EJB JAR .
    I don't want to keep them in the top level because other EJB JAR files also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

    Include the supporting jar files in the Ejb jar file.
    Specifiy the jar files in the Ejb jar manifest file.
    Manifest-Version: 1.0 [CRLF]
    Class-Path: utility.jar [CRLF]
    thanks,
    Deepak
    "NLB" <[email protected]> wrote:
    >
    Hi,
    How can we access additional supporting jar files as part of my EJB JAR
    I don't want to keep them in the top level because other EJB JAR files
    also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

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

  • Unable to access jar file error !

    hello,
    i have built my netbeans project and obtained the hequalifies.jar file . unfortunately when i'm trying to run this jar file from the prompt command I'mgetting the error: unable to access jar file
    here is the command i'm typing:
    C:\Users\User\Documents\NetBeansProjects\hEqUALIFIES\dist>java -jar " C:\Users\U
    ser\Documents\NetBeansProjects\hEqUALIFIES\dist hequalifies.jar "
    anyone has any clue?
    10x!

    ok i'm gonna make it easier on you.
    i gess i found what is the problem but have no idea how to solve it.
    when i obtained the .jar file i also obtained a README.txt file in which it is written the following phrase:
    ** If a library on the projects classpath also has a Class-Path element*
    specified in the manifest,the content of the Class-Path element has to be on the projects runtime path.
    I'M SORRY BUT I DID NOT UNDERSTAND WHAT IS MEANT BY: what is "the projects runtime path"?
    the content of my manifest is:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 10.0-b23 (Sun Microsystems Inc.)
    Main-Class: hequalifies.ui.HeQualifies
    Class-Path: lib/PlugIn
    X-COMMENT: Main-Class will be added automatically by build
    I'm having problem with lib/plugin.

  • Can't run JavaFX app as a jar file from command line

    I'm trying to build a JavaFX app from scratch (that is, by including the jar file from the JavaFX SDK rather than by using the special JavaFX project type from NetBeans). It runs fine in NetBeans. However, when I try to launch it as a jar file from the command line (using "java -jar dist\TestApp") I get the following. Has anybody seen this before, and if so how can I fix it?:
    *** Fallback to Prism SW pipeline
    Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLink
    Error: Can't load library: C:\dev\TestApp\dist\bin\mat.dll
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:
    289)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:68)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
    pl.java:145)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
    27)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:97)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\dev\RedactionT
    oolPrototype\RedactionToolPrototype.Core\dist\bin\mat.dll
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoad
    er.java:155)
    at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoad
    er.java:85)
    at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:
    30)
    at com.sun.glass.ui.Application$1.run(Application.java:28)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:26)
    at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
    at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatform
    Factory.java:20)
    at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatform
    Factory.java:17)
    at com.sun.glass.ui.Application.Run(Application.java:51)
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:
    279)
    ... 5 more

    Unsatisfied link means that Java is trying to access a native library, but it cannot be found. As to why this error is being thrown, here is my guess:
    If you open up one of the sample jars with a zip viewer, you will see that the Manifest file has the following entries:
    >
    Manifest-Version: 1.0
    JavaFX-Version: 2.0
    implementation-vendor: Oracle
    implementation-title: BrickBreaker
    implementation-version: 1.0
    JavaFX-Application-Class: brickbreaker.Main
    Created-By: JavaFX Packager
    Main-Class: com/javafx/main/Main
    >
    In other words, a JavaFX project works a bit differently than a normal Java project. com/javafx/main/Main is used as the Main class and your "Main" class is called later.
    If you are trying to build this from a normal Java project, then com/javafx/main/Main will not be created and it will call your Main class right away. Thus, whatever setup is needed to run JavaFX will not occur.

  • Multiple jar files from different locations

    Hello,
    I am having an applet that access code from two different jar files. Of them one is a common jar file for many applets. So I couldn't place it in the local dir as that of the applet's html. I am not using any web server.
         Just to give you a feel of it :
         <PARAM NAME = archive VALUE = "DVApplet.jar,DVVP.jar" > are the jar files my applet is dependant on. But DVVP.jar has to be accessed from a dir different from local dir.
         Will be glad if someone can throw some light on accessing different jar files from different dirs.
         Thanks for your time.
    Regards,
    Anantha

    [url=
    http://forum.java.sun.com/thread.jsp?forum=421&thread=425724&tstart=0&trange=100
    ]This question is a bit similar
    You can use a class loader to do such things.

  • Running a jar file from java code

    Hi!
    Im trying to run a jar file from my code.
    I've tried Classloader, but that doesnt work because it doesnt find the images (also embedded in the 2nd jar file).
    WHat I would like to do is actually RUN the 2nd jar file from the first jar file. There must be a way to do this right?
    any ideas?

    ok, I found some wonderful code (see below) that will try to start the jar. But it doesn't. What it does is produce the following error when my application runs...
    So it's not finding the images in the jar file that I am trying to run? Strange. I checked the URL that sending, but it seems ok....
    I think I will check the url again to make sure......
    any ideas?
    Uncaught error fetching image:
    java.lang.NullPointerException
         at sun.awt.image.URLImageSource.getConnection(Unknown Source)
         at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
         at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
         at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
         at sun.awt.image.ImageFetcher.run(Unknown Source)
    the code....
    /* From http://java.sun.com/docs/books/tutorial/index.html */
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.net.JarURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.jar.Attributes;
    * Runs a jar application from any url. Usage is 'java JarRunner url [args..]'
    * where url is the url of the jar file and args is optional arguments to be
    * passed to the application's main method.
    public class JarRunner {
      public static void main(String[] args) {
        URL url = null;
        try {
          url = new URL(args[0]);//"VideoTagger.jar");
        } catch (MalformedURLException e) {
          System.out.println("Invalid URL: ");
        // Create the class loader for the application jar file
        JarClassLoader cl = new JarClassLoader(url);
        // Get the application's main class name
        String name = null;
        try {
          name = cl.getMainClassName();
        } catch (IOException e) {
          System.err.println("I/O error while loading JAR file:");
          e.printStackTrace();
          System.exit(1);
        if (name == null) {
          fatal("Specified jar file does not contain a 'Main-Class'"
              + " manifest attribute");
        // Get arguments for the application
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        // Invoke application's main class
        try {
          cl.invokeClass(name, newArgs);
        } catch (ClassNotFoundException e) {
          fatal("Class not found: " + name);
        } catch (NoSuchMethodException e) {
          fatal("Class does not define a 'main' method: " + name);
        } catch (InvocationTargetException e) {
          e.getTargetException().printStackTrace();
          System.exit(1);
      private static void fatal(String s) {
        System.err.println(s);
        System.exit(1);
    * A class loader for loading jar files, both local and remote.
    class JarClassLoader extends URLClassLoader {
      private URL url;
       * Creates a new JarClassLoader for the specified url.
       * @param url
       *            the url of the jar file
      public JarClassLoader(URL url) {
        super(new URL[] { url });
        this.url = url;
       * Returns the name of the jar file main class, or null if no "Main-Class"
       * manifest attributes was defined.
      public String getMainClassName() throws IOException {
        URL u = new URL("jar", "", url + "!/");
        JarURLConnection uc = (JarURLConnection) u.openConnection();
        Attributes attr = uc.getMainAttributes();
        return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
       * Invokes the application in this jar file given the name of the main class
       * and an array of arguments. The class must define a static method "main"
       * which takes an array of String arguemtns and is of return type "void".
       * @param name
       *            the name of the main class
       * @param args
       *            the arguments for the application
       * @exception ClassNotFoundException
       *                if the specified class could not be found
       * @exception NoSuchMethodException
       *                if the specified class does not contain a "main" method
       * @exception InvocationTargetException
       *                if the application raised an exception
      public void invokeClass(String name, String[] args)
          throws ClassNotFoundException, NoSuchMethodException,
          InvocationTargetException {
        Class c = loadClass(name);
        Method m = c.getMethod("main", new Class[] { args.getClass() });
        m.setAccessible(true);
        int mods = m.getModifiers();
        if (m.getReturnType() != void.class || !Modifier.isStatic(mods)
            || !Modifier.isPublic(mods)) {
          throw new NoSuchMethodException("main");
        try {
          m.invoke(null, new Object[] { args });
        } catch (IllegalAccessException e) {
          // This should not happen, as we have disabled access checks
    }

  • Protecting your jar file from been extracted

    Please i noticed that the java jar file of a software can easily be extracted to review the class files with winrar which allows just anyone to have access to your class file and decompile to get source codes, allowing pirating of the software. How can I lock the jar file to prevent extraction of my class files.

    1. why are you mocking others instead of answering the question ? some one wants to protect his jar file. the solution is simple.
    2. you can use google to search, here is result :
    http://stackoverflow.com/questions/1280702/protecting-java-jar-files-for-distribution
    http://stackoverflow.com/questions/9633455/how-to-protect-a-jar-file-from-being-decompiled
    http://www.thegeekstuff.com/2008/06/protect-your-java-code-from-reverse-engineering/
    http://answers.google.com/answers/threadview/id/431511.html
    http://stackoverflow.com/questions/1879061/how-to-protect-java-codes-against-decompiler
    http://viralpatel.net/blogs/2009/07/protect-java-code-decompilation-using-java-obfuscator.html
    http://www.coderanch.com/t/430716/java/java/Protect-class-file-not-decompile
    http://stackoverflow.com/questions/7324708/are-jar-file-insecure-what-can-done-apart-from-code-obfuscation
    http://stackoverflow.com/questions/3647255/how-do-i-copy-protect-my-java-application
    http://www.javaworld.com/javaworld/javatips/jw-javatip22.html
    http://stackoverflow.com/questions/12088/do-you-obfuscate-your-commercial-java-code
    3. it is true if you can use basic methods that EJP mentioned, there would be no need for obfuscators, nor native library use.
    but there are many situations that you can't do any of those methods.
    4. EJP claims that he probably is the one "who have had perhaps 40 times as long as you've had to think about it."
    here is the problem that made me use both obfuscation and native library :
    My company released a simple java library that scanned a document (directly from scanner or camera device).
    the documents were exam papers.
    Use some OCR techniques to convert image to text so some other application could calculate the score using it's api.
    For marketing purposes, the company needed to publish a 7-day trial version of this library.
    So, as you can see I'm eager to hear what you want to suggest.

  • How to protect my jar file from being downloaded

    How can i protect my jar file from being downloaded by users by accessing it through the web site.
    Now everybody can just type the url www.mysite.com/applets/myApplet.jar
    And download it to his computer.
    I realize that anybody who really wants to download it he will get it anyway, but I want to make it harder.
    thanks in advance

    Your browser has to download the jar file if it's going to run the applet. That's applets work. The browser downloads the classes and then runs them locally.
    I suppose if you wanted to make something to make it difficult for users to explicitly download the jar, you could set some kind of permission flag when the HTML is page is rendered, and then unset it some amount of time (10 seconds?) later, and then only let the user download the jar when the flag is set. But this would be fragile and irritating and unhelpful. It would probably break more than you'd like and not prevent download very much (it wouldn't take long to figure out what was happening), and besides nobody is ever going to try to steal your code.

  • Error message at start-up Unable to access Jar file

    I am a consumer, not a business...and not an IT professional. I am running Vista and have not installed any new software recently.
    At every start-up, I get a pop-up titled Java Virtual Machine Launcher. The message says "Unable to access jar file". C:\users\user\.jnana.jnana.tsa.
    Any idea how to fix this?
    Thanks in advance.
    Edited by: 794979 on Sep 15, 2010 5:31 AM

    ok i'm gonna make it easier on you.
    i gess i found what is the problem but have no idea how to solve it.
    when i obtained the .jar file i also obtained a README.txt file in which it is written the following phrase:
    ** If a library on the projects classpath also has a Class-Path element*
    specified in the manifest,the content of the Class-Path element has to be on the projects runtime path.
    I'M SORRY BUT I DID NOT UNDERSTAND WHAT IS MEANT BY: what is "the projects runtime path"?
    the content of my manifest is:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 10.0-b23 (Sun Microsystems Inc.)
    Main-Class: hequalifies.ui.HeQualifies
    Class-Path: lib/PlugIn
    X-COMMENT: Main-Class will be added automatically by build
    I'm having problem with lib/plugin.

  • Deploying a JAR file from Forte

    I have written an application using the Forte CE IDE. Now I want to deploy it to other PCs running JRE1.3, so I used the JAR packager to create a JAR file and I ensured the manifest had the Start class specified. Unfortunately, when I try to run this application via the command line on either another machine or my own (outside of Forte), I get the message
    Exception in thread "main" java.lang.NoClassDefFoundError: <start class name>
    I have used the "java -jar" command.
    The start class is in the jar file.
    The start class name is in the manifest.
    I must have missed something, and I am at my wits end.
    Has anyone else had similar problems deploying applications from Forte? Or can anyone offer advice or a link to some comprehensive documentation on how to accomplish deployment? The help function in Forte was no help at all.
    Thanks.

    Are you sure that there is a newline after your lines in the manifest?
    Hit return after each line to make sure!

  • Reading files from phone memory

    Hi All,
    I am developing a Universal application using vs 2013 in windows phone 8.1. I am stuck in finding and reading file from phone memory.
    I have used the Localfolder syntax
    StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;but it didn't worked. Its Showing the application data. But i want to read the file exixts in my phone memory.Then i have usedStorageFolder file = KnownFolders.DocumentsLibrary;but as i read from the forums its not suggested way to approach. Please suggest me the way to find the file from phone memory and to read it.Any help would be appreciatable!!

    Hi sarika,
    That is expected, see the documentation for more information:
    App capability declarations at Documents section, you need declared at least a file type association.
    Furthermore You can't use the Documents library in a Windows Phone Store app.
    You can't publish a Windows Phone Store app that specifies the documentsLibrary capability to the Windows Phone Store. The Store blocks the publishing of the app.
    Your app can't access the Documents library in the phone's internal storage. If another app creates a Documents folder on the optional SD card, however, your app can see that folder.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Calling jar file from jsp - serious problem !

    Hi there, I'm trying to call a jar from a jsp file. I need an import clause in my jsp, to the class I want to use.
    I'm using eclipse, and while i"m writing "<%= " and the begining of my class name , he autocompletes it and automatically puts an import of my class in the top of the html. It is very convenient , but the problem is that he underling the class name (in the impot: <%@page import="myClass"%>), and I get "The import myClass cannot be resolved" error.
    I got an advice to put my class in a package, since it was in a default package. I did it. But now I have 2 problems:
    1. I can't run my jar in command window: java - jar myJar.jar. in gives me: Exception in thread "main" java.lang.NoClassDefFoundError....
    2. I still get an error - "The import myClass cannot be resolved" in the jsp, although I threw the old jar (that his class I want to use was out of package), and brought a new jar after creating it.
    I hope I managed to clarify myself. I'll be thankful of any help !!!

    Hi MSoldier.
    There are two ways to do this:
    1) You use the java.lang.Runtime classes to start the java application in your JAR file, just like you would have done it from the command line. The Runtime class has three different exec() methods that can be used to run any program just like you would from the command line. Remember, using this method you will have to write everything just like if you run your Java application from the command line, incl. classpath etc. This way your Java application will be run as a separate process. When the application finishes the process is shutdown and the resources (RAM etc.) taken by it freed, just like when you shutdown any other application.
    2) You can open the JAR file yourself from inside the JSP page, look inside the META-INF file to find the main class, and then calls the main class main method. There is an example of how to do this in the Java Tutorial available from Sun under the JAR files track. Check these links :
    The Java Tutorial at Sun
    http://java.sun.com/docs/books/tutorial/
    The JAR File Tutorial at Sun
    http://java.sun.com/docs/books/tutorial/jar/index.html
    Opening JAR Files via the Java JAR File API
    http://java.sun.com/docs/books/tutorial/jar/api/index.html
    Note however, if you have just created some classes that you want to use from inside your JSP pages, and not a separate application that needs to be run separately, you should just include the JAR file with your custom classes inside the WEB-INF/lib directory. These classes are then automatically available to your JSP pages, just like the rest of the Java API.
    I hope this answers your questions,
    Kind Regards,
    Jakob Jenkov
    Software Architect
    Jenkov Development
    www.jenkov.com

  • Running .jar files from Java code

    Hi.
    I am designing a sort of platform to run some games which are saved in .jar files. Basically this platform is a menu from which the user can select the game which he/she wants to run. It also has the feature of adding new games.
    Is is possible to run the .jar file from within java code?
    Thanks for any help!
    Krt_malta

    Just list the jar in the classpath list and call the class in the jar.

Maybe you are looking for