有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在Linux Ubuntu 12.04上运行maven2

我正在尝试在Linux 12.04中使用maven编译一个程序。为此,我使用mvn clean install命令。但是,我得到一个生成错误:

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

我检查了路径,实际上我丢失了那个关键文件。这就是我所拥有的:

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

显然,我运行的是openJDK,但我缺少文件。我该如何解决这个问题


共 (4) 个答案

  1. # 1 楼答案

    确保您选择了正确的jdk:

    $ sudo update-alternatives --config java
    

    我必须选择/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java来运行mvn。不祥的是,有一种工具。jar在/usr/lib/jvm/java-7-openjdk-amd64/,但在/usr/lib/jvm/java-6-openjdk-amd64/

  2. # 3 楼答案

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

    请确保JAVA_HOME指向/usr/lib/jvm/java-6-openjdk-amd64/

  3. # 4 楼答案

    运行javac:

      javac
    

    如果找不到,请检查路径:

      echo $PATH
    

    它应该包含

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