2

I'm new in JavaAgent concept, so maybe this issue isn't complicated. But I hope some discussion and knowledge arrangement will be helpful (not only for me).

So - what I want to do? I would like to load external jar library when I start my application. This external library is under development and versioned on ARM (Nexus) and contains functionalities which are essential in my_app.

My attempt:

  1. Download wanted version of lib (no problem here - got proper func_version.jar in right place)

  2. I add in parent dir of downloaded jar class JavaAgent.java:

    import java.lang.instrument.*;
    
    public class JavaAgent {  
        private static Instrumentation inst;  
    
        public static Instrumentation getInstrumentation() { return inst; }  
    
        public static void premain(String agentArgs, Instrumentation inst) {  
            System.out.println(inst.getClass() + ": " + inst);  
            System.out.println("JavaAgent LOADED!");
            JavaAgent.inst = inst;  
        }  
    }  
    
  3. Modify META-INF/MANIFEST.MF in lib (added line: Premain-Class: JavaAgent)

  4. Try to load JavaAgent by passing it as JVM parameter:

    java -javaagent:/home/func_1.0.1.jar /home/my_app/MyStartup
    

MyStartup.java contains main method for my_app.

I know this steps are not enough (can't see any result yet). But is it a right approach? And what else do I need to do to see wanted "JavaAgent LOADED!" on console output? Some work with Java ClassLoader is needed?

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
oundru87
  • 43
  • 1
  • 8
  • Your java invocation looks wrong (should be something like `java -javaagent:/home/func_1.0.1.jar -cp . MainClass`). What error are you seing? – Brett Kail Mar 22 '14 at 16:18

0 Answers0