如何更改从 XSD 生成 Java 的默认目录 (JAXB)
How to change default directory for generating Java from XSD (JAXB)
我有一个 manve 项目,我正在使用 JAXB2 插件从 XSD 模式生成 java class。默认情况下,classes是在目标文件夹中生成的,但我需要在src/main/java文件夹中生成它。
我尝试添加行属性 generateDirectory。 classes在我想要的地方生成,但我不能在其他地方导入它们
这是我的 pom.xml:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
<generateDirectory>src/main/java/com/evol/foo/generated-bar-sources</generateDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
我的 java class 使用生成的文件:
package com.evol.foo.service;
import com.evol.foo.generated-bar-sources; //error: cannot resolve symbol generated
@Component
public class XMLParserService {
//ComplexType cannot be found
public ComplexType parseErrorFile(String filePath) throws JAXBException {
File file = new File(filePath);
JAXBContext jaxbContext = JAXBContext.newInstance(ComplexType.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
ComplexType errFile = (ComplexType)
jaxbUnmarshaller.unmarshal(file);
return errFile;
}
我正在使用 Intellij Comunity 和 Java 8。
我做错了什么?
我认为应该使用 generatePackage
在 generateDirectory
之外声明包:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
<generateDirectory>src/main/java</generateDirectory>
<generatePackage>com.evol.foo.generated-bar-sources</generatePackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
我有一个 manve 项目,我正在使用 JAXB2 插件从 XSD 模式生成 java class。默认情况下,classes是在目标文件夹中生成的,但我需要在src/main/java文件夹中生成它。
我尝试添加行属性 generateDirectory。 classes在我想要的地方生成,但我不能在其他地方导入它们
这是我的 pom.xml:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
<generateDirectory>src/main/java/com/evol/foo/generated-bar-sources</generateDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
我的 java class 使用生成的文件:
package com.evol.foo.service;
import com.evol.foo.generated-bar-sources; //error: cannot resolve symbol generated
@Component
public class XMLParserService {
//ComplexType cannot be found
public ComplexType parseErrorFile(String filePath) throws JAXBException {
File file = new File(filePath);
JAXBContext jaxbContext = JAXBContext.newInstance(ComplexType.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
ComplexType errFile = (ComplexType)
jaxbUnmarshaller.unmarshal(file);
return errFile;
}
我正在使用 Intellij Comunity 和 Java 8。 我做错了什么?
我认为应该使用 generatePackage
在 generateDirectory
之外声明包:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
<generateDirectory>src/main/java</generateDirectory>
<generatePackage>com.evol.foo.generated-bar-sources</generatePackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>