I am trying to specify another version of JDK in maven-compiler-plugin. When -target and -source parameters are set to 1.5, everything is ok. But when i try to use 1.6 JDK, maven reports an error. Has anyone faced this problem?
Error:
Failure executing javac, but could not parse the error:
javac: invalid flag: -s
Usage: javac
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
Thanks.
If you use 1.6 flag your JAVA_HOME should point to JDK 1.6.
Check it with java -version on a command line.
To define your JAVA_HOME do this:
Add to your ~/.bashrc this line:
export JAVA_HOME=$(/usr/libexec/java_home)
reference: http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/
Related
I am trying to downgrade the jdk for a project I'm running from 17.0.5 to 1.8, but have not been able to replicate any of the results I've found online. Specs and attempts below.
Specs:
MacOS Big Sur v11.6.8
Java v1.8.0_351
Javac v17.0.5
Gradle v7.6
Homebrew v3.6.16
Running /usr/libexec/java_home -V:
Matching Java Virtual Machines (4):
17.0.5 (x86_64) "Oracle Corporation" - "Java SE 17.0.5" /Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home
1.8.351.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_351 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home
1.8.0_341 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home
First, I tried replicating the code from this answer regarding downgrading java:
https://stackoverflow.com/a/48422257/20834861
I quickly realized that the bash profile from sudo nano was already used to downgrade java to v1.8.
Then, I tried this solution: https://stackoverflow.com/a/23819062/20834861
But sudo mv jdk1.8.0_351.jdk ~/Desktop/ returns the following error: mv: rename jdk1.8.0_351.jdk to /Users/sahil/Desktop/jdk1.8.0_351.jdk: No such file or directory
So next, I tried the solution from this link:
https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/#java-home-and-macos-11-big-sur
When I tried the final line of code, echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home , I received the following error: zsh: permission denied: /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home .
Finally, I tried a similar line of code but with source as the bash_file instead of zshenv. I got the same error.
I must be missing something really obvious but I could not find anything else on the internet. Any help is appreciated.
With OSX you can select which jdk to use by using the JAVA_HOME environment variable. To set it.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home
That should work because it is in the list of jdk's you have available according to java_home. You can also use the java_home command to get the appropriate jdk.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Then when you run java or javac it should be from the version selected.
When I run the command
./build/mvn -DskipTests clean package
the following error occurs(though it seems that the java home environment was not set properly)
[WARNING] javac exited with exit code -1
[ERROR] ## Exception when compiling 10 sources to /Users/johnding/spark/common/tags/target/scala-2.12/classes
java.io.IOException: Cannot run program "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/javac" (in directory "/Users/johnding/spark"): error=2, No such file or directory
though it seems that the java home environment was not set properly
Make sure you set JAVA_HOME properly.
Use echo $JAVA_HOME to check.
On Mac you can use jenv to manage your java version.
(Don't forget to restart your terminal application or resource your configuration.)
I am trying to build this project to develop custom x-pack plugins (https://github.com/elastic/shield-custom-realm-example)
However, when I try to run ./gradlew inside the project root I get a JAVA_HOME must be set to build Elasticsearch error.
Here are the details on why I don't understand why this error is being thrown.
➜ shield-custom-realm-example git:(master) echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
➜ shield-custom-realm-example git:(master) java -version
'java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
➜ shield-custom-realm-example git:(master) ./gradlew
> Configure project :
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Build file '~/dev/temp/shield-custom-realm-example/build.gradle' line: 39
* What went wrong:
A problem occurred evaluating root project 'x-pack-custom-realm-extension-example'.
> Failed to apply plugin [id 'elasticsearch.build']
> JAVA_HOME must be set to build Elasticsearch
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
Additionally, I also have these added to my ~/.zshrc file.
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
export RUNTIME_JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
Try running ./gradlew --stop, confirm with env | grep JAVA that your env vars are exported and try your build again. It happened to me in the past that the Gradle Daemon was started without the env var and did not restart to pick it up.
when i run the command "mvn --version" i get the following error.
mvn --version
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/java/jdk1.7.0_51/bin/java
It looks like I need to get rid of "bin/java" at the end
How do i fix this ? any suggestions?
set JAVA_HOME where your JDK's root directory is
export JAVA_HOME= /usr/java/jdk1.7.0_51
I have cygwin in Windows 7 and downloaded and installed maven "binaries" and have the following set
export JAVA_HOME=/cygdrive/c/java/jdk1.7.0_11
export MAVEN_HOME=/usr/apache-maven-3.0.5
export M2_HOME=/home/MyUser/.m2
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
$ which java
/cygdrive/c/java/jdk1.7.0_11/bin/java
$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
$ which mvn
/usr/apache-maven-3.0.5/bin/mvn
$ mvn -version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I've looked at Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher but it did not address my issue.
What did I miss?
Maven with Cygwin - Error: JAVA_HOME is not defined correctly
The "alias mvn=mvn.bat" answer toward the bottom of above post worked for me. However, is this THE solution?
I spent a couple of hours fruitlessly fiddling with different combinations of JAVA_HOME, M2_HOME and M2 after this same problem. Finally I set down to debugging the mvn script (by changing line 1 to read "#!/bin/sh -x"). It occurs because the script is relying on shell globbing to get the correct version of the .jar file (at approx. line 157):
CLASSPATH="${M2_HOME}/boot/plexus-classworlds-*.jar"
the * is not being expanded, for some reason globbing is disabled;
Hence the command the script attempts to execute is:
'/cygdrive/c/Program Files/Java/jdk1.7.0_40/bin/java' -classpath 'D:\apps\apache-maven-3.0.4\boot\plexus-classworlds-*.jar' '-Dclassworlds.conf=D:\apps\apache-maven-3.0.4\bin\m2.conf' '-Dmaven.home=D:\apps\apache-maven-3.0.4' org.codehaus.plexus.classworlds.launcher.Launcher -version
when it should be:
'/cygdrive/c/Program Files/Java/jdk1.7.0_40/bin/java' -classpath 'D:\apps\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar' '-Dclassworlds.conf=D:\apps\apache-maven-3.0.4\bin\m2.conf' '-Dmaven.home=D:\apps\apache-maven-3.0.4' org.codehaus.plexus.classworlds.launcher.Launcher -version
Solution: Edit the "mvn" script and change line 157 to read:
CLASSPATH="$(echo ${M2_HOME}/boot/plexus-classworlds-*.jar)"
change the JAVA_HOME path in .bashrc_profile file