Load jar in ClassLoad

I need load jar in ClassLoad, I did write code, but he not work. what is the problem?
package jar;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
public class Jar1 {
    public static void main(String[] args) {
        try {
            String filePath = "/home/pitbull/temp/plugins/script.jar";
            printJar(filePath);
            load(filePath);
        } catch (Exception e) {
            e.printStackTrace();
    public static void printJar(String path) throws IOException {
        JarFile jarFile = new JarFile(path);
        Enumeration entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            System.out.println(entry.getName());
        jarFile.close();
    public static void load(String filePath) throws MalformedURLException, ClassNotFoundException {
        filePath = "jar:file://" + filePath + "!/";
        URL url = new File(filePath).toURI().toURL();
        URLClassLoader clazzLoader = new URLClassLoader(new URL[]{url});
        Class clazz = clazzLoader.loadClass("scripts.task_custom_field_value.MessageFormat");
        for (Method method : clazz.getMethods()) {
            System.out.println(method.getName());
}This jar "/home/pitbull/temp/plugins/script.jar" not classpath.

Get exception. But class scripts.task_custom_field_value.MessageFormat.class is exactly have in jar.
java.lang.ClassNotFoundException: scripts.task_custom_field_value.MessageFormat
     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
     at jar.Jar1.load(Jar1.java:38)
     at jar.Jar1.main(Jar1.java:18)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)Edited by: P1tBull on Jul 27, 2010 2:17 AM

Similar Messages

  • Replacing JAR files loaded by custom ClassLoader

    Hi all,
    I am trying to create an auto-updater for a stand alone application, which can look for new versions of relevant jar files on the internet and download them. I have code which will look for newly downloaded versions and can replace the old jar file with the new one (using simple File methods). This works fine for when the application is started initially, but as the application is a server and may not manually be started for a long time, I am trying to force the server to restart and reload with the new code.
    if(newCode.exists()) {
         System.out.println("new code!");
         if(oldCode.exists()) {
              oldCode.delete();
         if(code.exists()) {
              if(! code.renameTo(oldCode)) {
                        throw new IOException("Error backing up code file");
         if(! newCode.renameTo(code)) {
              throw new IOException("Error installing new code file");
    }I have looked around the forums a bit, and have come up with using a ClassLoader based on URLClassLoader:
    class ProxyLoader extends URLClassLoader
         public ProxyLoader(String jarFile) throws MalformedURLException {
              super(new URL[] { (new File(jarFile)).toURL() });
         public Class findClass(String name) throws ClassNotFoundException {
              System.out.println("Finding: " + name);
              return super.findClass(name);
    }This seems to work OK, as all the classes from the jar file are loaded by this classloader.
    I have a method which can create an instance of the class loader, and load the server application.
    private boolean startProxy(int port) {
         try {
              pl = new ProxyLoader("proxy.jar");
              Class ptClass = pl.loadClass("proxy.POPThread");
              pt = ptClass.newInstance();
              Method ptStart = ptClass.getMethod("start", new Class[0]);
              ptStart.invoke(pt, new Object[0]);
              return true;
         } catch(Exception e) {
              return false;
    }I also have a method to shut down the server:
    private boolean stopProxy() {
         try {
              Class ptClass = pl.loadClass("proxy.POPThread");
              Method ptInterrupt = ptClass.getMethod("interrupt", new Class[0]);
              ptInterrupt.invoke(pt, new Object[0]);
              return true;
         } catch(Exception e) {
              return false;
    }These appear to be working fine, the problem I have however is when I try to rename the existing jar file (proxy.jar) in order to replace it with a new one (proxy.new), the renameTo method on the File object fails. I am guessing that is because the proxy.jar file is still in use by the JVM. I have tried setting the classloader var to null, but this doesnt seem to have any effect.
    My main question is how can I 'free' the jar file so that it can be replaced with new code? Is it possible? My only otherway of working around this is to have a variable stored in a file pointing at the 'current' code, but the jar file isn't litterally replaced.
    This is a standalone application, which will probably run in a startup script on a server, so webstart isn't really an option.
    TIA
    iklesteve

    I have found this to be true anytime I try to use the renameTo() API to rename a file with a .jar file extension (regardless of the actual file type - i.e. it could be a text file with .jar appended and it will still fail) in the case where the class making the renameTo() call is loaded from another .jar file.
    I run the same exact code after extracting from the .jar, then the rename to the other .jar file is successful. Also, if I rename the .jar file to a ".ja" file, I can successfully rename the jar file even if the code is running with the context of another .jar file.
    Is this some kind of bogus security measure within the JVM or is it a bug?

  • Customer ClassLoader:  keeping JWS from loading jars

    I really like the ability of JWS to be able to download jars required for my application to run, but there are several jars that I need the ability to load up via a custom ClassLoader. But because JWS includes all of these jars in the classpath upon application start, the system class loader will take the first class it can find. Because I need to load classes from these jars based upon something a user selects, I need to have control over the codesource for these classes. Does anyone have any ideas on how to tackle this problem? Not include the jars in the jnlp and then download if not cached locally, if that's the case what's the best way to do that? Include in jnlp and be able to load with custom classloader(I dont think this will work)? Any ideas on this would greatly be appreciated.

    Easiest solution to your problem and still being able to use the update mechanism of JWS is to include your JAR-file in another JAR-file that JWS loads, and then write up your own classloader, which tries to fetch your JAR-file from the downloaded JAR-file (if JWS already downloaded it, otherwise JWS will download it).
    The contents of the jws-stub.jar would be something
    of the following ;).
    jws-stub.jar
    --> myjar1.jar
    --> myjar2.jar
    org.myjar.MyJarClassloader
    Then based on your user selecting something you
    can decide which JAR-file you want to load, and thus
    which class.
    Hope this helped,
    Manfred.

  • Loading jar files at execution time via URLClassLoader

    Hello�All,
    I'm�making�a�Java�SQL�Client.�I�have�practicaly�all�basic�work�done,�now�I'm�trying�to�improve�it.
    One�thing�I�want�it�to�do�is�to�allow�the�user�to�specify�new�drivers�and�to�use�them�to�make�new�connections.�To�do�this�I�have�this�class:�
    public�class�DriverFinder�extends�URLClassLoader{
    ����private�JarFile�jarFile�=�null;
    ����
    ����private�Vector�drivers�=�new�Vector();
    ����
    ����public�DriverFinder(String�jarName)�throws�Exception{
    ��������super(new�URL[]{�new�URL("jar",�"",�"file:"�+�new�File(jarName).getAbsolutePath()�+"!/")�},�ClassLoader.getSystemClassLoader());
    ��������jarFile�=�new�JarFile(new�File(jarName));
    ��������
    ��������/*
    ��������System.out.println("-->"�+�System.getProperty("java.class.path"));
    ��������System.setProperty("java.class.path",�System.getProperty("java.class.path")+File.pathSeparator+jarName);
    ��������System.out.println("-->"�+�System.getProperty("java.class.path"));
    ��������*/
    ��������
    ��������Enumeration�enumeration�=�jarFile.entries();
    ��������while(enumeration.hasMoreElements()){
    ������������String�className�=�((ZipEntry)enumeration.nextElement()).getName();
    ������������if(className.endsWith(".class")){
    ����������������className�=�className.substring(0,�className.length()-6);
    ����������������if(className.indexOf("Driver")!=-1)System.out.println(className);
    ����������������
    ����������������try{
    ��������������������Class�classe�=�loadClass(className,�true);
    ��������������������Class[]�interfaces�=�classe.getInterfaces();
    ��������������������for(int�i=0;�i<interfaces.length;�i++){
    ������������������������if(interfaces.getName().equals("java.sql.Driver")){
    ����������������������������drivers.add(classe);
    ������������������������}
    ��������������������}
    ��������������������Class�superclasse�=�classe.getSuperclass();
    ��������������������interfaces�=�superclasse.getInterfaces();
    ��������������������for(int�i=0;�i<interfaces.length;�i++){
    ������������������������if(interfaces[i].getName().equals("java.sql.Driver")){
    ����������������������������drivers.add(classe);
    ������������������������}
    ��������������������}
    ����������������}catch(NoClassDefFoundError�e){
    ����������������}catch(Exception�e){}
    ������������}
    ��������}
    ����}
    ����
    ����public�Enumeration�getDrivers(){
    ��������return�drivers.elements();
    ����}
    ����
    ����public�String�getJarFileName(){
    ��������return�jarFile.getName();
    ����}
    ����
    ����public�static�void�main(String[]�args)�throws�Exception{
    ��������DriverFinder�df�=�new�DriverFinder("D:/Classes/db2java.zip");
    ��������System.out.println("jar:�"�+�df.getJarFileName());
    ��������Enumeration�enumeration�=�df.getDrivers();
    ��������while(enumeration.hasMoreElements()){
    ������������Class�classe�=�(Class)enumeration.nextElement();
    ������������System.out.println(classe.getName());
    ��������}
    ����}
    It�loads�a�jar�and�searches�it�looking�for�drivers�(classes�implementing�directly�or�indirectly�interface�java.sql.Driver)�At�the�end�of�the�execution�I�have�found�all�drivers�in�the�jar�file.
    The�main�application�loads�jar�files�from�an�XML�file�and�instantiates�one�DriverFinder�for�each�jar�file.�The�problem�is�at�execution�time,�it�finds�the�drivers�and�i�think�loads�it�by�issuing�this�statement�(Class�classe�=�loadClass(className,�true);),�but�what�i�think�is�not�what�is�happening...�the�execution�of�my�code�throws�this�exception
    java.lang.ClassNotFoundException:�com.ibm.as400.access.AS400JDBCDriver
    ��������at�java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    ��������at�java.security.AccessController.doPrivileged(Native�Method)
    ��������at�java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    ��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    ��������at�sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    ��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    ��������at�java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    ��������at�java.lang.Class.forName0(Native�Method)
    ��������at�java.lang.Class.forName(Class.java:140)
    ��������at�com.marmots.database.DB.<init>(DB.java:44)
    ��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
    ��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
    ��������at�com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
    ��������at�com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
    Driver�file�is�not�in�the�classpath�!!!�
    I�have�tried�also�(as�you�can�see�in�comented�lines)�to�update�System�property�java.class.path�by�adding�the�path�to�the�jar�but�neither...
    I'm�sure�I'm�making�a/some�mistake/s...�can�you�help�me?
    Thanks�in�advice,
    (if�there�is�some�incorrect�word�or�expression�excuse�me)

    Sorry i have tried to format the code, but it has changed   to �... sorry read this one...
    Hello All,
    I'm making a Java SQL Client. I have practicaly all basic work done, now I'm trying to improve it.
    One thing I want it to do is to allow the user to specify new drivers and to use them to make new connections. To do this I have this class:
    public class DriverFinder extends URLClassLoader{
    private JarFile jarFile = null;
    private Vector drivers = new Vector();
    public DriverFinder(String jarName) throws Exception{
    super(new URL[]{ new URL("jar", "", "file:" + new File(jarName).getAbsolutePath() +"!/") }, ClassLoader.getSystemClassLoader());
    jarFile = new JarFile(new File(jarName));
    System.out.println("-->" + System.getProperty("java.class.path"));
    System.setProperty("java.class.path", System.getProperty("java.class.path")+File.pathSeparator+jarName);
    System.out.println("-->" + System.getProperty("java.class.path"));
    Enumeration enumeration = jarFile.entries();
    while(enumeration.hasMoreElements()){
    String className = ((ZipEntry)enumeration.nextElement()).getName();
    if(className.endsWith(".class")){
    className = className.substring(0, className.length()-6);
    if(className.indexOf("Driver")!=-1)System.out.println(className);
    try{
    Class classe = loadClass(className, true);
    Class[] interfaces = classe.getInterfaces();
    for(int i=0; i<interfaces.length; i++){
    if(interfaces.getName().equals("java.sql.Driver")){
    drivers.add(classe);
    Class superclasse = classe.getSuperclass();
    interfaces = superclasse.getInterfaces();
    for(int i=0; i<interfaces.length; i++){
    if(interfaces[i].getName().equals("java.sql.Driver")){
    drivers.add(classe);
    }catch(NoClassDefFoundError e){
    }catch(Exception e){}
    public Enumeration getDrivers(){
    return drivers.elements();
    public String getJarFileName(){
    return jarFile.getName();
    public static void main(String[] args) throws Exception{
    DriverFinder df = new DriverFinder("D:/Classes/db2java.zip");
    System.out.println("jar: " + df.getJarFileName());
    Enumeration enumeration = df.getDrivers();
    while(enumeration.hasMoreElements()){
    Class classe = (Class)enumeration.nextElement();
    System.out.println(classe.getName());
    It loads a jar and searches it looking for drivers (classes implementing directly or indirectly interface java.sql.Driver) At the end of the execution I have found all drivers in the jar file.
    The main application loads jar files from an XML file and instantiates one DriverFinder for each jar file. The problem is at execution time, it finds the drivers and i think loads it by issuing this statement (Class classe = loadClass(className, true);), but what i think is not what is happening... the execution of my code throws this exception
    java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:140)
    at com.marmots.database.DB.<init>(DB.java:44)
    at com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
    at com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
    at com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
    at com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
    Driver file is not in the classpath !!!
    I have tried also (as you can see in comented lines) to update System property java.class.path by adding the path to the jar but neither...
    I'm sure I'm making a/some mistake/s... can you help me?
    Thanks in advice,
    (if there is some incorrect word or expression excuse me)

  • How to dynamically load jar files - limiting scope to that thread

    Dynamically loading jar files has been discussed a lot. I have read a quite a few posts, articles, and demo code for doing just that. However, I have yet to find a solution to my problem. Most people modify their system class loader and are happy. I have done that and was happy for a time. Occasionally, you will see reference to an application server or tomcat or some other large project that have successfully been able to load and unload jar files, allow for dynamic deployment of code, etc. However, I have not been able to achieve similar success; And my problem is much less complicated.
    I have an application that executes a thread to send a given file/message to a standard JMS Server Queue. Depending on the parameters selected by the user, this thread may need to communicate with one of a number of JMS Servers, ie. JBoss, WebLogic, EAServer, Glassfish, etc. All of which can be done with the same code, but each needs to load their own flavor of JMS Client Jar files. In this instance, spawning a separate JVM for each communication would work from a classloader perspective. However, I need to keep it in the family and run under the same JVM, albeit each JMS Server Connection will be created and maintained in separate Threads.
    I am close, I am doing the following...
    1. Creating a new URLClassLoader in the run() method of each thread.
    2. Set this threads contextClassLoader to the new URLClassLoader.
    3. Load the javax.jms.JMSException class with the URLClassLoader.loadClass() method.
    4. Create an initialContext object within this thread.
    Note: I read that the initialContext and subsequent conext lookup calls would use the Thread�s
    contextClassLoader for finding/loading classes.
    5. Perform context.lookup calls for a connectionFactory and Queue name.
    6. Create JMS Connection, etc. Send Message.
    Most of this seems to work. However, I am still getting a NoClassDefFoundError exception for the javax.jms.JMSException class ( Note step #3 - tried to cure unsuccessfully).
    If I include one of the JMS Client jar files ( ie wljmsclient.jar for weblogic ) in the classpath then it works for all the different JMS Servers, but I do not have confidence that each of the providers implemented these classes that now resolve the same way. It may work for now, but, I believe I am just lucky.
    Can anyone shine some light on this for me and all the others who have wanted to dynamically load classes/jar files on a per Thread basis?

    Thanks to everyone - I got it working!
    First, BenSchulz' s dumpClassLoader() method helped me to visualize the classLoader hierarchy. I am still not completely sure I understand why my initial class was always found by the systemClassLoader, but knowning that - was the step I needed to find the solution.
    Second, kdgregory suggested that I use a "glue class". I thought that I already was using a "glue class" because I did not have any JMSClient specific classes exposed to the rest of the application. They were all handled by my QueueAdmin class. However...
    The real problem turned out to be that my two isolating classes (the parent "MessageSender", and the child "QueueAdmin") were contained within the same jar file that was included in the classpath. This meant that no matter what I did the classes were loaded by the systemClassLoader. Isolating them in classes was just the first step. I had to remove them from my jar file and create another jar file just for those JMSClient specific classes. Then this jar file was only included int custom classLoader that I created when I wanted to instantiate a JMSClient session.
    I had to create an interface in the primary jar file that could be loaded by the systemClassLoader to provide the stubs for the individual methods that I needed to call in the MessageSender/QueueAdmin Classes. These JMSClient specific classes had to implement the interface so as to provide a relationship between the systemClassLoader classes and the custom classLoader classes.
    Finally, when I loaded and instantiated the JMSClient specific classes with the custom classLoader I had to cast them to the interface class in order to make the method calls necessary to send the messages to the individual JMS Servers.
    psuedu code/concept ....
    Primary Jar File   -  Included in ClassPath                                                      
    Class<?> cls = ClassLoader.loadClass( "JMSClient.MessageSender" )
    JMSClientInterface jmsClient = (JMSClientInterface) cls.newInstance()                            
    jmsClient.sendMessage()                                                                      
    JMSClient Jar File  -  Loaded by Custom ClassLoader Only
    MessageSender impliments Primary.JMSClientInterface{
        sendMessage() {
            Class<?> cls=ClassLoader.loadClass( "JMSClient.QueueAdmin" )
            QueueAdmin queueAdmin=(QueueAdmin) cls.newInstance()
            queueAdmin.JMSClientSpecificMethod()
        }

  • How to load jar files from remote location

    Hi all,
    I am trying to load jar files from remote server, from a servlet which is running on OC4j.
    For doing this,First I am getting ClassLoader by using ClassLoader.getSystemClassLoader() and then type casting it to URLClassLoader.
    But by doing it I am getting ClassCastException,because oc4j returns oracle.classloader.PolicyClassLoader instead of java.net.ClassLoader.
    Appreciate if anyone can tell me how to load remote jar files using oracle.classloader.PolicyClassLoader .
    Thanks
    Harish

    Hi,
    I suppose you know about this, but just in case.
    I have used jnpl to load jar files from remote location.
    Rowan

  • Problem :  Native Library already loaded in another classloader

    I created a shared library HaspKeyAPI.dll by using JNI and add path to Java class library. I need to call native functions in my servletAction class to check some information in a key. Sometimes not always, I met �java.lang.UnsatisfiedLinkError: Native Library C:\eclipse\workspace\HaspKey\SharedLib\HaspKeyAPI.dll already loaded in another classloader� problem. I have to restart tomcat server then to restart my web app.
    Does anyone know how to fix it?
    Thank you in advance!
    ////////////////////////////////////my native function class, a singleton class////////////////////////////////
    package haspkey.api;
    import java.util.Collection;
    import java.util.Vector;
    import haspkey.HardwareSecurityKey;
    Public class HaspKeyAPI {
    Public static final int KEYEXIST = 1;
    //A Singleton Class
    private static HaspKeyAPI haspKeyAPI;
    private HaspKeyAPI()
    public static HaspKeyAPI getSingletonObject()
    if ( haspKeyAPI== null)
    haspKeyAPI = new HaspKeyAPI();          
    return haspKeyAPI;
    public Object clone()
         throws CloneNotSupportedException
    throw new CloneNotSupportedException();
    /**********use native functions to call hasp C API***********/
    public native int keyPresent(int password1, int password2);
    public native int getId(int password1, int password2);
    public native void readBlock(int startMemoryLocation, int size,
    byte[] block, int password1, int password2);
    public native void writeBlock(int startMemoryLocation,int size, byte[] block, int password1,
    int password2);
    public native boolean decodeData(int size, byte[] block, int password1,
    int password2);
    public native boolean encodeData(int size, byte[] block, int password1,
    int password2);
    static {
    System.loadLibrary("HaspKeyAPI");
    private int getPrivMachineSpeed(boolean decrypt, int pass1, int pass2, String MLOCRTypeCode){
    byte[] block = new byte[8];
    int privMachineSpeed = 0;
    boolean isNumeric = true;;
    readKeyMemory(40,8,block, decrypt, pass1, pass2);
    if(block.length!=8){
    return -1;
    }else{
    String s = new String(block);
    for(int n=0; n<3; n++){
    if(s.charAt(n)<48 || s.charAt(n)>57){
    isNumeric = false;
    if(isNumeric){
    privMachineSpeed = Integer.parseInt(s.substring(0,3));
    return privMachineSpeed;
    public HardwareSecurityKey getHardwareSecurityKey(boolean decrypt, int pass1, int pass2, String AuthorizationCodes,String MLOCRTypeCode){
    HardwareSecurityKey key = new HardwareSecurityKey();
    if(keyPresent(pass1,pass2)==KEYEXIST){
    key.setPrivKeyID(getId(pass1, pass2));
    key.setPrivMachineSpeed(getPrivMachineSpeed(true, pass1,pass2, MLOCRTypeCode));
    }else{
    return null;
    /////////////////////////////// a class include some static final information to call the native function///////////////
    import com.bowebellhowell.haspkey.api.HaspKeyAPI;
    import com.bowebellhowell.winsort.vo.haspkey.HardwareSecurityKey;
    public class HaspKey{
    public static final String MLOCRTypeCode ="mmmmmmmmmmmmmmm";
    public static final String AuthorizationCodes = "bbbbbbbbbbbbbbbb";
    public static final int p1 = 0;
    public static final int p2 = 0;
    public static HardwareSecurityKey getHardwareSecurityKey(){
    HaspKeyAPI key = HaspKeyAPI.getSingletonObject();
    return key.getHardwareSecurityKey(true,p1,p2,AuthorizationCodes,MLOCRTypeCode);
    /////////////////////////////////// a servlet to call native function///////////////////////////////////
    public class LogonAction extends Action {
         public ActionForward execute(
              ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response)
              throws Exception {
              int n = HaspKey.isKeyPresent();
              if(n!=1){
              if(n==2){
              message = "KeyDriverNotMatch";          
              }else if(n==3){
              message = "KeyOldModel";
              }else if(n==4){
              message = "KeyPasswordNotMatch";
              }else if(n==-1){
              message = "keyNotExist";
              request.getSession().setAttribute("message",message);
    java.lang.UnsatisfiedLinkError: Native Library C:\eclipse\workspace\HaspKey\SharedLib\HaspKeyAPI.dll already loaded in another classloader
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1551)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at haspkey.api.HaspKeyAPI.<clinit>(HaspKeyAPI.java:76)
    at util.HaspKey.isKeyPresent(HaspKey.java:35)
    at LogonAction (LogonAction .java:65)

    Hi EveryBody:
    i working in 2 servlets, these servlets import a login.jar library and login.jar call to Login.dll (a native Library)
    then. when i start second servlet i have this message
    java.lang.UnsatisfiedLinkError: Native Library dllLogin.dll already loaded in another classloader
    i read about class loader and i know about a only one load for native library but i don't know how resolve this exception because both servlets need dllLogin.dll to validate the user
    please anybody knows how or have any idea?
    Kind Regards
    Edson
    --sorry i know. my english is very bad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • UnsatisfiedLinkError ... ntvinv.dll already loaded in another classloader

    Hi,
    I'm trying to run a program using JCOM from the command line. My program is a
    test runner which spawns a number of users in separate threads and runs a sequence
    of requests. For every new user, the constructor which initializes the jcom proxy
    object (IWlsTrigWrapProxy below) is called. Running the test with one user works
    fine. In a multiple user test, the first user is successful, but when subsequent
    users try to initialize I get the following message:
    -----------------------8<---------------------------
    BEA WebLogic 6.1 license found...
    java.lang.UnsatisfiedLinkError: Native Library C:\bea\wlserver6.1\jcom\bin\ntvinv.dll
    already loaded in another classloader
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1346)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
    at java.lang.Runtime.loadLibrary0(Runtime.java:749)
    at java.lang.System.loadLibrary(System.java:820)
    at com.bea.jcom.NativeObjRef.r(NativeObjRef.java)
    at com.bea.jcom.Dispatch.a(Dispatch.java)
    at com.bea.jcom.Dispatch.isNativeMode(Dispatch.java)
    at com.bea.jcom.Dispatch.createDispatch(Dispatch.java)
    at com.bea.jcom.Dispatch.<init>(Dispatch.java)
    at xx.xxx.IWlsTrigWrapProxy.<init>(IWlsTrigWrapProxy.java:49)
    at .......................
    [ stuff deleted ]
    -----------------------8<---------------------------
    Is there an obvious reason for this? What can be done about it?
    Best regards,
    Lars Cronsioe

    Hi Cronsioe,
    I encountered the same error as you mentioned here when trying to access the COM
    object using jcom.
    The message I am getting is
    UnsatisfiiedLinkError:getNegociateMessage()
    I have put the jcom\bin in the path variable and the jcom.jar in the system classpath.
    I have even sepcified the path for jcom\bin\ntvauth.dll in path variable.
    Did you get any solution to your problem. If so please let me know. I appreciate
    your responses.
    Quraishi
    "Lars Cronsioe" <[email protected]> wrote:
    >
    Clarifying my question from yesterday, I would like to add the following:
    From the JCom Reference Guide, chapter 8, first section "From Java to
    COM", it
    seems that "The WebLogic jCOM runtime DCOM engine will allow multiple
    simultaneous
    requests to the same COM object". However, since nothing is said about
    the native
    mode, I draw the conclusion that simultaneous requests to the same COM
    object
    are not supported. Is this correct? What can I do about it?
    Regards
    Lars Cronsioe again

  • Libdb_java46.dll already loaded in another classloader

    I'm trying to use DB XML in a servlet with Tomcat 5.5. In the init() method, I open a container and in destroy(), I do the cleanup.
    The problem is that if I recompile my code and let Tomcat reload the webapp, I get the following error:
    "java.lang.UnsatisfiedLinkError: Native Library libdb_java46.dll already loaded in another classloader"
    I'm using Java 1.5.
    Is there a way to get around this error? it is very annoying in development mode to stop and restart Tomcat each time I make a modification.
    Thanks.

    hi
    try with putting db.jar and dblxml.jar into
    $CATALINA_HOME/common/lib
    more to read about classloading at following url
    http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
    yurss rober

  • Usr/lib/mps/sercv1/libjss3.so already loaded in another classloader.

    I�ve got the followindg error when i use the sun one applicationserver 7.
    /usr/lib/mps/sercv1/libjss3.so already loaded in another classloader.
    What can i do to solve the problem?

    Hello
    I had that problem more than 3 months ago on 10.1.3 DP4 "Native library already loaded in an other class loader". and I come back now, as one of my customer meets that problem himself with OC4J 10.1.3.00!
    My question is the following: what sort of advices could you give, in OC4J consiguration, if one have two components run by OC4J run the same classes from the same jar file, which in turn loads a native shared library ?
    Is there a way of declaring this shared library so that it is loaded only once ?
    Thank you very much in advance, help very much appreciated!
    Paul Barnes

  • Java Connector. "sapjcorfc.dll already loaded in another classloader"

    Dear all:
    I'm fighting against a Java Connector problem.
    I'm using:
    -JCO version 2.16
    -Apache Tomcat 5.5.17
    I have written the environment variables:
    CLASSPATH pointing where I have sapjco.jar, sapjcorfc.dll
    Path where i have sapjco.jar, sapjcorfc.dll.
    I try to make a webservice which calls a RFC function in SAP.
    Java program compiles and Deploy OK.
    I load the web service in Tomcat.
    When I call the java server page, I get this error message from Tomcat:
    org.apache.jasper.JasperException: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
    JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc Native Library C:\Traspas\Projecte\lib\sapjcorfc.dll already loaded in another classloader. java.library.path C:\Tomcat5.5.17\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Java\jdk1.5.0_07\bin;C:\Traspas\Projecte\lib
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    Seems that is trying to load twice sapjcorfc.dll?
    I would be grateful if someone can give me help.
    Thanks in advance.
    Jordi

    I received a message asking for further clarification. I try to further explain.
    Be sure sapjco.jar is not included in the application. Doing so will lead the system to load more than one time the SAP Java Connector. Sapjco.jar has to be loaded only once in the server.
    To do so (in Windows & Tomcat environment):
    1-Be sure sapjco.jar is not included in the WEB-INF folder.
    2-Put sapjcorfc.dll and librfc32.dll in c:Windowssystem32
    3-Put sapjco.jar in c:Tomcatcommonlib
    4-Add a reference to sapjco.jar in the project (In Eclipse: Project/Properties/Java Build Path, Tab Libraries, Add External JARs.
    5-Compile and deploy the application. Generate War file. If ant gives problems, add proper command to find sapjco.jar (section <path id=u201Dpath.baseu201D>, <include name=u201Dsapjco.jaru201D>)
    6-Load the WAR file in Tomcat.
    7-Stop and Start Tomcat.
    8-Run the application.
    A related thread: [SAP J2EE engine problem|SAP J2EE engine problem]
    Hope this helps.

  • Bonjour java already loaded in another classloader error

    I'm using the java bonjour library (dns_sd.jar) in a web application running in Jboss web server.
    When I start the server a Servlet finds every resource on the network with bonjour and returns to the user. The first time everything runs great but when I redeploy the web app I get:
    java.lang.UnsatisfiedLinkError: Native Library C:\Windows\System32\jdns_sd.dll already loaded in another classloader
    I already tried deletting the .dll and the samething happens.
    Why does it even refer the .dll if I have the .jar lib in my web app?
    Does anyone have any idea on how to fix this?

    marcosRoriz wrote:
    But I can't use another instance of IXCRegistry?You understand that you have two class loaders right?
    The shared library is loaded by the OS into the application. There can be only one.
    The VM wants to associate that single shared library with the class loader that loaded it.
    One solution is to have a class loader for just that class. Note that the OS, not the VM, will not let you have two instances of the shared library so it is generally pointless (in terms of class loaders) to have more than one.

  • How to load jar file in oracle 9i???

    Hi Friends,
    Can you help me, how to load jar file oracle 9i? I have to tried to load in 10g using loadjava command but it's not working in oracle 9i because the loadjava batch file itself is not there in oralce 9i.
    Is there any other way then pls let me know.
    - Hiren Modi

    Hi,
    I have oracle version : Release 2 (9.2.0.1.0) for Windows. I have tried to execute the loadjava command from SQL prompt but its giving as below.
    H:\>loadjava
    The system cannot find the path specified.
    Do you know why its giving error like this. I have checked in dir : C:\oracle\ora92\bin but loadjava executable file is not there in it.
    - Hiren Modi

  • Load jar file into Oracle db 10.1.0.2.0.

    Hi,
    I am trying to create a Java Stored procedure that is dependent on some other classes. The java source doesn't compile since it cannot find the imported libs.
    How can I load jar files into the database so I can get my java source to compile?
    I have heard of dbms_java.loadjava procedure, but not very clear on how to use it.
    Please let me know how I can load the jar files in to the db.
    Thanks,
    -- DR.

    http://oraclesvca2.oracle.com/docs/cd/B12037_01/java.101/b12021/dbms_jav.htm

  • Error: native library oljdbc40.dll already loaded in another classloader

    Hi, we're using Oracle 8iLite in combination with Tomcat (on WinNT4.0) to run servlets accessing our OLite db. We use a deployed db (Deployment tool: PolUtil.exe) and pure JDBC connections.
    When starting tomcat, the servlet is automatically initialized (exactly once!). It comes to the point, where a database connection is to be established. At this point, we get the following error message:
    Native Library E:\MyServer\DB\BIN\oljdbc40.dll already loaded in another classloader
    The strange thing is, that this error only occurs on some machines. There are no other java apps running.
    Where does this error come from, and how can someone avoid this seemingly arbitrary error?
    Thanks in advance for your time, Holger
    null

    You are having some problems with that Oracle Driver and Orion.
    Do you have any JSP at your Installation that work with Oracle?
    Orion needs to know where that Diver is located is that Driver in
    some package that is in Orion's Class Path?

Maybe you are looking for