[英]How to identify maven artifact for different Java versions?
I have a maven project that is compiled for both Java 1.7 and for Java 1.6. 我有一个为Java 1.7和Java 1.6编译的maven项目。 The 1.7 jar is the default artifact, but I don't know which how to identify the 1.6 jar.
1.7 jar是默认的工件,但我不知道如何识别1.6 jar。
I could add a suffix to the artifact id, to the version, or set a classifier. 我可以为工件id,版本添加后缀,或者设置分类器。 Which is the preferred way?
哪种方式首选? What happens when another project
A
depends on the 1.7 jar, project B
depends on the 1.6 jar, and project C
depends on A
and B
? 当另一个项目
A
依赖于1.7 jar时,会发生什么,项目B
依赖于1.6 jar,而项目C
依赖于A
和B
?
OK, so after some reading, I think classifiers are the way 好的,所以经过一些阅读后,我认为分类器就是这样
From the maven docs 来自maven文档
classifier: The classifier allows to distinguish artifacts that were built from the same POM but differ in their content.
分类器:分类器允许区分从同一个POM构建但内容不同的工件。 It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
它是一些可选的任意字符串 - 如果存在 - 将附加到版本号之后的工件名称。 As a motivation for this element, consider for example a project that offers an artifact targeting JRE 1.5 but at the same time also an artifact that still supports JRE 1.4.
作为此元素的动机,请考虑一个项目,该项目提供针对JRE 1.5的工件,但同时也是一个仍支持JRE 1.4的工件。 The first artifact could be equipped with the classifier jdk15 and the second one with jdk14 such that clients can choose which one to use.
第一个工件可以配备分类器jdk15,第二个工件配备jdk14,以便客户端可以选择使用哪个。
Then to solve the issue of forcing one jar over an other, in project C's
pom, use the <dependencyManagement>
section and specify the classifier there. 然后在项目
C's
pom中解决强制一个jar超过另一个jar的问题,使用<dependencyManagement>
部分并在那里指定分类器。
Hope this helps 希望这可以帮助
you have to declare in pom.xml file the java compiler version: 你必须在pom.xml文件中声明java编译器版本:
<build>
<finalName>skremm_mobile_web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.