简体   繁体   English

如何识别不同Java版本的maven工件?

[英]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依赖于AB

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.

相关问题 如何配置Maven以构建两个版本的工件,每个版本用于不同的目标JRE - How to configure Maven to build two versions of an artifact, each one for a different target JRE 如何从java maven项目中的两个不同版本的jar加载类的两个版本? - How to load two versions of a class from two different versions of jars in a java maven project? Maven:项目和插件的不同Java编译器版本 - Maven: different java compiler versions for project and plugin 让 jenkins 和 maven 使用不同的 java 版本 - Making jenkins and maven use different java versions 我自己的Maven插件如何获得Maven工件的可用版本? - How can my own Maven plugin get the available versions of a Maven artifact? 使用Maven工件API ComparableVersion比较版本 - Comparing versions with maven artifact api ComparableVersion Maven项目取决于同一工件的两个版本 - Maven project depending on two versions of the same artifact 使用Maven,如何使用一个不同的.java文件构建两个版本的Java项目? - With Maven how do I build two versions of a Java project with just one different .java file? maven-jar-plugin:如何为测试创建不同的工件名称? - maven-jar-plugin: How to create a different artifact name for tests? Java Maven-如果两个第三方依赖于库的不同版本,如何解析版本 - Java Maven - How to resolve the version if two third parties depend on different versions of a library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM