Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:26:56+00:00 2026-06-11T02:26:56+00:00

I have a small application that uses the Attach API to modify some third

  • 0

I have a small application that uses the Attach API to modify some third party classes during runtime. Alas, I have run into a large problem: the Attach API only comes with the JDK. The necessary files I can copy from the JDK and add into my project, but the library responsible for this(attach.(dll|so)) I can’t. This is because I would have to copy attach.lib from a resource inside jar, and put it in the JRE/lib directory.

An action that would not work if the user isn’t root on a Linux machine, therefore losing compatibility to alot of users (as this app is supposed to run on a server, and most servers are Linux, and I can’t be sure all are root)

I looked into all the classes responsible for the attach API (VirtualMachine, AttachProvider etc) but found no place where it is loading the library.

Is it possible to do this? I mean, can I use the Attach API outside of a JDK installation? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:26:57+00:00Added an answer on June 11, 2026 at 2:26 am

    You can do so by modifying java.library.path:

    static void addToLibPath(String path) throws NoSuchFieldException,
                                                 SecurityException,
                                                 IllegalArgumentException,
                                                 IllegalAccessException
    {
        if (System.getProperty("java.library.path") != null) {
            // If java.library.path is not empty, we will prepend our path
            // Note that path.separator is ; on Windows and : on Unix-like,
            // so we can't hard code it.
            System.setProperty("java.library.path",
                               path + System.getProperty("path.separator")
                               + System.getProperty("java.library.path"));
        } else {
            System.setProperty("java.library.path", path);
        }
    
        // Important: java.library.path is cached
        // We will be using reflection to clear the cache
        Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
        fieldSysPath.setAccessible(true);
        fieldSysPath.set(null, null);
    }
    

    Call addToLibPath("path") will add "path" to java.library.path.

    Please note that java.library.path is cached, and reflection is required to clear the cache.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application that uses the same API as the powerscript examples
I have a small application that uses WCF to communicate with a webserver. This
I have a small application that uses a SharePoint list as the data source.
This is getting me quite confused: I have a small application that uses a
I have a small shell application that embeds Tcl to execute some set of
I have an application that uses the bluetooth to receive some data (bytes) from
I have a small application that uses a DrawingArea to draw a simple map
I have a small application that uses a navigation window and a set of
I have manage to create a small size js application that uses jQuery and
I have a web application that uses jQuery to load some sound effect on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.