Class JavaLaunchHelper is implemented in two places - java

Today I upgraded my Intellij Idea on macOS Sierra, and now, when I run apps in console I have this error:
objc[3648]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10d19c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ea194e0). One of the two will be used. Which one is undefined.

You can find all the details here:
IDEA-170117 "objc: Class JavaLaunchHelper is implemented in both ..." warning in Run consoles
It's the old bug in Java on Mac that got triggered by the Java Agent being used by the IDE when starting the app. This message is harmless and is safe to ignore. Oracle developer's comment:
The message is benign, there is no negative impact from this problem
since both copies of that class are identical (compiled from the exact
same source). It is purely a cosmetic issue.
The problem is fixed in Java 9 and in Java 8 update 152.
If it annoys you or affects your apps in any way (it shouldn't), the workaround for IntelliJ IDEA is to disable idea_rt launcher agent by adding idea.no.launcher=true into idea.properties (Help | Edit Custom Properties...). The workaround will take effect on the next restart of the IDE.
I don't recommend disabling IntelliJ IDEA launcher agent, though. It's used for such features as graceful shutdown (Exit button), thread dumps, workarounds a problem with too long command line exceeding OS limits, etc. Losing these features just for the sake of hiding the harmless message is probably not worth it, but it's up to you.

Since “this message is harmless”(see the #CrazyCoder's answer), a simple and safe workaround is that you can fold this buzzing message in console by IntelliJ IDEA settings:
【Preferences】- 【Editor】-【General】-【Console】- 【Fold console lines that contain】
Of course, you can use 【Find Action...】(cmd+shift+A on mac) and type Fold console lines that contain so as to navigate more effectively.
add Class JavaLaunchHelper is implemented in both
On my computer, It turns out: (LGTM :b )
And you can unfold the message to check it again:
PS:
As of October 2017, this issue is now resolved in jdk1.9/jdk1.8.152/jdk1.7.161
for more info, see the #muttonUp's answer)

I am using Intellij Idea 2017 and I got into the same problem. What solved the problem for me was to simply
close the project in intelliJ
File -> New -> project from existing resources
use Import from external model (if any)
open the project again.

This happened to me when I installed Intellij IDEA 2017, go to menu Preferences -> Build, Execution, Deployment -> Debugger and disable the option: "Force Classic VM for JDK 1.3.x and earlier". This works to me.

I have found the other workaround: to exclude libinstrument.dylib from project path. To do so, go to the Preferences -> Build, Execution and Deployment -> Compiler -> Excludes -> + and here add file by the path in error message.

Same error, I upgrade my Junit and resolve it
org.junit.jupiter:junit-jupiter-api:5.0.0-M6
to
org.junit.jupiter:junit-jupiter-api:5.0.0

This was an issue for me years ago and I'd previously fixed it in Eclipse by excluding 1.7 from my projects, but it became an issue again for IntelliJ, which I recently installed. I fixed it by:
Uninstalling the JDK:
cd /Library/Java/JavaVirtualMachines
sudo rm -rf jdk1.8.0_45.jdk
(I had jdk1.8.0_45.jdk installed; obviously you should uninstall whichever java version is listed in that folder. The offending files are located in that folder and should be deleted.)
Downloading and installing JDK 9.
Note that the next time you create a new project, or open an existing project, you will need to set the project SDK to point to the new JDK install. You also may still see this bug or have it creep back if you have JDK 1.7 installed in your JavaVirtualMachines folder (which is what I believe happened to me).

Related

Why does any collection object not recognized? (VSCode) [duplicate]

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Visual Studio Code - Java - Import Errors and More

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Class JavaLaunchHelper is implemented in both XXX and XXX,One of the two will be used. Which one is undefined [duplicate]

Today I upgraded my Intellij Idea on macOS Sierra, and now, when I run apps in console I have this error:
objc[3648]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10d19c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ea194e0). One of the two will be used. Which one is undefined.
You can find all the details here:
IDEA-170117 "objc: Class JavaLaunchHelper is implemented in both ..." warning in Run consoles
It's the old bug in Java on Mac that got triggered by the Java Agent being used by the IDE when starting the app. This message is harmless and is safe to ignore. Oracle developer's comment:
The message is benign, there is no negative impact from this problem
since both copies of that class are identical (compiled from the exact
same source). It is purely a cosmetic issue.
The problem is fixed in Java 9 and in Java 8 update 152.
If it annoys you or affects your apps in any way (it shouldn't), the workaround for IntelliJ IDEA is to disable idea_rt launcher agent by adding idea.no.launcher=true into idea.properties (Help | Edit Custom Properties...). The workaround will take effect on the next restart of the IDE.
I don't recommend disabling IntelliJ IDEA launcher agent, though. It's used for such features as graceful shutdown (Exit button), thread dumps, workarounds a problem with too long command line exceeding OS limits, etc. Losing these features just for the sake of hiding the harmless message is probably not worth it, but it's up to you.
Since “this message is harmless”(see the #CrazyCoder's answer), a simple and safe workaround is that you can fold this buzzing message in console by IntelliJ IDEA settings:
【Preferences】- 【Editor】-【General】-【Console】- 【Fold console lines that contain】
Of course, you can use 【Find Action...】(cmd+shift+A on mac) and type Fold console lines that contain so as to navigate more effectively.
add Class JavaLaunchHelper is implemented in both
On my computer, It turns out: (LGTM :b )
And you can unfold the message to check it again:
PS:
As of October 2017, this issue is now resolved in jdk1.9/jdk1.8.152/jdk1.7.161
for more info, see the #muttonUp's answer)
I am using Intellij Idea 2017 and I got into the same problem. What solved the problem for me was to simply
close the project in intelliJ
File -> New -> project from existing resources
use Import from external model (if any)
open the project again.
This happened to me when I installed Intellij IDEA 2017, go to menu Preferences -> Build, Execution, Deployment -> Debugger and disable the option: "Force Classic VM for JDK 1.3.x and earlier". This works to me.
I have found the other workaround: to exclude libinstrument.dylib from project path. To do so, go to the Preferences -> Build, Execution and Deployment -> Compiler -> Excludes -> + and here add file by the path in error message.
Same error, I upgrade my Junit and resolve it
org.junit.jupiter:junit-jupiter-api:5.0.0-M6
to
org.junit.jupiter:junit-jupiter-api:5.0.0
This was an issue for me years ago and I'd previously fixed it in Eclipse by excluding 1.7 from my projects, but it became an issue again for IntelliJ, which I recently installed. I fixed it by:
Uninstalling the JDK:
cd /Library/Java/JavaVirtualMachines
sudo rm -rf jdk1.8.0_45.jdk
(I had jdk1.8.0_45.jdk installed; obviously you should uninstall whichever java version is listed in that folder. The offending files are located in that folder and should be deleted.)
Downloading and installing JDK 9.
Note that the next time you create a new project, or open an existing project, you will need to set the project SDK to point to the new JDK install. You also may still see this bug or have it creep back if you have JDK 1.7 installed in your JavaVirtualMachines folder (which is what I believe happened to me).

Eclipse - Unable to install breakpoint in a Java API Class

I have found a few question about the issue here on StackOverlow, but all were about own written code. My problem is a bit different, because I want to debug a Java API class, named javax.swing.JComponent.
My first problem was, that I couldn't see any sources. I fixed it described like here Attach the Java Source Code by attaching the source to rt.jar.
Now I see the source and I want to set a breakpoint in the JComponent class. If I try so, I get the error message:
"Modify compiler options to generate line number attributes". That is a nice proposal. But my JDK version was already compiled when I downloaded it..
So, do I have it to compile on my own? Or do you have other advices?
Thanks for your help!
P.S.: I have installed
- Eclipse Neon
- jdk1.8.0_91
- Windows 10 (64 Bit)
One probable issue could come from your application server in IDE pointing to JRE instead of JDK.
Try verifying:
Window -> Preferences --> Server --> runtime environments
<Your-Application-Server> --> edit
Select a JDK instead of JRE
Not sure if you have gone through this link.... has few solutions which worked for some.
Eclipse - Unable to install breakpoint due to missing line number attributes
this happens when you use JRE on your build path in this case.
Try do this:
Window -> Preferences --> Java --> Installed JRES-->then use jdk as default JRE
problem fixed!

What's up with warnings about runtime not being a 'perfect match' to 'RequiredExecutionEnvironment'?

There is this warning I regularly encounter when working with Java/Eclipse/Maven/OSGi:
The JRE container on the classpath is not a perfect match to the 'JavaSE-1.6' execution environment
I am on a Java 7 JDK. Most project require (rightly so I think) a lower version than that. For example they will require JavaSE-1.6 or JavaSE-1.5. So in their MANIFEST.MF, these projects will have an entry that looks like this (sample taken from a bundle project of mine):
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
This will give me the mentioned warning. Now, I know of two possible ways to 'solve' this warning:
Replace the current runtime environment for the project with a Java 6 runtime
Change the MANIFEST entry to JavaSE-1.7
Both 'solutions' seem completely ludicrous to me. My project does not require JavaSE-1.7. It runs perfectly fine on JavaSE-1.6. Requiring all users of the bundle to have at least Java 7, just because the developer was on Java 7 and did not like the warning seems to me to be the opposite of what you would want. On the other hand, requiring me as a developer to have all versions of Java installed that are listed as required execution environment on projects I work with seems to be almost just as ludicrous. All these projects run perfectly fine on Java 7 so why would I need to have many of them?
Am I completely missing something (in which case I am not the only one), or is this warning really stupid as it is actively promoting developers to set a much higher required execution environment for their projects as would be strictly needed?? Any insight (and hopefully a third way to get rid of this warning) would be greatly appreciated.
There are three possible ways to get rid of the warning:
Replace the current runtime environment for the project with a Java 6 runtime (recommended)
Change the MANIFEST entry to JavaSE-1.7
Change the build settings to ignore the warning
Replace the current runtime environment for the project with a Java 6 runtime
This is the recommended solution. What the warning is trying to say is that specifying a minimum required execution environment of Java 6, but then using a Java 7 environment during development is inherently risky as you could write some code that only works in Java 7 and you would not notice this until you deploy to a Java 6 environment and it breaks (thanks to greg-449 and Konstantin Komissarchik for mentioning this in the comments).
Step 1: Add a new Java 6 Runtime environment:
Window -> Preferences -> Java / Installed JREs -> button 'Add...'
Step 2: Select the newly added JRE as runtime for the project
Poject -> Properties -> Java Build Path
Change the MANIFEST entry to JavaSE-1.7
This solution is simple enough. The big downside is that you will be forcing all users of your project to upgrade their Java runtime to whichever version you are using. So it's not so good if you want to support older runtimes as well.
Change the build settings to ignore the warning
Just make Eclipse stop complaining. WARNING: Use with care. Ignoring the warning could make you miss breaking backwards compatibility with older VMs without noticing it.
Window -> Preferences -> Java / Compiler / Building (or the equivalent per-project page if it applies):
This is not a very important problem and I agree with the previous solutions given, but this message is still delivered in the following recent context :
Eclipse IDE for Java EE Developpers : Luna (SR1a-win32), the most recent download available in january 2015 for my Vista machine
installed JRE : version 8 (update 1.8.0_25-b18).
I tried a thing I haven't done for a long time (maybe since the first time I used Eclipse) : trying the examples available on the Welcome page, an icon labelled "Samples - Try out the samples". I did it, a wizzard installed a lot of source code in one project, and I got the a red exclamation mark on the project root. Looking at the Problems view gave the solution : the entire project is defined for the old J2SE-1.4 JRE.
It seemed easy to change that in the Java Build Path window, by editing the JRE System Library of the project : I selected the Workspace default JRE (jre1.8.0_25) option.
And that's the point I got the message "The JRE container of the classpath is not a perfect match to the 'J2SE-1.4' execution environment". I decided to attempt to resolve this (trivial) problem, to get a clean starting point to my investigation in the examples code. It was not so obvious.
Double-clicking on the error message in the Problems view takes you in the Manifest file of the project, on the line with the red mark :
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Trying to change the version 1.4 by 1.8 is not the solution, you get the message : "'J2SE-1.8' is not a valid Execution Environment".
Trying to remove the line is no more the solution, you get the message :
"No required execution environment has been set".
After spending a little bit of time, the correct action I founded is simple : do the same thing with the manifest editor of Eclipse to get the correct name of the option : it is not J2SE-1.8 but JavaSE1.8
Here is the proc :
in the Overview pane of the manifest file in the editor view, in the Execution Environments scope, clic the Add... button and select JavaSE-1.8
Select J2SE1.4 and clic the Remove button.
That's it.

Categories