Maven项目依赖于JDK版本 [英] Maven project dependecy against JDK version

查看:170
本文介绍了Maven项目依赖于JDK版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些项目需要使用特定版本的JDK进行构建。



问题不在源和目标参数中,而是在在编译期间使用的运行时。
在某些情况下,如果我尝试使用错误的JDK进行编译,我会收到一个编译错误,但有时构建是成功的,并且在使用jar时遇到运行时错误。



例如在eclipse中,我有能力为.classpath文件中的项目建立执行环境。



有没有办法在maven中处理这种情况?



我想要的是能够处理JRE依赖关系,如POM文件中项目的其他依赖项。



更新:



当我问这个问题时,接受的解决方案是最好的解决方案,所以我不会改变它。同时,引入了一种解决这类问题的新方法: Maven Toolchain

解决方案

我发现这篇文章:



http:// maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

 <项目> 
[...]
< 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>


I have projects that need to be build with a specific version of the JDK.

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.

For example in eclipse I have the ability to establish the execution enviroment for the project in the .classpath file.

Is there a way to handle such situation in maven?

What I would like to have is the ability to handle JRE dependency like other dependencies of the project in the POM file.

UPDATE:

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.

解决方案

I've found this article:

http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

<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版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆