maven error when running in cygwin? - maven

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

Related

How to downgrade JDK/javac - MacOS

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.

I am trying to build spark, on Mac and the following error occurs

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.)

How to get Kotlinc 1.8.0 to run with Ubuntu on Windows

I installed Kotlinc through the zip file kotlin-compiler-1.8.0.zip and extracted it and moved the kotlinc\bin files to my C:\Program files. I later then verified that I had installed it correctly by running the kotlinc -version command in the terminal and got back info: kotlinc-jvm 1.5.21 (JRE 16.0.2+7-67). So I believe I have that working just fine. So I believe now the error is arising from Java somehow.
When I go to run my simple hello world program with this:
kotlinc main.kt -include-runtime -d main.jar
I am met with the error:
/mnt/c/Program Files/kotlinc/bin/kotlinc: line 98: java: command not found
Previously I was just getting: kotlinc command not found. I later read on StackOverflow someone else was having the same problem and the answer to that solution was just add it to the environment Variable path, in which I did but I very soon then ran into this issue.
I have since tried everything I have came across on this issue, I've reinstalled the kotlinc compiler and java and put the Java\jdk16.0.2\bin in my environment variable path as well. When I try to run the simple command kotlinc help in Ubuntu I am also met with the same line 98: java command not found error.

Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher in windows 10

I am using windows 10 and i have set the path as mention in the instruction
Set M2_HOME (E:\softwares\apache-maven-3.3.9)
Set M2 (%M2_HOME%\bin)
Set system variable path (%M2_HOME%\bin)
When i run mvn --version i am getting error
C:\Users\zafaque>echo %M2_HOME%
E:\softwares\apache-maven-3.3.9
C:\Users\zafaque>mvn --version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I had the same issue using the source zip archive files from the maven.apache website. I solved using the Binary zip archive files.

Error when using javac: "javac: invalid flag: -s"

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/

Resources