jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
465 stars 240 forks source link

JMOCKIT with OpenJDK issue: com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute #114

Closed yourganesan closed 9 years ago

yourganesan commented 9 years ago

Hi I am getting the below error when starting my server with jmockit-1.9.jar in classpath. Any idea how to resolve this? I am using junit-4.5.jar, testng-6.7.jar and jmockit-1.9.jar. and I have ensure that jmockit jar appears before the junit and testng in the classpath

^[[0m^[[31m14:35:58,932 ERROR stderr java.lang.RuntimeException: com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute ^[[0m^[[31m14:35:58,933 ERROR stderr at mockit.internal.startup.AgentLoader.loadAgentAndDetachFromThisVM(AgentLoader.java:115

yourganesan commented 9 years ago

More to the story... the issue happens only when the server is built/deployed/started using openjdk.. and works with oracle jdks.. any quick help will be greatly appreciated.. Here is some more stack trace..

java.lang.RuntimeException: com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute 19:09:42,185 ERROR stderr at mockit.internal.startup.AgentLoader.loadAgentAndDetachFromThisVM(AgentLoader.java:115) 19:09:42,186 ERROR stderr at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:54) 19:09:42,186 ERROR stderr at mockit.internal.startup.AgentInitialization.loadAgentFromLocalJarFile(AgentInitialization.java:27) 19:09:42,186 ERROR stderr at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:252) 19:09:42,186 ERROR stderr at mockit.integration.testng.Initializer.(Initializer.java:29) 19:09:42,187 ERROR stderr at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 19:09:42,187 ERROR stderr at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 19:09:42,187 ERROR stderr at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 19:09:42,188 ERROR stderr at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 19:09:42,188 ERROR stderr at java.lang.Class.newInstance(Class.java:374) 19:09:42,188 ERROR stderr at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373) 19:09:42,188 ERROR stderr at java.util.ServiceLoader$1.next(ServiceLoader.java:445) 19:09:42,189 ERROR stderr at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:955) 19:09:42,189 ERROR stderr at org.testng.TestNG.initializeConfiguration(TestNG.java:890) 19:09:42,189 ERROR stderr at org.testng.TestNG.run(TestNG.java:1004) 19:09:42,189 ERROR stderr at org.testng.TestNG$run.call(Unknown Source) 19:09:42,190 ERROR stderr at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 19:09:42,190 ERROR stderr at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) 19:09:42,190 ERROR stderr at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)

rliesenfeld commented 9 years ago

If the JRE from OpenJDK does not support dynamic agent loading (which is normally done by JMockit), then you will have to start the JVM with the "-javaagent:/jmockit.jar" initialization parameter (substitute "jmockit-1.9.jar" if needed).

yourganesan commented 9 years ago

Hi Thanks for the reply, In our project, adding the jmockit as an agent is not an option. and i am helpless.. can you kindly help me any other alternative way?

FYI.. you can have a look at the below thread which discusses the same issue when using jmockit with open jdk.. Though the context is different, if you read all the comments completely, then we can detect that the jmockit does not initialize well in open jdk context.. A solution (other than adding it as agent) is needed in time. please help me..

https://groups.google.com/forum/#!topic/java-pathfinder/i5c62gMkk5o

rliesenfeld commented 9 years ago

Ok. I see no useful info in that thread, though.

What I need to know is the following: 1) What is the version of OpenJDK being used? For which OS? 2) Where does the OpenJDK binaries come from? Some site with downloadable binaries, or did you build it yourself? 3) Does the "jre/bin" directory in the OpenJDK installation contain the "attach" native library file?

yourganesan commented 9 years ago

Thanks for reopening this. Here is the requested information 1) What is the version of OpenJDK being used? For which OS? - OpenJDK7-45 and RHEL 6.5 2) Where does the OpenJDK binaries come from? Some site with downloadable binaries, or did you built it yourself? - We installed openjdk as mentioned here http://openjdk.java.net/install/index.html 3) Does the "jre/bin" directory in the OpenJDK installation contain the "attach" native library file? - No, but it has /jre/lib/amd64/libattach.so file. Does this information help?

Thanks for the support and appreciate your quick response in resolving this issue.

rliesenfeld commented 9 years ago

I suspect your JRE does not contain the attach library (if it did, should be "jre/bin/attach.so", not "jre/lib/libattach.so"). In the "OpenJDK: Download and install" page, it says: "The java-1.7.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.7.0-openjdk-devel package."

Plain JREs indeed do not contain the Attach API library; you need the JRE from a JDK. So, the likely solution here is to use the "java-1.7.0-openjdk-devel" package.

yourganesan commented 9 years ago

Hi we have used java-1.7.0-openjdk-devel" package only and still there is no attach.so under jre/bin directory.. let me know if you need any more information.

rliesenfeld commented 9 years ago

Nothing more I can do, I am afraid, as I don't currently have a Linux system available for testing.

yourganesan commented 9 years ago

Hi, i can test it with my linux system if that is what is stopping now. is it okay?

rliesenfeld commented 9 years ago

Sure, you can test it. What I would do is to run a single test using the mocking API, with a breakpoint on the first line containing a "new Expectations() ..." statement or similar; then step through the initialization methods in class mockit.internal.Startup etc.