问题描述
我有一个Maven模块,需要在J2ME客户端和EJB服务器中使用.在客户端中,我需要针对目标1.1进行编译,而在服务器中针对目标1.6进行编译.
I have a maven module that I need to use in the J2ME client and in the EJB server. In the client I need to compile it for target 1.1 and in the server for target 1.6 .
我还需要将1.6版本部署到Nexus存储库中,因此从事服务器项目的成员可以包含此依赖项,而无需下载源代码.
I also need to deploy the 1.6 version to a Nexus repository, so the members working on the server project can include this dependency without needing to download the source code.
我已阅读 http://java.dzone.com/articles/maven-profile-最佳实践,使用配置文件不是实现此目的的最佳方法,但作者没有说什么是最佳方法.
I've read at http://java.dzone.com/articles/maven-profile-best-practices that using profiles is not the best way of doing this, but the author didn't say what's the best way.
这是我的pom.xml:
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>proj-parent</artifactId>
<groupId>br.com.comp.proj</groupId>
<version>0.0.4-SNAPSHOT</version>
</parent>
<artifactId>proj-cryptolib</artifactId>
<name>proj - Cryto Lib</name>
<dependencies>
<dependency>
<groupId>br.com.comp</groupId>
<artifactId>comp-proj-mobile-messages</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>1.1</target>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
推荐答案
您可以通过Maven编译器插件进行配置.
You can configure this via the Maven compiler plugin.
看看 Maven编译器插件文档.
例如,您可以通过其他配置文件启用此功能.
You could enable this via different profiles for instance.
如果只想拥有不同的目标版本,则可以简单地使用可变目标.像这样:
If you only want to have different target versions you could simply use a variable target. Something like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>${TARGET_VERSION}</target>
<fork>true</fork>
</configuration>
</plugin>
这篇关于如何配置Maven以构建工件的两个版本,每个版本用于不同的目标JRE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!