基于轮廓的Maven包装类型

时间:2014-06-13 01:15:11

标签: maven pom.xml

我在stackoverflow上使用了一个找到的示例,它根据配置文件动态更改打包类型

Changing packaging based on active profile in pom

这是我的pom.xml的片段

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.scene7.is.qa</groupId>
<artifactId>jorogumo</artifactId>
<packaging>${packaging.type}</packaging>
...
<profile>
    <id>JorogumoReportingWebApp</id>
    <properties>
        <packaging.type>war</packaging.type>
        <final.name>jorogumo</final.name>
    </properties>
...

基于上面答案链接的upvotes,我假设这应该有效,但我在清理时收到错误

$ mvn clean
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.scene7.is.qa:jorogumo:0.0.1-SNAPSHOT     (/Users/xyz/working/_workspaces/Scene7/java/jorogumo/pom.xml) has 1 error
[ERROR]     Unknown packaging: ${packaging.type} @ line 10, column 13

我错过了什么吗?或者这是错误的方法? 我的最终目标是在Web应用程序和命令行jar之间共享公共java类。

1 个答案:

答案 0 :(得分:1)

我最终创建了一个默认的packing.type属性,其值为:

<modelVersion>4.0.0</modelVersion>
<groupId>com.scene7.is.qa</groupId>
<artifactId>jorogumo</artifactId>
<packaging>${packaging.type}</packaging>

...

<properties>
    <packaging.type>war</packaging.type>
</properties>

<profiles>
    <profile>
        <id>JorogumoReportingWebApp</id>
        <properties>
            <packaging.type>war</packaging.type>
            <final.name>jorogumo</final.name>
        </properties>
...