我是maven的新手,这是我第一次使用maven-jaxb2-plugin从.xsd架构生成java类。
这是我的pom.xml:
<properties>
<java.source.version>1.6</java.source.version>
<java.target.version>1.6</java.target.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/schema</schemaDirectory>
<schemaIncludes>
<include>mySchema.xsd</include>
</schemaIncludes>
<generatePackage>it.mycompany.jaxb2</generatePackage>
<readOnly>true</readOnly>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- A few dependiences -->
</dependencies>
麻烦的是,当我尝试运行时
mvn install
我收到以下错误
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.3:generate failed: Illegal pattern character 'g'
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException: Illegal pattern character 'g'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
at com.sun.tools.xjc.Options.getPrologComment(Options.java:937)
at com.sun.tools.xjc.addon.episode.PluginImpl.run(PluginImpl.java:177)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:294)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.generateCode(XJC22Mojo.java:70)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:45)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:29)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:318)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:160)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
... 21 more
以这种方式配置Maven:
mvn --version Maven home:C:\ Program Files (x86)\ apache-maven-3.1.1 \ bin .. Java版本:1.6.0_45,供应商:Sun. Microsystems Inc. Java home:C:\ Program Files (x86)\ Java \ jdk1.6.0_45 \ jre默认语言环境:it_IT,平台编码: Cp1252操作系统名称:“windows 8”,版本:“6.2”,arch:“x86”,系列: “窗口”
我在哪里做错了?
答案 0 :(得分:0)
问题是maven-jaxb2-plugin默认使用的是jaxb-xjc的2.2.6版本,这个版本有一些问题
默认语言环境:it_IT
但仅适用于美国区域设置。然后我添加了以下对我的pom的依赖
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.5</version>
</dependency>
现在一切正常。