【发布时间】:2018-06-09 21:29:25
【问题描述】:
我尝试使用从jaxb2-maven-plugin 生成的类构建一个 Maven 项目。
考虑以下最小的 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>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>test</packageName>
<sources>
<source>src/main/resources/schema.xsd</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
src/main/resources/schema.xsd 中的这个最小架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" vc:maxVersion="1.1" vc:minVersion="1.0" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>
调用mvn clean compile 时,项目按预期构建。但是当我使用包含.. 的路径指定文件时,会出现以下错误。当使用(相对或绝对)路径没有..时,一切都很好。
C:\dev\test>mvn -f ..\test\pom.xml clean compile
[...]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /C:/dev/test/target/generated-sources/jaxb/test/ObjectFactory.java:[32,8] duplicate class: test.ObjectFactory
我怎样才能摆脱这个错误并使用mvn -f <some path containing ".."> 构建我的项目?
【问题讨论】:
-
首先你为什么这样称呼maven?这是多模块构建吗?为什么不切换到正确的目录并像
mvn clean compile这样简单地调用 Maven? -
@khmarbaise 我在脚本中调用 Maven - 由于该脚本中还有其他几个相对路径,我不想更改位置。同时,我发现,我可以使用绝对路径(没有 ..)并且一切都按预期工作。但是我很好奇为什么这不起作用。
标签: maven maven-compiler-plugin jaxb2-maven-plugin