简体   繁体   中英

Cygwin runs wrong version of java

I have this problem with Cygwin. I have Java 1.6 and 1.7 installed. I want to use maven 3.0.4 with Java 1.7 but I don't want to uninstall Java 1.6. My JAVA_HOME looks like:

C:\Program Files\Java\jdk1.7.0_09

when I run java -version in Cygwin I get:

java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)

when I run the same command in cmd.exe I get:

java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

Does anyone knows how to solve this?

There are two separate questions here.


The first question is why java -version is finding different Java installations on Cygwin and the classical Windows command interpreter.

The answer is most likely that your Cygwin and Windows environments have different values for $PATH and %PATH% respectively. If you want java -version on Cygwin to run Java 7, you need to make sure that the Cygwin $PATH includes the Java 7 bin directory ... in the appropriate syntax.


The second question is how to get the mvn command under Cygwin to use Java 7.

The answer is not so straight-forward:

  • Setting $PATH might solve your problem.

  • According to the Maven installation documentation, the mvn wrapper scripts should use the $JAVA_HOME environment variable in your (Cygwin) shell to decide on which Java to use.

  • The way to find out what is really going on is to look at the wrapper scripts and see what they are actually doing. And if reading the scripts is too hard, try "hacking" the scripts to include set -vx . That will tell you what lines of the script are being read, and what commands are being executed.

  • Finally, the POM file can influence the source and target levels for your build ... independently of the JVM that runs the build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM