Cannot run maven2 on Linux Ubuntu 12.04

梦想与她 提交于 2019-12-13 05:21:36

问题


I am trying to compile a program using maven in my Linux 12.04. In order to do, I use the mvn clean install command. However I get a build error:

[ERROR] Unable to locate the Javac Compiler in:
  /usr/lib/jvm/java-6-openjdk-amd64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

I check the path and indeed I am missing that critical file. This is what I have:

user@modelX:/usr/lib/jvm/java-6-openjdk-amd64/jre/lib$ ls
accessibility.properties  im                    net.properties
amd64                     images                psfontj2d.properties
calendars.properties      jar.binfmt            psfont.properties.ja
charsets.jar              javazic.jar           resources.jar
classlist                 jce.jar               rhino.jar
cmm                       jexec                 rt.jar
compilefontconfig.jar     jsse.jar              security
content-types.properties  jvm.hprof.txt         sound.properties
currency.data             logging.properties    swing.properties
ext                       management            tz.properties
flavormap.properties      management-agent.jar  zi
fontconfig.properties     meta-index

So apparently, I am running openJDK, but I am missing files. How do I fix this?


回答1:


Apparently I was missing some important packages. I found the solution in this website:

  • http://sixarm.com/about/error-unable-to-locate-tools-jar.html



回答2:


In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

Please make sure that JAVA_HOME points to /usr/lib/jvm/java-6-openjdk-amd64/




回答3:


Run javac:

  javac

If it is not found, check the PATH:

  echo $PATH

It should contain

  /usr/lib/jvm/java-6-openjdk-amd64/bin



回答4:


Make sure you have choosen the proper jdk:

$ sudo update-alternatives --config java

I had to choose /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to run mvn. Ominously, there resides a tools.jar in /usr/lib/jvm/java-7-openjdk-amd64/ , but not in /usr/lib/jvm/java-6-openjdk-amd64/



来源:https://stackoverflow.com/questions/21391921/cannot-run-maven2-on-linux-ubuntu-12-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!