Java 编译致命错误:目标版本无效:1.8 -> [帮助 1]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28291691/
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
Fatal error compiling: invalid target release: 1.8 -> [Help 1]
提问by rvd
Similar problem like one posted on invalid target release: 1.7but after following the blog my problem is still unresolved.
类似的问题,如发布在无效目标版本:1.7 上,但在关注博客后,我的问题仍未解决。
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project hm_app: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
无法在项目 hm_app 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile): Fatal error compiling: invalid target release: 1.8 -> [Help 1]
I was following as tutorialwhen I faced this problem.
当我遇到这个问题时,我正在按照教程进行操作。
abt java & mvn
C:\mvn>echo %JAVA_HOME%
C:\mvn>echo %JRE_HOME%
C:\mvn>echo %MAVEN_HOME% yields
outputs
产出
C:\Program Files\Java\jdk1.7.0_51
C:\Program Files\Java\jre7
C:\apache-maven-3.0.4
采纳答案by Zavior
You have set your %JAVA_HOME
to jdk 1.7, but you are trying to compile using 1.8. Install jdk 1.8 and make sure your %JAVA_HOME
points to that or drop the target release to 1.7.
您已将%JAVA_HOME
jdk设置为 1.7,但您正在尝试使用 1.8 进行编译。安装 jdk 1.8 并确保您%JAVA_HOME
指向该版本或将目标版本降至 1.7。
invalid target release: 1.8
无效的目标版本:1.8
The target release refers to the jdk version.
目标版本是指jdk版本。
回答by Camila Macedo
Put the value in the plugin:
将值放入插件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
The error was use:
错误是使用:
<source>${java.version}</source>
<target>${java.version}</target>
回答by lilalinux
Putting that in your .profile will dynamically take care of your $JAVA_HOME
把它放在你的 .profile 中会动态地照顾你 $JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home)
Close your shell afterwards, open a new one and test with
之后关闭你的外壳,打开一个新的并测试
echo $JAVA_HOME
It should display something like
它应该显示类似
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
If not, remove any other assignments of JAVA_HOME in your startup scripts. Remember, that these startup scripts start with a .
so they are hidden and won't be included when using *
wildcard, e.g. if you want to grep all files of your home directory, you need to:
如果没有,请删除启动脚本中 JAVA_HOME 的任何其他分配。请记住,这些启动脚本以 a 开头,.
因此它们是隐藏的,不会在使用*
通配符时包含在内,例如,如果您想 grep 主目录的所有文件,您需要:
grep -s JAVA_HOME ~/.* --exclude=.bash_history
回答by Roland Ettinger
In my case the maven "Run configuration" was using the wrong JRE (1.7). Be sure to check Run -> Run Configurations -> (Tab) JREto be some jdk1.8.x.
在我的情况下,maven“运行配置”使用了错误的 JRE (1.7)。一定要检查Run -> Run Configurations -> (Tab) JRE是一些 jdk1.8.x。
回答by Bikramjit Saha
The issue was resolved as i was having a JDK pointing to 1.7 and JRE pointing to 1.8. Check in command prompt my typing
该问题已解决,因为我有一个指向 1.7 的 JDK 和指向 1.8 的 JRE。签入命令提示符我的输入
java -version
and
和
javac -version.
Both should be same.
两者应该是一样的。
回答by Vaibhav Gupta
The problem I was facing was that I was able to make a maven build from the command prompt but not from Eclipse.What worked for me in eclipse is that I changed the run configuration to point to JRE folder inside of JDK rather than leaving it in JDK folder only as per the standard.This solution may work for you as well but try this if and only if all the java paths are correct, java and javac are showing the same version as present in the target of pom.xml.
我面临的问题是我能够从命令提示符而不是从 Eclipse 进行 maven 构建。 JDK 文件夹仅符合标准。此解决方案也可能适用于您,但当且仅当所有 java 路径都正确时才尝试此操作,java 和 javac 显示的版本与 pom.xml 的目标中存在的版本相同。
回答by VIJAYKUMAR REDDY ALAVALA
What worked in my case is this:
在我的情况下是这样的:
I opened the pom.xml
and replaced the one of the plug-ins as below.
我打开pom.xml
并替换了如下插件之一。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Before I edited the source and target tags both had 1.8
, I changed that to 1.7
and it worked.
在我编辑源标签和目标标签之前1.8
,我将其更改为1.7
并且它起作用了。
回答by vivat pisces
This question wasn't asking explicitly about Docker, but I received the same error when I had a pom.xml file that was targeting 1.9...
这个问题没有明确询问 Docker,但是当我有一个针对 1.9 的 pom.xml 文件时,我收到了同样的错误......
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
... but then tried to run tests against a Docker container by specifying "maven" by itself.
...但随后尝试通过单独指定“maven”来针对 Docker 容器运行测试。
docker run -t --rm -v m2_repository:/root/.m2/repository -v $(pwd):/work -w /work maven mvn -e test
For me, the fix was to target the exact version I needed.
对我来说,修复是针对我需要的确切版本。
docker run -t --rm -v m2_repository:/root/.m2/repository -v $(pwd):/work -w /work maven:3.5.2-jdk-9 mvn test
(You can learn more here.)
(您可以在此处了解更多信息。)
回答by РАВИ
For eclipse here is how I solved my problem:
对于 eclipse,这里是我解决问题的方法:
Preferences --> Compiler --> Compiler Complainer Level (Change to 1.8)
Rebuild via maven using Run as maven build.
使用 Run as maven build 通过 maven 重建。
It shouldn't show you the invalid target error anymore.
Note: I didn't have to set or change any other variables in my terminal.
Hope this helps.
它不应该再向您显示无效目标错误。
注意:我不必在终端中设置或更改任何其他变量。希望这可以帮助。
回答by Edmore M Gonese Digolodollarz
I faced this issue deploying on Dokku, for some reason it was choosing JDK 1.7
我在 Dokku 上部署时遇到了这个问题,出于某种原因它选择了 JDK 1.7
Creating a system.properties
file and setting java.runtime.version=1.8
solved the issue. Dokku now uses Java version 8.
Choosing a JDK on Heroku
创建system.properties
文件和设置java.runtime.version=1.8
解决了这个问题。Dokku 现在使用 Java 版本 8。
在 Heroku 上选择 JDK
I Never had to do it before...
我以前从来没有这样做过......