Detecting if class is loaded from jar?

is this possible?

because my current app, stupid or not, tries to save a
file in the directory where the class is located. But
if its a jar, it cant save it there!?No, you cannot write something into a jar file. To do that you have to create a new version of the jar file, copy all the jar entries from the old version, and add a new jar entry for the new something you want to add, then delete the old version and rename the new version back. Apart from being cumbersome, this will probably not work in your case because the JVM will have a lock on the jar file containing your classes. So if you have a configuration file that can be changed by the program, you don't want to store it in a jar file.

Similar Messages

  • Where do Pipeline Component classes get loaded from?

    Can someone please point me to some documentation that describes where my Pipeline
    Component classes get loaded from?
    I have just wasted hours on this - to find that they are not loaded from WEB-INF/classes
    - but instead they must be available to the EJB classloader. The sampleportal
    is completely misleading in putting the classes in WEB-INF/classes - because they
    are in fact loaded from the sampleportal EJB jar!
    Did I miss something obvious?
    regards,
    Nick

    Nick
    Refer to this portal doc on dev2dev
    ftp://edownload:[email protected]/pub/downloads/webflow.doc
    -tulan
    "Nick Minutello" <[email protected]> wrote
    in message news:[email protected]..
    >
    >
    Can someone please point me to some documentation that describes where myPipeline
    Component classes get loaded from?
    I have just wasted hours on this - to find that they are not loaded fromWEB-INF/classes
    - but instead they must be available to the EJB classloader. Thesampleportal
    is completely misleading in putting the classes in WEB-INF/classes -because they
    are in fact loaded from the sampleportal EJB jar!
    Did I miss something obvious?
    regards,
    Nick

  • Find out where class was loaded from

    Is there a way to find out from what resource the java runtime loaded a class from? I know that -verbose:class argument will tell where classes were loaded from during runtime for only normal sun libs (core libraries from rt.jar), but it does not say where it is loading external stuff from. Can this be found out?
    For example, if a particular third party class is available several times (through accidental redundancy in classpaths)-- find out which resource it was taken from.
    I am sure you could get down into the weeds and look thorugh all the classpath entries for which ones contain which classes-- but there has got to be a better way.

    import java.io.File;
    import java.net.JarURLConnection;
    import java.net.URL;
    import java.net.URLDecoder;
    private File getPathToClass(Class c)
         try
              URL url = getClass().getResource(c.getName() + ".class");
              if( url.getProtocol().equals("jar") )
                   JarURLConnection jarCon = (JarURLConnection)url.openConnection();
                   url = jarCon.getJarFileURL();
              File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
              return file;
         catch(Exception e)
              return null;
    }

  • Find where Actionscript class is loaded from

    Hi folks,
              Is there anyway to tell where an actionscript class is loaded from (i.e. what swf file) at runtime? I've had a look at some of the reflection api's and some of the sample code but none seem to address this. I'm originally a Java developer and this is a fairly straightforward call. For any java developers who may be viewing this if I may I'll put in the java for which I'm looking for the equivalent actionscript if possible.
    Thread.currentThread().getContextClassLoader().getResource("java/lang/String.class").getPa th();
    This will give me the location jar/folder path from where the String class is loaded for the particular thread.
    Any help would be greatly appreciated,
    Mark.

    No official API, but there is a getSWFRoot on SystemManager that might help.

  • Failed to load main-class manifest attribute from jar files....

    Hi,
    I installed Java1.5 version in my system before to that Java1.6 was installed and uninstalled. When i i double clicked on any jar file getting a message like: Failed to load main-class manifest attribute from<name of the jar file>.jar file....
    can anyone please suggest me how to rectify this error.

    mvnath wrote:
    The jar files are worked before the installation of 1.5 but not after installation of 1.5I am guessing that the Windows file association for .jar somehow got munjed. It's hard to say since you have not provided much information.

  • Failed to load Main-Class manifest attribute from jar

    I get this error when i try start a executable jar file:
    Failed to load Main-Class manifest attribute from
    even though i have a
    Main-Class: a.b.c.MyClass
    entry in the meta-inf/manifest.mft
    I also have a (rather long) "Class-Path:" entry preceeding the "Main-Class:" entry in the manifest. What's wrong?

    ant has a major problem with very long "Class-Path" entries in a manifest file.
    The ant manual states, that jars wrap lines in manifest files longer than 72 characters. They say it's not their fault, and they can't do anything about it...
    I need to make an executable jar file with a classpath of approx. 200 characters.
    When i use Netbeans to jar the project, everythings fine.
    But using ant, the Class-Path seems to get messed up and none of the external classes are found, even though the manifest looks just like the one generated by Netbeans and the jar contents are the same.
    One way to workaround this problem is by using a manifest like this:
    Class-Path: some.jar foo.jar
      someother.jar
      guesswhat.jar
    Main-Class: what.everPlease take note of the leading spaces on the second and third Class-Path line.
    But i don't think, there's any way to make ant create a manifest like that using the ant <manifest> tag, because you can only specify a single "Class-Path" attribute, empty attributes are not allowed and if you use ${line.separator} to break lines, the line will still get a hard break after 72 characters. D'uh!
    Looks to me like a case of denial.
    On the other hand, there's another good idea to be found at jakarta:
    http://jakarta.apache.org/commons/sandbox/hivemind/jakarta-hivemind/ant/ManifestClassPath.html
    I'm going to check tomorrow if this might solve the problem.
    Or is there some other magical ingredient missing in the ant generated jar, that the NetBeans generated jar has??
    The most interesting part is, that i can't even make the ant jar run properly, if i call
    java -classpath ... -jar myAnt.jar

  • Java applet won't load from Jar file

    Hi all,
    I have a problem which I didn't used to have. I have written an applet which used certain classes stored in directories. It used to work just fine. I recently updated the main class from which the applet starts and since then I get error messages:
    Java Plug-in 1.6.0_26
    Using JRE version 1.6.0_26-b03-384-10M3425 Java HotSpot(TM) 64-Bit Server VM
    User home directory = /Users/benoize
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    load: class WiaRekenToolHC.class not found.
    java.lang.ClassNotFoundException: WiaRekenToolHC.class
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
         at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:687)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3046)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1498)
         at java.lang.Thread.run(Thread.java:680)
    Exception: java.lang.ClassNotFoundException: WiaRekenToolHC.class
    As you can see it says that it can't find the class WiaRekenToolHC, but it's there in the jar files.
    Here is the link where you can see it:
    www.creativemathsolutions.nl/demo/HC/demo.html
    The jar files are in the directory HC and Generic.
    If you need more info then let me know!
    Regards, Benoit

    <applet
      codebase="http://www.creativemathsolutions.nl/demo/HC"
      code="WiaRekenToolHC.class"
      ARCHIVE="HC/wia_hc_archive_v0_3.jar, Generic/wia_archive_v0_3.jar"
      width=900 height=600>The code-base combined with archive href for the first Jar mean the JRE will look for it at:
    http://www.creativemathsolutions.nl/demo/HC/HC/wia_hc_archive_v0_3.jar
    It is not there. The other Jar is also missing from the stated location.

  • Find where a class is loaded from

    Hi
    How do I find out programmatically where a class is being loaded from.
    For ex:
    I want to know where the java.rmi.Naming class is being loaded from. I thought it was from the rt.jar file. I deleted the Naming.class and 2 other anonymous inner classes of Naming class from rt.jar. When I do Class c = Class.forName("java.rmi.Naming"); it still works.
    TIA
    Sankar

    check this out:
    http://www.javaworld.com/javaworld/javatips/jw-javatip105.html
    "The Java classpath has always been a source of frustration and confusion, despite its seemingly simple concepts. This article demonstrates a simple tool for unambiguously identifying which Java class in your classpath the class loader will load."

  • Classes not loaded from cached JAR ???

    I am running an applet package in jar files using the 1.4.1 plug-in.
    The plug-in is set to cache the JAR file(s) downloaded from the web site, and output in the plug-in console indicates that these JARs are downloaded an cached successfully. I noticed that there is a lot of network traffic as the user is interacting with the applet. After I turned plug-in tracing on, I noticed that the plug-in is accessing the server (where the jar files are downloaded from) every time it needs to load a class or resource!
    The java console contains trace outputs of the form:
    Connecting http:[myserver]/someclass.class with no proxy
    Connecting http:[myserver]/someclass.class with cookie "JSESSIONID=..."
    The applet sometimes freezes until a given class can be accessed over the network!
    Does anyone have any idea why the applet keeps going back to the server for classes and resources through they are contained in the downloaded and cached JAR file?

    I do have the archive tag, but not the cache_archived. In fact the html page contains the following:
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = "100%" HEIGHT = "100%" ID = "myApplet"
    codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME = "CODE" VALUE = "appletclass.class" >
    <PARAM NAME = "ARCHIVE" VALUE = "myjar.jar"
    <PARAM NAME = "MAYSCRIPT" VALUE = "true" >
    <PARAM NAME = "type" VALUE="application/x-java-applet;version=1.3.1">
    <PARAM NAME = "scriptable" VALUE="true">
    </OBJECT>
    As far as I can tell the jar file is downloaded only once. It's when the classes (in the jar) are accessed that the applet goes back to the servlet!

  • Dynamic class loading from JARs in web application

    Hello,
    I'm working on a web project in which we would like to dynamically load plugins without server restart.
    We have developed our own ClassLoader in order to load the plugins from a path or with a user interface upload function.
    The class loader hierarchy should be something like this:
          Bootstrap
              |
           System
              |
           Common
    Catalina   Shared
            Webapp1  OurSystem
                       PluginClassLoaderThe all works fine within the classes loaded in the PluginClassLoader, but classes loaded in OurSystems class loader cannot access classes loaded in PluginClassLoader. For example when Hibernate tries to load classes definied in mapping files we got a java.lang.ClassNotFoundException.
    Is there a way to load classes dynamically to OurSystems class loader or notify it about PluginClassLoaders classes?
    Or is this a bad way to do it?
    Best regards,
    Kristoffer Renholm

    Hi,
    Sounds like a classpath problem that the folks in the workshop newsgroup
    could help with. Try asking your question in:
    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=xover&group=weblogic.developer.interest.workshop&utag=
    Bruce
    Graeme Dougal wrote:
    >
    Hi, I am developing a web service with weblogic workshop. The JWS file references
    other classes one of which is a factory for distributing various implementations
    of an interface. I am trying to dynamically load the relevant class to be distributed
    from the factory via its name, e.g. Class c = Class.forName(className)
    However I keep getting a classNotFoundException.
    Any ideas ??

  • Applet not loading from JAR?

    Well, I've been having a bit of a problem with embedding my applet into a webpage. My applet tag looks like this:
    <applet archive="poke.jar" code="a.class" width=550 height=600>
    <param name=cachelistsrcdir value="http://io9labs.com/poke/cache">
    </applet>and when I access the page, I set the trace level to 5 in the Java Console, and look into it and see the following:
    basic: Stopping applet ...
    basic: Removed progress listener: sun.plugin.util.GrayBoxPainter@61db2b
    basic: Finding information ...
    basic: Releasing classloader: sun.plugin.ClassLoaderInfo@1df377e, refcount=0
    basic: Caching classloader: sun.plugin.ClassLoaderInfo@1df377e
    basic: Current classloader cache size: 3
    basic: Done ...
    basic: Joining applet thread ...
    basic: Destroying applet ...
    basic: Disposing applet ...
    basic: Quiting applet ...
    basic: Joined applet thread ...
    basic: Referencing classloader: sun.plugin.ClassLoaderInfo@1df377e, refcount=1
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter@c710ba
    basic: Loading applet ...
    basic: Initializing applet ...
    basic: Starting applet ...
    basic: completed perf rollup
    network: Cache entry not found [url: http://io9labs.com/poke/a.class, version: null]
    network: Connecting http://io9labs.com/poke/a.class with proxy=DIRECT
    network: Connecting http://io9labs.com/poke/a.class with cookie "PHPSESSID=831a2067577cfe38db085b2566c36631"
    network: Cache entry not found [url: http://io9labs.com/poke/a/class.class, version: null]
    network: Connecting http://io9labs.com/poke/a/class.class with proxy=DIRECT
    network: Connecting http://io9labs.com/poke/a/class.class with cookie "PHPSESSID=831a2067577cfe38db085b2566c36631"
    load: class a.class not found.
    java.lang.ClassNotFoundException: a.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    basic: Exception: java.lang.ClassNotFoundException: a.classIt seems as though it's trying to load the applet from the actual directory, instead of the JAR. Any ideas on why this is happening? Thanks in advance for your help.
    Also, the applet is located at http://io9labs.com/poke/

    I'm using Mozilla Firefox 3.0.1 on Windows XP with SP2. I tried running it with IE7 and it gives me the same exact problem. It can't be my browser because it loads JAR'ed applets on any other webpage just fine.
    I tried it with a non-obfuscated JAR, and it STILL gives me the same error. Do you have any ideas as to why it would choose to ignore the archive attribute?
    EDIT: I think it might be because I signed it improperly, lemme try that.
    EDIT2: Nope, still doesnt work
    EDIT3: Problem solved, it was because the JAR needed a unique name, and i already had a jar of the same name in my cache.
    Edited by: io9_ on Aug 20, 2008 11:17 AM

  • GIF files not loading from jar in Netscape

    Hi,
    I have a jar file that contains my applet code(class files) and a bunch of gif files. I load the image using the URL returned from getCodeBase() method. The images load fine in Explorer but they do not show up in Netscape. The class files and gif files are not in separate directories and getCodeBase is returning the correct URL of my server(Example: http://www.myserver.com). Does anyone know how to fix this? I also noticed that download time did not improve on either browser when I bundled all the gif file in the jar rather than place them outside the jar file. Isn't bundling them in the jar supposed to save multiple requests back to the server to get the gifs and thus reduce download time? Thanks in advance.

    There the sample from Netscape: http://developer.netscape.com/docs/technote/java/getresource/getresource.html#classloader

  • ImageIcon not loading from Jar file

    Hi,
    I'm developing an application that uses ImageIcons in JButtons.
    The images are stored in the following relative dir:
    images/<filename>.jpg
    They load fine when I run the application from class files in the appropriate directory.
    However when I jar everything, my ImageIcons don't load.
    I know that my jar file is in the classpath, because other items in the jar file load successfully.
    I've tried everything the related threads recommend, but still nothing.
    When I try to launch from the jar file, the ClassLoader.getResource("filepath"); returns null.
    Whereas when I launch the class files, it returns the correct URL for the image.
    What am I missing? Is this jar file security-related? Do I need to sign the jar file with all-permissions?
    Any suggestions would be gratefully appreciated.
    I'm using java 1.4.2_01-b06
    Much thanks,
    -Jeroen

    Here is a little load program that you can use.
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    * <p>Resources extracts all the resources from a jar file into binary large
    * objects. These objects can be used to create images or read as streams.
    * This class is implemented as a singleton model.</p>
    * <p>An attempt is made to find the path to the jar file in
    * if this file is not found no resources are
    * loaded.
    * @author Michael Couck
    * @version 1.00, 16/01/2004
    public final class Resources extends Constants {
          * The only instance of this class
         private static Resources resources;
          * Hashtables for the sizes of the entries in the jar
         private static Hashtable sizes= new Hashtable();
          * Hashtable for each entry in the jar as a blob
         private static Hashtable contents= new Hashtable();
          * Flag to test if the resources were loaded correctly
         private static boolean resourcesLoaded= false;
          * Initilises the <code>static</code> instance of the
          * <code>Resources</code> instance.
         public static void initiliseResources() {
              if (resources == null)
                   resources= new Resources();
          * Instanciates a <code>Resources</code> object.
         private Resources() {
              init();
          * Returns a resource as a <code>byte</code> array, which can then be used
          * as a <code>ByteArrayInputStream</code> to instanciate among other things
          * images and property files.
          * @param name a resource name. This is the path to the recource from the
          *         root of the jar file.
         public static byte[] getResourceAsByteArray(String name) {
              if (resources == null)
                   resources= new Resources();
              return (byte[]) Resources.contents.get(name);
          * Returns true if the resources were correctly loaded
         public static boolean resourcesLoaded() {
              return resourcesLoaded;
          * Reads the jar file and inserts the contents
          * into the Hashtables.
         public void init() {
              try {
                   //Sizes into the table     
                                                                    File jar= new File("[path to]/yourjar.jar");
                   if (jar != null && jar.exists()) {
                        //Found the path to this jar file
                        ZipFile zipFile= new ZipFile(jar);
                        Enumeration enum= zipFile.entries();
                        while (enum.hasMoreElements()) {
                             ZipEntry zipEntry= (ZipEntry) enum.nextElement();
                             sizes.put(
                                  zipEntry.getName(),
                                  new Integer((int) zipEntry.getSize()));
                        zipFile.close();
                        //Contents into the table
                        FileInputStream fis= new FileInputStream(jar);
                        BufferedInputStream bis= new BufferedInputStream(fis);
                        ZipInputStream zis= new ZipInputStream(bis);
                        ZipEntry zipEntry= null;
                        while ((zipEntry= zis.getNextEntry()) != null) {
                             if (zipEntry.isDirectory()) {
                                  continue;
                             int size= (int) zipEntry.getSize();
                             // -1 means unknown size.
                             if (size == -1) {
                                  size=
                                       ((Integer) sizes.get(zipEntry.getName()))
                                            .intValue();
                             byte[] blob= new byte[(int) size];
                             int readBuffer= 0;
                             int buffer= 0;
                             while (((int) size - readBuffer) > 0) {
                                  buffer=
                                       zis.read(blob, readBuffer, (int) size - readBuffer);
                                  if (buffer == -1) {
                                       break;
                                  readBuffer += buffer;
                             contents.put(zipEntry.getName(), blob);
                        resourcesLoaded= true;
              } catch (NullPointerException e) {
                   Constants.logger.severe(e.getMessage());
                   StackTraceElement[] stackTrace= e.getStackTrace();
                   for (int i= 0; i < stackTrace.length; i++) {
                        Constants.logger.severe(stackTrace.toString());
                   resourcesLoaded= false;
              } catch (FileNotFoundException e) {
                   Constants.logger.severe(e.getMessage());
                   StackTraceElement[] stackTrace= e.getStackTrace();
                   for (int i= 0; i < stackTrace.length; i++) {
                        Constants.logger.severe(stackTrace[i].toString());
                   resourcesLoaded= false;
              } catch (IOException e) {
                   Constants.logger.severe(e.getMessage());
                   StackTraceElement[] stackTrace= e.getStackTrace();
                   for (int i= 0; i < stackTrace.length; i++) {
                        Constants.logger.severe(stackTrace[i].toString());
                   resourcesLoaded= false;
    } //End Resources
    You can get the icons with "new ImageIcon(new ByteArrayResources.getResourceAsByteArray(String name));
    See ya
    Michael

  • Unwanted faces-config getting loaded from jars in classpath

    In our application, we have some 3rd party jars containing faces-config xml's. These get merged with our main faces configs. Is there a way to tell the loader to exclude faces-config from some jars. Of course, cleaning these jars of faces config is a way, but we want to keep it as last resort only.

    In our application, we have some 3rd party jars containing faces-config xml's. These get merged with our main faces configs. Is there a way to tell the loader to exclude faces-config from some jars. Of course, cleaning these jars of faces config is a way, but we want to keep it as last resort only.

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

Maybe you are looking for

  • Point-to-Site disconnect every few minutes

    Hi, I'm using Azure vNet Point-to-Site feature and I can connect from an on-premise server to my Azure Gateway and to a Web Role located in my vNet. My problem is that the VPN connection get's dropped at irregular intervals (after 3, 6, 12, 20, 21 mi

  • Java Code to transfer a file through FTP

    I am writing a java code to transfer a file from local machine to a server on another machine. While uploading i am encountering with an exception which is showing as java.net.ConnectException: Connection refused: connect The file is getting transfer

  • RGB values

    I know my iMac has a digital color meter in it (finder, utilities, digitalcolor meter. But its giving me sort of funky readings off my photo's. I'm making a zone system for my camera for a class (ugh awful assignment). I have Aperture, can I see the

  • What happened to the southern gospel channel on iTunes music?

    WWhere did the southern gospel channel go? It was there yesterday and gone today. It's enough to make me cancel iTunes match.

  • JavaScript and Adobe Flash player massage in webpage

    Hi all, I have difficulties surfing some of the pages. It either show Adobe Flash Player not available or javascript not present. I had on both plug-in and javascript but it still show the above massages. Especially i surf pages which require to logi