5

I have looked for answers to this problem and tried the only solution to this I could find (jmockit: Native library for Attach API not available in this JRE error)

I tried adding attach.dll to PATH environment variable with no success. (C:\Program Files\Java\jdk1.7.0_60\jre\bin\attach.dll)

any other suggestions?

java.lang.IllegalStateException: Native library for Attach API not available in this JRE
at mockit.internal.startup.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:88)
at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:47)
at mockit.internal.startup.AgentInitialization.loadAgentFromLocalJarFile(AgentInitialization.java:27)
at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:252)
at mockit.integration.junit4.JMockit.<clinit>(JMockit.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.UnsatisfiedLinkError: no attach in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at sun.tools.attach.WindowsVirtualMachine.<clinit>(WindowsVirtualMachine.java:185)
at mockit.internal.startup.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:66)
... 22 more
Community
  • 1
  • 1
SteveK
  • 207
  • 2
  • 6
  • 17
  • 3
    The accepted answer to that question is wrong. There are no environment variables to be set. Instead, you need to run the tests with the complete JRE from a JDK, which contains the "attach" library; a plain JRE (ie, not from a JDK) does not contain such library. – Rogério Jul 21 '14 at 16:40
  • @Rogério Thanks for your reply any chance of a little more detail on how to fix the problem? I understand what your saying just don't how to fix it! – SteveK Jul 22 '14 at 08:38
  • Try to set javaagent. Refer this http://stackoverflow.com/questions/11961571/jmockit-native-library-for-attach-api-not-available-in-this-jre-error. See @sasuke's answer. – वरुण Jul 22 '14 at 14:19
  • 2
    @SteveK I believe [this](http://stackoverflow.com/questions/13635563/setting-jdk-in-eclipse) question should help you. – Rogério Jul 22 '14 at 17:24
  • @Rogério Thanks for your first comment, it did the trick for me! – Alexis Leclerc Sep 02 '14 at 13:59
  • The top answer at worked for me – Trey Jonn Nov 13 '14 at 07:36

1 Answers1

10

You are using jre instead of jdk. Go to Windows->Preferences->Java->Installed JRE's and remove jre and add jdk, also select it as default.

telebog
  • 1,706
  • 5
  • 25
  • 34
  • Better answer than the referred (possible duplicate) question. – L. Holanda Oct 13 '15 at 19:39
  • 1
    This worked for me. The assumption was that Installed JREs would mean that I point to my JRE, but pointing it to the JDK fixed the issue. – kev Nov 03 '15 at 12:07