java 在 ubuntu 中查找 maven 版本并设置 MAVEN_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26449957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
finding maven version & set MAVEN_HOME in ubuntu
提问by Bailey
I think I have jumbled up something. yesterday things were working fine. Having lots of problems today..
我想我搞砸了一些事情。昨天一切正常。今天遇到很多问题。。
1.I ran this command
1.我运行了这个命令
echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/
then
然后
mvn --version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
yesterday it was working fine (returning maven version, 3.0.4 , I think) . Now this has started creating problems. what to do ?
昨天它工作正常(返回 maven 版本,3.0.4,我认为)。现在这已经开始产生问题。该怎么办 ?
Also after running
$java --version Unrecognized option: --version Could not create the Java virtual machine.
运行后也是
$java --version 无法识别的选项:--version 无法创建 Java 虚拟机。
here is the content of my .bashrc file and I have nothing in my /etc/environment file.
这是我的 .bashrc 文件的内容,我的 /etc/environment 文件中没有任何内容。
PATH=$PATH:$HOME/.rvm/
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH
and this is in my /etc/profile
这是在我的 /etc/profile
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
PATH=$PATH:$HOME:$JAVA_HOME/bin
export JAVA_HOME
export PATH
- Also let me know, how can i set MAVEN_HOME in it..
- 也让我知道,我如何在其中设置 MAVEN_HOME ..
Any help would be appreciated. Thanks :)
任何帮助,将不胜感激。谢谢 :)
回答by GeroldBroser reinstates Monica
Maybe my config gives you a hint:
也许我的配置给了你一个提示:
/$ uname -a
Linux jenkins 3.2.0-55-generic #85-Ubuntu SMP Wed Oct 2 12:29:27 UTC 2013 \
x86_64 x86_64 x86_64 GNU/Linux
/$ echo $PATH
/var/lib/jenkins/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
/$ ls -l /usr/bin/java* / usr/bin/mvn*
lrwxrwxrwx 1 root root 22 Feb 21 2013 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Feb 21 2013 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 24 Feb 21 2013 javaws -> /etc/alternatives/javaws
lrwxrwxrwx 1 root root 21 Feb 21 2013 mvn -> /etc/alternatives/mvn
lrwxrwxrwx 1 root root 26 Feb 21 2013 mvnDebug -> /etc/alternatives/mvnDebug
/$ ls -l /etc/alternatives/java* /etc/alternatives/mvn*
lrwxrwxrwx 1 root root 17 May 31 2013 /etc/alternatives/java -> \
/opt/jdk/bin/java
lrwxrwxrwx 1 root root 18 May 31 2013 /etc/alternatives/javac -> \
/opt/jdk/bin/javac
lrwxrwxrwx 1 root root 58 Feb 21 2013 /etc/alternatives/javaws.1.gz -> \
/usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/javaws.1.gz
lrwxrwxrwx 1 root root 24 Feb 21 2013 /etc/alternatives/mvn -> \
/usr/share/maven/bin/mvn
lrwxrwxrwx 1 root root 29 Feb 21 2013 /etc/alternatives/mvn.1.gz -> \
/usr/share/maven/man/mvn.1.gz
lrwxrwxrwx 1 root root 29 Feb 21 2013 /etc/alternatives/mvnDebug -> \
/usr/share/maven/bin/mvnDebug
lrwxrwxrwx 1 root root 34 Feb 21 2013 /etc/alternatives/mvnDebug.1.gz -> \
/usr/share/maven/man/mvnDebug.1.gz
/usr/share/maven/conf/m2.conf
:
/usr/share/maven/conf/m2.conf
:
main is org.apache.maven.cli.MavenCli from plexus.core
set maven.home default ${user.home}/m2
[plexus.core]
optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/*.jar
/$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
/$ mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_21, vendor: Oracle Corporation
Java home: /opt/jdk1.7.0_21/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-55-generic", arch: "amd64", family: "unix"
回答by Bailey
there was just one mistake that was java --version. It should be java -version (single dash) otherwise it is working fine now...
只有一个错误是 java --version。它应该是 java -version(单破折号),否则它现在工作正常......
回答by George Sun
http://www.johnlabarge.com/post/33156663109/dreaded-maven-error-could-not-find-or-load-main-classThis link could help, just remove the M2_HOME variable, then add M3_HOME variable.
http://www.johnlabarge.com/post/33156663109/dreaded-maven-error-could-not-find-or-load-main-class这个链接有帮助,只需删除 M2_HOME 变量,然后添加 M3_HOME 变量。
BTW, to print Java version no, you should enter java -version
, rather than java --version
, only single dash is needed, but with Maven, both 'mvn -version' and mvn --version
are ok.
顺便说一句,要打印 Java 版本号,您应该输入java -version
,而不是java --version
,只需要一个破折号,但是对于 Maven,'mvn -version'mvn --version
都可以。