jmockit: Native library for Attach API not available in this JRE error - jmockit

I was trying to use jmockit to unit test my project and got the following error:
java.lang.UnsatisfiedLinkError: no attach in java.library.path
java.lang.IllegalStateException: Native library for Attach API not available in this JRE
at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:95)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:98)
at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:112)
at org.junit.runner.Runner.<clinit>(Runner.java:22)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
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
I have included jdk6/lib/tools.jar, jmockit.jar, and junit.jar in the classpath, respectively. Any clues why this is happening?

Go to Java Build Path of your project and change the JRE System Library and make it points to the jdk instead of jre.

It's not tools.jar that you need, but the native library file for the "Attach API": attach.dll (or the Linux/Mac equivalent, attach.so or similar). A plain JRE does not contain this library. Instead, point Eclipse to a JDK installation, which should contain the jre/bin/attach.dll file.

Add the path to attach.dll to your PATH environment variable

You have to set agent.
You can set VM arguments if you are using eclipse and Args will be like this:
-javaagent:local path to your jmockit jar\jmockit.jar
eg: -javaagent:D:\jmockit.jar

Dao Lam,
Here are some other things to try:
Make sure your project is using either:
The workspace default (That assumes that the default is your the jdk installation you just added. From the window where you added it, make sure it is checked.),
The jdk version, or
An execution Environment that uses the jdk version.
Pull up your system's environment variables, and add this path to it: (jdk_dir)/jre/bin. (Remember, you'll have to restart Eclipse once you've saved that to get it to take).
Close eclipse, and modify the shortcut you are using to start it to use (jdk_dir)/jre/bin.
I've found that any one of these measures will allow Eclipse to find the attach.dll.

Looks like you need to point your Eclipse to JDK , not JRE.
Steps :Windows->Preferences>Java>"Installed JRE's" and remove JRE from "Installed JRE's" window and add JDK browsing to your JDK location and select as default.

I found this issue with JDK 1.8.45 and 1.8.80 on 64-bit Windows. My solution was to copy attach.dll from the JDK's ./jre/bin directory to the ./bin. This eliminated the need for updating Eclipse and a Cygwin command line with a non-standard JAVA_HOME.
Maybe the Windows version may be ignoring the contents of the JRE directory?

Related

Missing tools.jar when launching STS application

I have the latest STS4. I am using installed java-1.8 JDK not embedded as the execution environment. My project just runs fine without any issue.
However when I launch the STS application itself I have a pop up saying
"Missing tools.jar"
I have already tried:
pointing JAVA_HOME to different JDK
added -vm args in the .ini file.
Yet I cannot get rid of this pop up.
I solved this same problem by modifying the file "eclipse.ini". First I tried to solve it by modifying the file SpringToolSuite4.ini, but nothing happened, because I previusly had installed the eclipse ide, and the change in SpringToolSuite4.ini didn't work. then I modified the file eclipse.ini; and it worked.
The changes that I did in eclipse.ini are detailed below:
To check with what Java version (JRE or JDK) Eclipse is running, do the following:
Open the menu item Help > About Eclipse. (On the Mac, it’s in the Eclipse-menu, not the Help-menu)
Click on Installation Details.
Switch to the tab Configuration
Search for a line that starts with -vm. The line following it shows which Java binary is used.
Depending on the name and location of the used Java binary one can figure out if a JRE or a JDK is used:
If the path contains “jre” (e.g. as in C:\Program Files\Java\jre6\bin\client\jvm.dll) it is a JRE
If the path contains “jdk” (e.g. as in C:\Program Files\Java\jdk1.6.0_31\bin\javaw.exe) it is a JDK.
If no JDK is used for Eclipse, change it:
Quit Eclipse if it is running
Go to the Eclipse installation directory and open the file eclipse.ini in a text editor.
Search for the line -vmargs
Before the line -vmargs, add two lines:
On the first line, write -vm
On the second line, write the path to your JDK installation (usually something like: C:\Program Files\Java\jdk1.6.0_31\bin\javaw.exe on Windows)*
source: https://matsim.org/docs/devguide/eclipse/jdk
The fix is in the -vm parameter. the order and the absolute path of the javaw.exe seems to be the issue.
the readme file mentions _
"To run Eclipse with an alternate Java runtime environment, the path to the Java virtual machine's binary must be identified. With an Eclipse installation from the distribution, altering the $PATH variable to include the path to the alternate Java runtime environment is often not enough as the Eclipse that Linux distributions package often performs a scan internally to pick up GCJ by itself whilst ignoring what's on the $PATH."
So I have edited now the SpringToolSuite4.ini and made this entry
-vm
C:\UserTemp\Softwares\java\jdk\oracle-jdk-1.8-64bit\bin\javaw.exe
Restarted my STS and it works perfect.
The reference to set the JVM Specifying the JVM was very useful in understanding this.
Don't spend too much time looking for tools.jar. If you get an error like that, don't be upset.
If you already have java JDK1.8, go to its lib folder, tools.jar should be available there. Copy and paste the same in JRE1.8 lib folder.
I have STS4 so I have modified SpringToolSuite4.ini
I changed from:
[...]
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.8
[...]
to exactly this
[...]
--launcher.defaultAction
openFile
-vm
C:\Program Files\Java\jdk1.8.0_152\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.8
[...]
And the message dissapeared
SOLUTION :
Check your Path JAVA_HOME - system property "Environment Variables"
for example: JAVA_HOME:
C:\Program Files\Java\jdk-12.0.1\lib
usually you only need add \lib at JAVA_HOME
Just remove this line from variable "Path"
"C:\Program Files (x86)\Common Files\Oracle\Java\javapath"
System Properties > Advanced > Environment Variables > Path > Edit > Reboot
Worked for me
In my case I had installed jre, and not jdk!
Observe that you have jdk installed!
I had the same issue when i upgraded to Java 11.
I simply edited SpringToolSuite4.ini and added
-vm
C:\Program Files\Java\jdk-11.0.4\bin\javaw.exe
For me, I had to do two things to make it work:
Remove vmargs:
vmargs
Dosgi.requiredJavaVersion=1.8
Setting the JDK:
vm
C:\Program Files\Java\jdk1.8.0_131\bin
By downloading the tool file and paste it in the jre\lib path. but make sure you should rename the pasted file as "tools.jar".
step 1
download the tool file.
download link http://www.java2s.com/Code/Jar/t/Downloadtools160jar.htm
step 2
extract the zip file.
step 3
you should rename the included .jar file as "tools".
step 4
then copy the renamed tools.jar file and paste in the C:\Program Files\Java\jre8\lib\ path.
then restart the STS ide.
I have fixed this from Window->preferences->Java->Installed JREs .
Then add the jdk bin path, uncheck other related jre paths
Copy JDK directory to your STS installation or extraction library and and rename JDK to jre. the directory structure of STS should look like this
.eclipseproduct
artifacts.xml
configuration
dropins
eclipsec.exe
features
jre
license.txt
META-INF
open-source-licenses.txt
p2
plugins
readme
SpringToolSuite4.exe
SpringToolSuite4.ini
Once STS open, initially its looking for tools.jar in jre\lib folder its not available in jre\lib folder.
so we need copy the tools.jar from jdk\lib folder and paste in jre\lib folder.
restart the STS, issue will resolve.

IntelliJ shows decompiled .class file instead of source code

I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.
This is what I see:
I am trying to open regular JDK source files.
The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij
The most detailed answer I've found so far is there as well.
Yet it doesn't work for me:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck
src.zip is not corrupt - I can open it via WinRAR
When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.
Everything else works/compiles properly.
My settings:
1. Get the source files
Make sure you have downloaded and installed the source files of the JDK.
I'm on Arch Linux and installed them with pacman -S openjdk8-src which put a src.zip into /usr/lib/jvm/java-8-openjdk/. We'll use that zip file in the next step.
To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src".
See this question on how to get the source files for your specific platform.
2. Point IntelliJ to the source files
In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:
3. Jump into the source
Select a JDK class, like Comparator, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.
I also have the same problem. The problem for my case is that Project SDK is set to 13 [Invalid]. After I can Project SDK to a valid SDK. My problem is solved.
I tried all the things mentioned at other places for this but at the end I was doing a silly mistake. Intellij was pointing to JDK 11 for which there was no source code (I had both the SDKs 8 & 11). I removed JDK 11 and pointed to JDK 8. JDK had the source code, thus now I can see the source code on ctrl click. Also, I had disabled the bytecode viewer and decompiler plugins. Hope this helps some one.
This also happens for large files - IDEA decides to decompile them instead if indexing sources, which can take ages.
If you're willing to accept the drawdown, adding the following in Help | Edit Custom Properties might fix the problem:
idea.max.intellisense.filesize=4096
On ubuntu there was java version “OpenJDK” when I changed to “Oracle Java”, the error went away and javadoc returned
I meet same problem and finally it gone after I copy JDK to another folder and change config in IntelliJ. I think maybe cause there is a space in path before, because it is installed under "Program Files" folder.
For downloading the source code of class files belong to jar you can use download source option present on top right corner in the de-compiled class file.
On my Windows 10, expand maven:
For me going to File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK and selecting Oracle OpenJDK solved the problem. Prior to that I had a different JDK selected and apparently it didn't include source code
If you are in a maven project make sure in the project structure all the complied folders are in the excluded section.
I suggest to use Linux Instead of windows. It's easy to find and download Java.
If you are using Linux, you can download SDKMAN
Install Java by SDKMAN
# find version
$ sdk list java
# download
$ sdk install java x.y.z-amzn
ctrl+alt+shift+s add JDK
Switch project JDK
If you are using maven , Right click on Project explorer -> choose Maven -> chick on "reload projects"
This did the trick for me:
Make sure you select the option "Project Files" (instead e.g. "Project").

Anypoint Studio Exit Code=13

I noticed that the jre folder inside the Program Files is empty may be because of the some software update.
so had to download the jre, unzip it and then place it inside the same path as mentioned in the AnypointStudio.ini
-startup plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
--launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.300.v20150602-1417
-vm C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe
-vmargs
-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
-Dosgi.instance.area.default=#user.home/AnypointStudio/workspace
-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
This maybe a 64-bit vs 32-bit issue. Please verify that both JRE and AnypointStudio are belongs to same bit version.
Please check this thread for similar issue.
This post from the Mulesoft site resolve my issue with this error. If you have multiple Java executables in your Path and the executable you add for the JDK needed for Mulesoft Anypoint Studio is not the first Java executable in your path, you will get this Exit Code = 13 error. Moving the new executable to the beginning of my path fixed the issue and Anypoint now runs.
https://www.mulesoft.org/jira/browse/MULE-13717?attachmentViewMode=list

Java 7 && IntelliJ

I installed openjdk 1.7.0 and set it up in IntelliJ 10.5
When I compile (anything) I get the error "Fatal Error: Unable to find package java.lang in classpath or bootclasspath".
I looked at this question:
IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath but all jar files inside the lib directory are already added.
Ok. I was wrong there weren't all jars added. I found some more in (sub)directories other than 'lib'. After adding all those manually everything is fine. Seems like even IDEA 10.5.2 does not like the structure in openJDK yet.
Try IDEA 10.5.2. Make sure that JDK path is not a symlink. If the issue remains, specify your OS and attach a screenshot of JDK classpath configured in IDEA.
I had the same problem. I added all jar files in the following directories manually:
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/1.7.0.jre/Contents/Home/lib
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/1.7.0.jre/Contents/Home/lib/ext

Conversion of jar to dll using ikvm

I am trying to convert a jar into dll in dotnet using IKVM but am getting this error Exception in thread "main" java.lang.ClassNotFoundException: \Location of the jar\...
CAn anyone provide some guidance..
Thanks in advance
Prerequisites -
You must have the JDK installed on your system.
Set the environment variables for the JDK.
Steps:
Open the command prompt.
Go to the ikvmc folder (ikvmc.exe comes with the ikvm package).
Enter the command ikvmc -out:myapp.dll myapp.jar
First, create a new Bindings Library project. In Xamarin Studio or Visual Studio, create a new Solution and select the Android Bindings Library template.
The template includes a Jars folder where you add your .JAR(s) to the Bindings Library project. Right-click the Jars folder and select Add > Existing Item:
Navigate to the .jar file downloaded earlier, select it and click Add:
Verify that the .jar file was successfully added to the project:
right click your jar file=>properities =>choose embedded jar
Set the build action to EmbeddedJar:
EmbeddedJar – the .JAR will be embedded in the Bindings Library.
Set the target API level for your Bindings Library
Finally, build the Bindings Library. Although some warning messages may be displayed, the Bindings Library project should build successfully and produce an output .DLL at the following location:
Projectname/bin/Debug/JarBinding.dll
Reference
https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/
Is it possible that you forgot reference all needed IKVM .Net dlls?
IKVM.Runtime.dll
IKVM.Reflection.dll
IKVM.OpenJDK.*.dll
I've got something similar with SmsLib .Net version
The follow wiki pages should be helpful:
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=Ikvmc
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=Ikvmc_messages