我创建了一个简单的Maven项目,该项目使用Jaxb将模式编译为Java文件。一切似乎都在起作用,但问题是生成的包名是倒退的:
我的Xml架构如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://com.mystuff.jaxb.inventorycontrol.inventorydata"
targetNamespace="http://com.mystuff.jaxb.inventorycontrol.inventorydata" elementFormDefault="qualified" version="1.0.0">
....
....
<xs:complexType name="InventoryItemListType">
<xs:sequence>
<xs:element name="Item" type="InventoryItemType" />
</xs:sequence>
</xs:complexType>
</xs:schema>
命名空间 http://com.mystuff.jaxb.inventorycontrol.inventorydata 以com开头,以inventorydata结束,所以我认为这将是包/文件夹顺序:
com\mystuff\jaxb\inventorycontrol\inventorydata
但我的倒退结束了:
inventorydata\inventorycontrol\jaxb\mystuff\com\
不确定在我的pom.xml上粘贴一些是否有点过分,但我猜它不会受到伤害。
这是我的根pom:
<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">
....
<packaging>pom</packaging>
<groupId>com.mystuff.jaxb</groupId>
<artifactId>inventorycontrol</artifactId>
<version>1.0-SNAPSHOT</version>
....
<build>
<pluginManagement>
<plugins>
....
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven-jaxb2-plugin-version}</version>
<configuration>
<catalog>src/main/resources/catalog.xml</catalog>
<catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
<extension>true</extension>
<schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>inventorydata</module>
</modules>
</project>
这是具有架构的模块的pom:
<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">
....
<packaging>pom</packaging>
<parent>
<groupId>com.mystuff.jaxb</groupId>
<artifactId>inventorycontrol</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mystuff.jaxb.inventorycontrol</groupId>
<artifactId>inventorydata</artifactId>
....
<build>
<plugins>
....
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
_Update _ 的
当我创建项目时,我基本上将架构/ pom文件从旧项目复制/粘贴到这个新项目。旧项目架构如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cmv.com/java/maven/jaxb/schemas/core/types"
targetNamespace="http://www.cmv.com/java/maven/jaxb/schemas/core/types" elementFormDefault="qualified" version="1.0.0">
....
<xs:complexType name="PoundsWeightType">
<xs:sequence>
<xs:element name="Value" type="PositiveFloat" />
</xs:sequence>
<xs:attribute name="Units" type="UnitsEnum" use="required" fixed="Lbs" />
</xs:complexType>
</xs:schema>
我为该项目生成的包是:
com\cmv\java\maven\jaxb\schemas\core\types
这就是我所期望的。
答案 0 :(得分:2)
Java组件,软件包等...使用反向dns命名。您正在以DNS格式指定命名空间,这意味着您打算将其撤消。
作为网址写出的名称空间com.mystuff.jaxb.inventorycontrol.inventorydata
将是:http://inventorydata.inventorycontrol.jaxb.mystuff.com