0
我有一个manve项目,我正在使用JAXB2插件从XSD模式生成java类。默认情况下,这些类是在目标文件夹中生成的,但我需要在src/main/java文件夹中生成它。如何更改从XSD生成Java的默认目录(JAXB)
我尝试添加行属性generateDirectory。这些类生成的,我想,但我不能导入他们在其他地方
这里是我的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类生成的文件:
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. 我在做什么错?
在生成的Java类检查包装声明。我怀疑它仍然是默认设置。虽然我从来没有使用jaxb maven插件,但是当我使用命令行工具生成类时,我必须指定目标目录和目标包名。 –
尝试在编译阶段之前明确执行插件目标。例如。 'maven clean org.jvnet.jaxb2.maven2:generate compile'。或者尝试通过在''标签内添加' compile '来尝试绑定插件的目标以构建阶段'compile'。 –
我尝试了两个答案:将generatePackage添加到配置中,并单独运行插件目标,并且它工作正常! –