Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Load C++ Library Only Once

Load C++ Library Only Once

Scheduled Pinned Locked Moved Java
c++questionjavaapache
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Django_Untaken
    wrote on last edited by
    #1

    Hello there. I have managed to load and use c++ dll using JNI, in my java servlet (System.load). It works perfectly on first request I submit. But on subsequent requests, I get this weir d exception. java.lang.UnsatisfiedLinkError: Native Library WEB-INF/lib/XXXXXX.dll already loaded in another classloader at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1525) Here is my loading code

    public void init(ServletConfig config) throws ServletException
    {
    super.init(config);
    ServletContext context = getServletContext();
    String sMathDllpath = context.getInitParameter("MathDLLPath");
    System.load(sMathDllpath);

    }

    I studied this tomcat wiki link and implemented their solution, among others, but could not succeed. How do I implement it successfully? Thnks for anything you share.

    L 1 Reply Last reply
    0
    • D Django_Untaken

      Hello there. I have managed to load and use c++ dll using JNI, in my java servlet (System.load). It works perfectly on first request I submit. But on subsequent requests, I get this weir d exception. java.lang.UnsatisfiedLinkError: Native Library WEB-INF/lib/XXXXXX.dll already loaded in another classloader at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1525) Here is my loading code

      public void init(ServletConfig config) throws ServletException
      {
      super.init(config);
      ServletContext context = getServletContext();
      String sMathDllpath = context.getInitParameter("MathDLLPath");
      System.load(sMathDllpath);

      }

      I studied this tomcat wiki link and implemented their solution, among others, but could not succeed. How do I implement it successfully? Thnks for anything you share.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should declare it as a static action at class level like:

      class ... {
      static
      {
      System.loadLibrary("MathDLLPath");
      }
      // remainder of your class
      }

      That will ensure it is loaded when the class is first instantiated, but will only be loaded once.

      D 1 Reply Last reply
      0
      • L Lost User

        You should declare it as a static action at class level like:

        class ... {
        static
        {
        System.loadLibrary("MathDLLPath");
        }
        // remainder of your class
        }

        That will ensure it is loaded when the class is first instantiated, but will only be loaded once.

        D Offline
        D Offline
        Django_Untaken
        wrote on last edited by
        #3

        Richard MacCutchan wrote:

        You should declare it as a static action at class level like:

        I tried this just now. This is what I have

        public class MainServlet extends HttpServlet
        {
        static{
        System.loadLibrary("MathDll");
        }

        ......... // rest of the class below this
        }

        And this is the exception I am getting java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\Java\jdk1.7.0_71\bin\MathDll.dll already loaded in another classloader What am I doing wrong now?

        L 1 Reply Last reply
        0
        • D Django_Untaken

          Richard MacCutchan wrote:

          You should declare it as a static action at class level like:

          I tried this just now. This is what I have

          public class MainServlet extends HttpServlet
          {
          static{
          System.loadLibrary("MathDll");
          }

          ......... // rest of the class below this
          }

          And this is the exception I am getting java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\Java\jdk1.7.0_71\bin\MathDll.dll already loaded in another classloader What am I doing wrong now?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          No idea, but it looks like you may have more than one call somewhere. Time to get the debugger out. Although, I have never used JNI in a servlet so it may be that there is something else happening.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups