Java Maven 错误:也许您在 JRE 而不是 JDK 上运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26313902/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:12:39  来源:igfitidea点击:

Maven error :Perhaps you are running on a JRE rather than a JDK?

javamavencompiler-errors

提问by Kraken

I've never worked with Maven before and I am following the instructions here.When I run the command

我以前从未与 Maven 合作过,我正在按照此处的说明进行操作当我运行命令时

mvn integration-test -Pamp-to-war

It initially downloaded a whole bunch of dependencies, and in the end it showed,

它最初下载了一大堆依赖项,最后它显示,

COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error

I am on ubuntu 13.04.

我在 ubuntu 13.04。

If there's anything you want me to tell you, let me know. Thanks.

如果你有什么想让我告诉你的,请告诉我。谢谢。

EDIT

编辑

When I do echo $JAVA_HOMEI get /usr/lib/jvm/java-7-openjdk-i386/

当我这样做时,echo $JAVA_HOME我得到/usr/lib/jvm/java-7-openjdk-i386/

When I do mvn -version

当我做 mvn -version

I get,

我明白了,

Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.0-26-generic", arch: "i386", family: "unix"

Also, I found out this problem faced by someone else. But I am not sure how to go about the solution that is specified?

另外,我发现了其他人面临的这个问题。但我不确定如何进行指定的解决方案?

Further edits.

进一步编辑。

kraken@kraken-Inspiron-1545:/usr/lib/jvm/java-7-openjdk-i386$ ls -l
total 12
drwxr-xr-x 2 root root 4096 Sep  9 10:44 bin
lrwxrwxrwx 1 root root   41 Jul  4  2013 docs -> ../../../share/doc/openjdk-7-jre-    headless
drwxr-xr-x 5 root root 4096 Oct 13  2013 jre
drwxr-xr-x 4 root root 4096 Oct 13  2013 man

采纳答案by Kraken

Apparently, it requires tools.jar file inside the lib folder of my $JAVA_HOME. I did not have the lib folder, so I reinstalled my jdk using command

显然,它需要我的 $JAVA_HOME 的 lib 文件夹中的 tools.jar 文件。我没有 lib 文件夹,所以我使用命令重新安装了 jdk

apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib

Also, this link may help some people.

此外,此链接可能对某些人有所帮助。

回答by Mack

This is how i fixed my problem

这就是我解决问题的方法

right clik on the project > properties > Java Compiler (select the one you are using)

右键单击项目 > 属性 > Java 编译器(选择您正在使用的那个)

it was 1.5 for me but i have 1.8 installed. so i changed it to 1.8.. and voilla it worked!.

对我来说是 1.5,但我安装了 1.8。所以我把它改成了 1.8 .. 瞧它奏效了!.

回答by ced

I've been facing the same issue with java 8 (ubuntu 16.04), trying to compile using mvncommand line.

我在 java 8 (ubuntu 16.04) 上遇到了同样的问题,试图使用mvn命令行进行编译。

I verified my $JAVA_HOME, java -versionand mvn -version. Everything seems to be okay pointing to /usr/lib/jvm/java-8-openjdk-amd64.

我验证了我的$JAVA_HOME,java -versionmvn -version. 一切都好似指指点点/usr/lib/jvm/java-8-openjdk-amd64

It appears that java-8-openjdk-amd64 is not completly installed by default and only contains the JRE (despite its name "jdk").

看起来 java-8-openjdk-amd64 默认没有完全安装,只包含 JRE(尽管它的名字是“jdk”)。

Re-installing the JDK did the trick.

重新安装 JDK 就成功了。

sudo apt-get install openjdk-8-jdk

Then some new files and new folders are added to /usr/lib/jvm/java-8-openjdk-amd64and mvn is able to compile again.

然后一些新文件和新文件夹被添加到/usr/lib/jvm/java-8-openjdk-amd64并且 mvn 能够再次编译。

回答by sks

For me, it worked like following. Please look at JAVA_HOME environment variable, whether it is pointing to JRE or JDK.? If it pointed to JRE, you will face "Perhaps you are running on a JRE rather than a JDK" issue. if so change the path to JDK.

对我来说,它的工作方式如下。请看JAVA_HOME环境变量,是指向JRE还是JDK。?如果它指向 JRE,您将面临“也许您在 JRE 而不是 JDK 上运行”的问题。如果是这样,请更改 JDK 的路径。

Modifying like this, it worked for me.

像这样修改,它对我有用。

JAVA_HOME C:\Program Files\Java\jdk1.8.0_31

JAVA_HOME C:\Program Files\Java\jdk1.8.0_31

回答by Qaddaffi

Right click on your project folder (Maven one), select properties and from the properties window, again select Java Compiler and see what is selected against compiler compliance level and make sure that it is the same version as your jre. In my case I had 1.8 but 1.5 was selected against compiler compliance level. After selecting 1.8 the build was successful without this error.

右键单击您的项目文件夹(Maven 之一),选择属性,然后从属性窗口中,再次选择 Java 编译器并查看针对编译器合规性级别选择的内容,并确保它与您的 jre 版本相同。在我的情况下,我有 1.8,但根据编译器合规性级别选择了 1.5。选择 1.8 后,构建成功,没有出现此错误。

回答by AnuradhaS

Add this configurations in pom.xml

在 pom.xml 中添加此配置

<project ...>
    ...
    <build>
        ...
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

回答by Raja Rajan

Check if /usr/bin has 'javac'. If not you have installed JRE & have to install jdk dev version like "java-1.8.0-openjdk-devel.x86_64"

检查 /usr/bin 是否有 'javac'。如果没有,您已经安装了 JRE 并且必须安装 jdk 开发版本,例如“java-1.8.0-openjdk-devel.x86_64”

回答by user1913615

I had the same error and I was missing the User variable: JAVA_HOME and the value for the SDK - "C:\Program Files\Java\jdk-9.0.1" in my case

我有同样的错误,我错过了用户变量:JAVA_HOME 和 SDK 的值 - 在我的例子中是“C:\Program Files\Java\jdk-9.0.1”

回答by Barani r

Just adding more details on where to setup. Main reason would be the JAVA_HOME setup in the environment variable should be pointing to correct JDK location.

只需添加有关设置位置的更多详细信息。主要原因是环境变量中的 JAVA_HOME 设置应该指向正确的 JDK 位置。

  1. Check System -> Advance System Settings
  2. Click on Environment variable
  3. Add variable JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_141;"
  4. Edit "path" -> append %JAVA_HOME%; to the existing text.
  1. 检查系统 -> 高级系统设置
  2. 点击环境变量
  3. 添加变量 JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_141;"
  4. 编辑“路径”-> 追加 %JAVA_HOME%; 到现有文本。

回答by Paul.M

I had the same issue after installing the java-1.8.0-openjdkpackage on an AWS Linux AMI. The incorrect assumption I made, was that because the file ended in openjdkit would be the jdk version. This is not the case.

java-1.8.0-openjdk在 AWS Linux AMI 上安装软件包后,我遇到了同样的问题。我做出的错误假设是,因为文件以openjdk结尾,所以它将是 jdk 版本。不是这种情况。

The openjdk install pageexplains everything clearly.

OpenJDK的安装页面解释清楚一切。

The java-1.8.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.8.0-openjdk-devel package.

java-1.8.0-openjdk 包只包含 Java 运行时环境。如果要开发 Java 程序,请安装 java-1.8.0-openjdk-devel 包。

If you've already installed the java-1.8.0-openjdk package, just leave it and the JAVA_HOME value if it's working for the JRE and install the java-1.8.0-openjdk-devel package using yum install java-1.8.0-openjdk-devel -y.

如果您已经安装了 java-1.8.0-openjdk 包,如果它适用于 JRE,只需保留它和 JAVA_HOME 值,并使用 安装 java-1.8.0-openjdk-devel 包yum install java-1.8.0-openjdk-devel -y