问题描述
我有需要使用特定版本的JDK构建的项目。
I have projects that need to be build with a specific version of the JDK.
问题不在源和目标参数中,而是在罐子里面编译期间使用的运行时。
在某些情况下,如果我尝试使用错误的JDK进行编译,则会出现编译错误,但有时构建成功并且在使用jar时出现运行时错误。
The problem isn't in the source and target parameters but in the jars of the runtime used during compilation.In some cases I get a compilation error if I try to compile with the wrong JDK, but sometimes the build is successful and I get runtime errors when using the jars.
例如在eclipse中,我有能力在.classpath文件中为项目建立执行环境。
For example in eclipse I have the ability to establish the execution enviroment for the project in the .classpath file.
有没有办法在maven中处理这种情况?
Is there a way to handle such situation in maven?
我想要的是能够处理JRE依赖性,就像POM文件中项目的其他依赖项一样。
What I would like to have is the ability to handle JRE dependency like other dependencies of the project in the POM file.
当我提出这个问题时,接受的解决方案是最好的,所以我不会改变它。同时引入了针对此类问题的新解决方案:。请点击链接了解更多详情。
The accepted solution was the best one when I asked this question, so I won't change it. Meanwhile a new solution to this kind of problems has been introduced: Maven Toolchain. Follow the link for further details.
推荐答案
我发现这篇文章:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_4_HOME}/bin/javac</executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
这篇关于Maven项目依赖于JDK版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!