TLDR;  Is there any way to tell java to UN-load a native library so that I can re-load it? (I understand it can only be loaded in a single class loader.  See below).  I know it's unloaded when the classloader is garbage collected, but I've had no success forcing a garbage collection.  Any ideas?    I found this question that explains why I'm hitting my error:   But it's not specific to what I'm wanting to do.  We have a jar that we want to be able to dynamically load at runtime (plugin style) to run some scale tests on another service.  It works fine on the first run, but when I stop the test run and attempt to unload the previous classloader and load a new one, I get the following error:  Caused by: java.lang.UnsatisfiedLinkError: Could not load J2V8 library. Reasons:          no j2v8_macosx_x86_64 in java.library.path         Native Library /Users/brian.trezise/libj2v8_macosx_x86_64.dylib already loaded in another classloader          at com.eclipsesource.v8.LibraryLoader.loadLibrary(LibraryLoader.java:71)         at com.eclipsesource.v8.V8.load(V8.java:70)         at com.eclipsesource.v8.V8.createV8Runtime(V8.java:132)         ... 8 more   Here's my method, which creates a new classloader to dynamically load my jar, and if one was previously it invalidates it by calling classLoader.close():  public void reloadJar(String jarName) throws IOException {         if (this.classLoader != null) {             classLoader.close(); //Invalidate the old class loader so we can load a new one         }         File file = new File(JAR_FILE_DIR + jarName);         if (!file.exists()) {             throw new IllegalStateException("The specified file does not exist");         }          URL urls[] = {file.toURI().toURL()};         classLoader = new EmbeddedJarClassLoader(urls, Thread.currentThread().getContextClassLoader());         LOGGER.info("Finished loading scale test jar");     }   My question: Is there any way to tell Java that a native library should be unloaded?
121465
I need to unload a DLL that was loaded with System.loadLibrary(..), anyone know if this is possible?
60178
In Java, is there any way to use the JDK libraries to discover the private classes implemented within another class? Or do I need so use something like asm?
49974
How can you reliably and dynamically load a JavaScript file?  This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand.  The client that uses the component isn't required to load all the library script files (and manually insert &lt;script&gt; tags into their web page) that implement this component - just the 'main' component script file.  How do mainstream JavaScript libraries accomplish this (Prototype, jQuery, etc)?  Do these tools merge multiple JavaScript files into a single redistributable 'build' version of a script file?  Or do they do any dynamic loading of ancillary 'library' scripts?  An addition to this question: is there a way to handle the event after a dynamically included JavaScript file is loaded?  Prototype has document.observe for document-wide events. Example:  document.observe("dom:loaded", function() {   // initially hide all containers for tab content   $$('div.tabcontent').invoke('hide'); });   What are the available events for a script element?
6832
How does one go about and try to find all subclasses of a given class (or all implementors of a given interface) in Java? As of now, I have a method to do this, but I find it quite inefficient (to say the least). The method is:    Get a list of all class names that exist on the class path Load each class and test to see if it is a subclass or implementor of the desired class or interface   In Eclipse, there is a nice feature called the Type Hierarchy that manages to show this quite efficiently. How does one go about and do it programmatically?
61721
Apparently, I have OpenJDK 6 JRE (openjdk-6-jre 6b27-1.12.6-1ubuntu0.12.04.2) and 7 JRE (openjdk-7-jre 7u25-2.3.10-1ubuntu0.12.04.2) installed in parallel – I don't know why I have both of them, I can't remember installing any of them manually.  However, the Firefox Java plugin is occasionally reported to be out of date by some websites, and it seems to me that it relies on JRE 6. How can I make Firefox use the newer version? Removing JRE 6 seems like a bad idea; when I attempted to do so in synaptic it appeared to me that a lot of software still relies on the older JRE, since removing it would have removed programs like jedit as well.  Do I mix up stuff? I'm not even sure how the FF plugin interferes with the OpenJDK JRE's.  EDIT:  Having tried even more, the problem persists. Using update-alternatives --config java, I see that the default Java version (with status "manual mode") is already set to Java 7, and java -version returns "1.7.0_25". The file /usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/IcedTeaPlugin.so exists, but still Firefox shows the Java 6 plugin when looking at about:plugins.  To sum it up:  How do I make Firefox use the IcedTea plugin belonging to the default Java version?
3732
For example:  javac Foo.java Note: Foo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
107809
I'm an entry level programmer so please be descriptive in your responses.  I am trying to use a Java API given as a .jar file in my C# .net application.  I don't know much Java, but this .jar file says "no main-class manifest attribute" when I try to run it so this means its a library?  This Java API also comes with a .java file which shows how to use the library but I cannot see the code inside the .jar.  I found  on this site, and one of the answers reads, "In simple way you can pack your java classes to jar file then In C# use Process class for execute and map IO stream."  I am semi-familiar with the Process class in C# but I don't understand how I could use it to use a Java library in my C# .net project.  Is this possible? or was that answer incorrect?  If so, could you explain how I can use the .jar library in my C# app.
108868
I have a Jar file, which contains other nested Jars. When I invoke the new JarFile() constructor on this file, I get an exception which says:     java.util.zip.ZipException: error in opening zip file   When I manually unzip the contents of this Jar file and zip it up again, it works fine.  I only see this exception on WebSphere 6.1.0.7 and higher versions. The same thing works fine on tomcat and WebLogic.   When I use JarInputStream instead of JarFile, I am able to read the contents of the Jar file without any exceptions.
929
I would like to be able to write a Java class in one package which can access non-public methods of a class in another package without having to make it a subclass of the other class. Is this possible?
97558
I've been trying to install the Java plugin for Chrome for a couple hours now, and I figured it was time to ask people with more experience. I can't seem to get it working. My current Java version is the 64-bit OpenJDK 1.6.0_24. I tried installing the IcedTea plugin to no avail. I have Ubuntu 12.04 64-bit installed at the moment.  When I tried testing if java was enabled in Chrome, any website with a Java applet would not load (when I disabled the plugin, they loaded, but not the applet).  I followed the instructions from here:   which said to create this script and run it:  JAVA_HOME=/usr/lib/jvm/jdk1.7.0 MOZILLA_HOME=~/.mozilla mkdir $MOZILLA_HOME/plugins ln -s $JAVA_HOME/jre/lib/i386/libnpjp2.so $MOZILLA_HOME/plugins   Note: You may need to change the value of JAVA_HOME so that it correctly points to your installation of the JDK. 64-bit users will need to change the final line to:   ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so $MOZILLA_HOME/plugins   but this did not work as well.  I just test it in Firefox and it's working. Still nothing for Chrome
75289
In relation to , I need to check whether a component that will be instantiated by Castle Windsor, can be garbage collected after my code has finished using it. I have tried the suggestion in the answers from the previous question, but it does not seem to work as expected, at least for my code. So I would like to write a unit test that tests whether a specific object instance can be garbage collected after some of my code has run.  Is that possible to do in a reliable way ?   EDIT  I currently have the following test based on Paul Stovell's answer, which succeeds:       [TestMethod]     public void ReleaseTest()     {         WindsorContainer container = new WindsorContainer();         container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();         container.AddComponentWithLifestyle&lt;ReleaseTester&gt;(LifestyleType.Transient);         Assert.AreEqual(0, ReleaseTester.refCount);         var weakRef = new WeakReference(container.Resolve&lt;ReleaseTester&gt;());         Assert.AreEqual(1, ReleaseTester.refCount);         GC.Collect();         GC.WaitForPendingFinalizers();         Assert.AreEqual(0, ReleaseTester.refCount, "Component not released");     }      private class ReleaseTester     {         public static int refCount = 0;          public ReleaseTester()         {             refCount++;         }          ~ReleaseTester()         {             refCount--;         }     }   Am I right assuming that, based on the test above, I can conclude that Windsor will not leak memory when using the NoTrackingReleasePolicy ?
13904
I'm doing some architectural cleanup that involves moving a bunch of classes into different projects and/or namespaces. Currently I'm moving the files by hand, building, and then manually adding using Foo statements as needed to resolve compilation errors. Anyone know of a smarter way of doing this? (We're a CodeRush and Refactor! shop, but I'd be interested to hear if Resharper has support for this)
77532
In C# code can you catch a native exception thrown from deep in some unmanaged library? If so do you need to do anything differently to catch it or does a standard try...catch get it?
14268
I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found  and others saying on Windows machine the JVM defaults max heap size as 64MB.  Given this situation, how should I deal with this constraint?  I could increase the max heap size using command line option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some finite max does not ultimately get rid of the issue.  I could rewrite some of my code to persist objects to file system frequently (using database is the same thing) to free up the memory. It could work, but it's probably a lot work too.  If you could point me to details of above ideas or some alternatives like automatic virtual memory, extending heap size dynamically, that will be great.
61411
Is it possible to know whether a Java class has been loaded, without attempting to load it? Class.forName attempts to load the class, but I don't want this side effect. Is there another way?  (I don't want to override the class loader. I'm looking for a relatively simple method.)
103112
When and why would somebody do the following:  doSomething( (MyClass) null );   Have you ever done this? Could you please share your experience?
36393
I have a java application that uses some third party API. The third party jar files change fairly frequently because of all kinds of patches, but the API itself does not change that often.   Do I have to recompile my application every time the third party jar changes?