2

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 Answer 1

1

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"] 
Sign up to request clarification or add additional context in comments.

3 Comments

That’s nonsense. You can specify the command line option without an environmental variable, to the same result, java -javaagent:/path/myagent.jar -jar myprogram.jar. You can use that instead of the distorted command line posted in your question. It’s not clear which actual problem this Q&A is supposed to solve.
But don't worry i reedited my anwser, for people that can't follow my flow
You should have edited the question instead, so that “people that can't follow your flow” have a chance to understand what actual problem you are trying to solve.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.