How to fix IntelliJ Idea stuck on "Preparing WSL build environment..."? - java

I am using Ubuntu 22.04 with windows WSL, and have installed JDK 19.01 and Maven inside this, and have imported a file from the WSL into IntelliJ Idea to work on, however once I run a class, IntelliJ "builds" for upwards of half an hour, hanging on the messages of "Executing pre-compile tasks..." and "Preparing WSL build environment...". Obviously this is a pain and I need to know how to fix it.
I've tried to reinstall my JDK in Ubuntu and set the JAVA_HOME variable, which I've checked and have no issues with. I've tried to reinstall IntelliJ, and disabled my firewall/made exceptions, and I've changed the SDK being used inside IntelliJ, all to no success.
Here are logs from inside the Ubuntu terminal showing my JDK and Maven installations:
user#user  \~  mvn -v
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 19.0.1, vendor: Private Build, runtime: /usr/lib/jvm/java-19-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.16.3-microsoft-standard-wsl2", arch: "amd64", family: "unix"
user#user  \~  javac -version
javac 19.0.1
user#user  \~  java -version
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-Ubuntu-1ubuntu122.04)
OpenJDK 64-Bit Server VM (build 19.0.1+10-Ubuntu-1ubuntu122.04, mixed mode, sharing)
user#user  \~  echo $JAVA_HOME
/usr/lib/jvm/java-19-openjdk-amd64
user#user  \~  which java
/usr/bin/java
user#user  \~  which javac
/usr/bin/javac

Disable the real-time antivirus monitoring. It's a known issue.

Remove fsnotifier.exe and idea64.exe in windows defender or follow the directions in this post:
https://youtrack.jetbrains.com/issue/IDEA-293604/IntelliJ-is-hanging-during-build-process-and-indexing-process-when-working-on-the-WSL-projects.#focus=Comments-27-6180537.0-0

Related

Maven Compilation Failure. No compiler is provided in this environment [Mac OS]

Maven suddenly stopped compiling with the error below. It was working this morning and I'm not sure what caused this.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ExampleProject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Basic Information:
OS: Mac
Machine: MacBook Pro
Java: 1.8.0_201 (jdk8)
Maven: 3.8.1
What I tried:
Checked for existence of Java compiler
$ javac -version
javac 1.8.0_201
Check $JAVA_HOME : I got /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home, which is correct for Mac OS according to Maven's installation instructions
Added mvn to PATH before compiling
Reinstalled Maven 3.8.1
Reinstalled JDK8 and reset JAVA_HOME & added mvn to PATH again before compiling
Added sudo to my command. In fact before adding sudo, I was facing some sorta "failed to delete something" error.
Restarting my laptop without using the "Reopen windows...." option.
Adding the compiler option to pom.xml(I didn't need this when it was working this morning)
Running mvn -v give me the output below
Maven home: /opt/apache-maven-3.8.3
Java Version: 1.8.0_201, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
Running java -version gave me the output below:
java version "1.8.0_201"
Java (TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot (TM) 64-Bit Server VM (build 25.201.b09, mixed mode)
Additional Info:
I am not using any IDE like Eclipse/IntelliJ/NetBeans. Just purely on terminal. Please base your answers on this.
It seems like there are 2 versions of Maven on my system, probably due to the reinstall. But prior to the reinstall, this problem already started
Reference (I've tried the solutions in here too)
https://roufid.com/no-compiler-is-provided-in-this-environment/
Edit
I have already made sure that JAVA_HOME points to the JDK and not the JRE by consulting Maven's documentation
Maven needs javac to compile your project. Can you try javac -version and see if your able to get an output.
$ javac -version
javac 1.8.0_201
If not set your JAVA_HOME to JDK not to JRE. C:\Program Files\Java\jdk1.8.0_202
If you are still getting this error, try opening another terminal for the environment variable to reflect. And try.
Regards

Maven on WSL2 can't see JAVA_HOME

I have JDK 11 and Maven 3.8.1 installed on my Windows 10 machine. Took care that install paths don't have spaces.
Made the value of JAVA_HOME visible inside the Ubuntu shell following the advice here. Then I restarted the Ubuntu shell.
Here are the outputs from inside an Ubuntu shell on Windows Terminal:
user#computer:/path$ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
user#computer:/path$ env | grep JAVA
JAVA_HOME=/mnt/c/AdoptOpenJDK/jdk-11-hotspot
user#computer:/path$ mvn -v
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
So although the value of JAVA_HOME is visible inside the Ubuntu shell, somehow mvn can't see it. How do I fix this?
Maven run from cmd gives this output:
C:\path>mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: C:\Maven\bin\..
Java version: 11.0.10, vendor: AdoptOpenJDK, runtime: C:\AdoptOpenJDK\jdk-11-hotspot
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Versions:
Windows 10 version 2004 (OS Build 19041.1110)
Java 11.0.10
Maven 3.8.1
WSL2
Ubuntu 20.04.2 LTS (via WSL2)
I gave up and simply installed JDK 11 & Maven 3.8.1 inside WSL2 using SDKMAN.
Not an ideal solution, but didn't feel like spending more time on this issue.
I don't disagree with your solution to use the Linux versions of Java and Maven inside WSL, but I do think I see why your example in the original question was failing.
The problem appears to be that you are using the Windows versions of Java/Maven, BUT your JAVA_HOME from inside WSL is using the "Linux form" of the path (/mnt/c/AdoptOpenJDK/jdk-11-hotspot).
Maven is complaining, because since it is running under Windows, it doesn't understand that path. It needs to see C:\AdoptOpenJDK\jdk-11-hotspot.
I believe this is because the answer you linked to said to use setx WSLENV "JAVA_HOME/p". The /p is forcing the translation from the Windows path to the WSL/Linux mapping, which you don't want in this case.
Also, be sure to restart the Terminal from which you launch WSL so that it can pick up the new environment variables.

Not able to switch java home properly in mac

I have two versions of Java in my mac and I am trying to switch from 1.8 to 1.7 for compiling one of my project which has 1.7 specific contents. Though I ran the following commands in the terminal:
$ alias setJdk1.7='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)'
$ setJdk1.7
With that, I can see the proper version in java -version and mvn -version.
$ java -version
java version "1.7.0_181"
Java(TM) SE Runtime Environment (build 1.7.0_181-b09)
Java HotSpot(TM) 64-Bit Server VM (build 24.181-b09, mixed mode)
$ mvn -version
Apache Maven 3.0.5 (...)
Maven home: *mvn path*
Java version: 1.7.0_181, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_181.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.5", arch: "x86_64", family: "mac"
However, the /usr/libexec/java_home still seems to be pointing to the 1.8 java only.
$ echo $(/usr/libexec/java_home)
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
I am very new to mac and not really sure how I can toggle between versions. This is not allowing to successfully compile my project.
Maybe try using a function instead and setting up your command as follows:
setJdk1.7() {
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
export PATH=$JAVA_HOME/bin:$PATH
}
Your command likely doesn't work because $JAVA_HOME is never added to your $PATH.

MVN Package Build Failure

I am trying to package a java project using maven. I've done it before on my old computer, but I can't seem to make it work on my new computer.
Here is the error:
`
(env)kyle#thinkpad ~/Code/simplefilehosting $ mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_95, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-38-generic", arch: "amd64", family: "unix"
(env)kyle#thinkpad ~/Code/simplefilehosting $ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
(env)kyle#thinkpad ~/Code/simplefilehosting $ javac -version
javac 1.7.0_95
(env)kyle#thinkpad ~/Code/simplefilehosting $
Here is my version information for java, javac and mvn:
(env)kyle#thinkpad ~/Code/simplefilehosting $ mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_95, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-38-generic", arch: "amd64", family: "unix"
(env)kyle#thinkpad ~/Code/simplefilehosting $ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
(env)kyle#thinkpad ~/Code/simplefilehosting $ javac -version
javac 1.7.0_95
(env)kyle#thinkpad ~/Code/simplefilehosting $
I tried looking at it online and add a plugin but then my mvn never realized the plugins tag or anything else. And I haven't changed the pom.xml from the last time I was able to package it.
Without the actual error message to diagnose (I think you intended to include it but didn't)...but a few things:
-check your M2_HOME and JAVA_HOME variables and make sure they are correct
-make sure settings.xml is in your ~/.m2 or $M2_HOME/config directories
-on your old machine, delete your entire ~/.m2/repository directory and see if it builds, if you upgraded Maven along the way there might be something you already have that Maven3 can't for some reason download
-consider upgrading, 3.0.5 was an intermediate version that was between the old Maven2 and Maven3 artifact resolution, some major differences, some completely different behavior, who knows what you have.

After Installing Java JDK 7 For Mac OS X - mvn -version still shows java version 1.6.0_31

Oracle released Java JDK 7 on April 26 for Mac OS X. I followed the install instructions and when I do java -version in a terminal window I get:
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
However when I do mvn -version in the terminal window I get:
Apache Maven 3.0.2 (r1056850; 2011-01-08 18:58:10-0600)
Java version: 1.6.0_31, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.3", arch: "x86_64", family: "mac"
How can I get Maven to use the Java JDK 1.7.0_04?
Thanks for the help.
Finally found the answer here:
http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7
You should use JAVA_HOME=$(/usr/libexec/java_home) instead on a Mac and then set the current jdk via "Java Preferences.app".
Set JAVA_HOME in ~/.profile
The problem is that the symbolic link "CurrentJDK" inside the versions of JavaVm.framework points to the old jdk, so when i used the following commands to set the CurrentJDK to the latest one (1.7.0_45) it works
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents CurrentJDK
reference: http://java.dzone.com/articles/installing-jdk-7-mac-os-x
To find the path from Java Preferences, try
/usr/libexec/java_home -X
My Java7 entry looks like this:
<dict>
<key>JVMArch</key>
<string>x86_64</string>
<key>JVMBundleID</key>
<string>com.oracle.java.7u04.jdk</string>
<key>JVMEnabled</key>
<true/>
<key>JVMHomePath</key>
<string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
<key>JVMIsBuiltIn</key>
<false/>
<key>JVMName</key>
<string>Java SE 7</string>
<key>JVMPlatformVersion</key>
<string>1.7</string>
<key>JVMVendor</key>
<string>Oracle Corporation</string>
<key>JVMVersion</key>
<string>1.7.0_04</string>
</dict>
You need to change the JAVA_HOME environment variable to the new JDK 1.7 location.
Look at this question for possible locations where JAVA_HOME might be defined. In a terminal, type which java to find the path of your Java installation, and then update JAVA_HOME to point to that path (but exclude the trailing bin folder).
In case anyone is installing Maven on a 64-bit Mac running Mac OSX 'Mavericks' save yourself some time and some hair pulling trying to get Maven installed. I was trying to follow this (which failed because the location of the java_home has changed on Mavericks:
http://maven.apache.org/download.cgi
I was pulling my hair out until I found this website, which recommends you Install homebrew and follow the instructions on this page: http://techspunky.blogspot.in/2013/10/how-to-install-maven-on-mac-osx-109.html
once complete don't panic when $ maven -version doesn't work, instead use $mvn --version as maven.apache.org/download.cgi recommended.
It worked, but then I noticed the Java SDK Maven was using was Java version: 1.6.0_65, which is not the latest SDK I installed on the system.
Once I set the JAVA_HOME=/usr/libexec/java_home
It was using the correct SDK:
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Success!
but wait...
next time I opened the terminal and ran mvn -v it went back to java version 1.6. WTH!
its some sort of supposed bug from what I read use:
echo JAVA_HOME=/usr/libexec/java_home -v 1.7 | sudo tee -a /etc/mavenrc
and now:
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
The reason Maven is still using Java 6 is that the /usr/bin/mvn script that launches it does not use the correct OS/X method for resolving the current Java version as specified in Java Preferences. See this Maven issue for details:
http://jira.codehaus.org/browse/MNG-4226
Voting it up might get it fixed; in the meantime, if you alter the /usr/bin/mvn script as shown in the comments & patch on that issue you will get the desired result.
Ok on my machine. Yes, the Oracle installer didn't exactly do its job, and it confused me to no end after 1.6 was still running.
java run time was updated
java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
but the SDK HOME is actually a sim link still pointing to 1.6
/Library/Java/Home in finder GetInfo points to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
in Terminal
./Home -> /System/Library/Frameworks/JavaVM.framework/Home
Go figure.
I found 1.7 here and I'm using that to build with: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
I think the problem lies partly with the java launch mechanism. I have been able to get Eclipse to run my code under Java7, but I think eclipse itself is still running under Java6. Also, I have a java program that was last compiled a year ago, and built using jarbundler-2.1.0.jar (with option jvmversion="1.6+"). When I double click the .app file it runs Java6, but when I double click the .jar file inside the .app it runs Java7.
Also, I do not use JAVA_HOME, but I still get the correct java version "1.7.0_04" shown in the question. JAVA_HOME seems to be a red herring. Maybe Maven needs it, but Eclipse doesn't seem to use it, and neither does launching jar files.
And after setting Java7 in the Java Preferences tool, it does not seem to affect launching .app java files. However it does make 'java -version' from the terminal work nicely. I tried unchecking everything but the Java7 option, and then Eclipse wouldn't run at all.
If your JAVA_HOME is located at the local user's bash, mvn will pick the system's current java version no matter what JAVA_HOME you've set.
Hence first run the command 'which mvn' and check which executable mvn you are using. After that edit that mvn file and change the JAVA_HOME variable to your prefered java home.

Categories

Resources