Load JavaAgent on JVM

Viewed 310

I have a theoretic question about java Agents. It's posible do a java or openJDK instruction to add a java agent before execute java?

The normally execution of javaagent (i discard runtime execution) is:

java -jar -javaagent myJavaAgent myProgram.jar

But my idea is create a docker container with OpenJDK version and my agent load

PersonalJDK

FROM openjdk:7
RUN java LOAD AGENT // I DONT KNOW THIS INSTRUCTION

the customer use my container with my agent load

FROM personalJDK:7
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", "Main"]
1 Answers

Searching solutions i come with this:

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html

The answer is using _JAVA_OPTIONS, you must include a enviroment variables includes java agent.

PersonalJDK

FROM openjdk:7
COPY . /agent
RUN _JAVA_OPTIONS=-javaagent:/agent/myagent.jar

the customer use my container with my agent load

FROM PersonalJDK
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", -jar, "Main.jar"]
Related