我正在尝试将我的 SpringBoot maven 项目更新到 Java 17。
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)
我定义了工作 maven-jaxb2-plugin 插件,它从 XSD 文件成功创建了 java 类。
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>my_schema</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/my/files</schemaDirectory>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/my/files</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<args>
<arg>-extension</arg>
<arg>-Xnamespace-prefix</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但自从java和插件升级后我就不能这样做了。
我定义了插件必要的依赖项:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但在 Maven 构建过程中我仍然收到未知错误:
Oct 19, 2021 10:07:06 PM com.sun.xml.bind.v2.runtime.reflect.opt.Injector <clinit> …Run Code Online (Sandbox Code Playgroud) 我有一个maven插件(jaxb2),我需要提供一个jvm arg.我不认为有一个标签可以在它的pom中添加jvm args.
我知道我可以在命令行传入jvm args,例如: mvn clean install -Djavax.xml.accessExternalSchema=all
是否可以在pom中设置此jvm arg,以便我不必每次都在命令行中键入它?
(除此之外 - 这个jvm arg是必需的,以便它可以与JAVA-8一起使用.它适用于JAVA-7)
在Helios/m2eclipse下,当我生成jaxb源时,当我执行"更新项目配置"时,它们将被放在Eclipse源路径上.
Indigo/m2e(2011年6月22日首次发布)不会发生这种情况.我需要做些什么来解决这个问题?
我正在使用标准的maven-jaxb2-plugin,版本0.75.
我有几十个和几十个.xsd我想自动生成代码的文件.当我尝试同时生成所有文件时,一些文件具有重复的名称.
我专注于尝试让其中的两个工作.
当我得到这两个工作时,我会解决剩下的问题.但我现在只关注其中的两个文件.我无法控制它们,它们来自供应商并遵循"标准",因此编辑它们不是出于多种原因的选择.
我正在使用它maven-jaxb2-plugin来处理这些文件.
我添加了一个binding.xjb文件,如mat b我在网站上找到的答案和其他说明中的链接所示.但我得到以下错误,没有输出.
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="2.1"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">
<jxb:bindings schemaLocation="mac-3.4.xsd">
<jxb:schemaBindings>
<jxb:package name="my.company.mac"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="mac-stylesheet-3.4.xsd">
<jxb:schemaBindings>
<jxb:package name="my.company.stylesheet"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
出现以下错误
[ERROR] Error while parsing schema(s).Location [ file:/C:/Users/Jarrod%20Roberson/Projects/spa-tools/spa-lib/src/main/sc
hema/mac-stylesheet-3.4.xsd{165,33}].
org.xml.sax.SAXParseException: 'halign' is already defined
Run Code Online (Sandbox Code Playgroud)
令人不快的元素是:(还有很多其他的只是第一个发生冲突的因素)
<xsd:simpleType name="halign">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="left" />
<xsd:enumeration value="center" />
<xsd:enumeration value="right" />
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
并且在每个.xsd文件中都是相同的,如何使用仅生成一个类或者将每个类生成到其自己的包命名空间中来解决此重复问题? …
我试图从wsdl文件生成源代码,但我在我的pom.xml上遇到错误,我认为这可能是我的问题?下面是我从我的pom和我的pom文件中得到的错误.我也无法用"mvn clean install"构建项目.我似乎只是因为没有真正原因而得到错误.
生成标记的错误:
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/codemodel/CodeWriter
-----------------------------------------------------
realm = plugin>org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3-715230752
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/Windows/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin/0.12.3/maven-jaxb2-plugin-0.12.3.jar
urls[1] = file:/C:/Users/Windows/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-core/0.12.3/maven-jaxb2-plugin-core-0.12.3.jar
urls[2] = file:/C:/Users/Windows/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar
urls[3] = file:/C:/Users/Windows/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar
urls[4] = file:/C:/Users/Windows/.m2/repository/com/sun/org/apache/xml/internal/resolver/20050927/resolver-20050927.jar
urls[5] = file:/C:/Users/Windows/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
urls[6] = file:/C:/Users/Windows/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
urls[7] = file:/C:/Users/Windows/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb22-plugin/0.12.3/maven-jaxb22-plugin-0.12.3.jar
urls[8] = file:/C:/Users/Windows/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
urls[9] = file:/C:/Users/Windows/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
urls[10] = file:/C:/Users/Windows/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]] …Run Code Online (Sandbox Code Playgroud) 我试图使用相同的生成类,但在单独的包中.所以结构看起来应该是这样的:
com.test.common
-commonType.java
com.test.A
-objectA.java
com.test.B
-objectB.java
Run Code Online (Sandbox Code Playgroud)
但我一直这样:
com.test.common
-commonType.java
com.test.A
-objectA.java
-commonType.java
com.test.B
-objectB.java
-commonType.java
Run Code Online (Sandbox Code Playgroud)
我的common.xsd看起来像这样:
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified" version="1.0"
targetNamespace="http://test.com/magic/common"
xmlns="http://test.com/magic/common"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<xs:complexType name="CommonType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
objectA.xsd看起来像
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified" version="1.0"
targetNamespace="http://test.com/magic/objectA"
xmlns:common="http://test.com/magic/common"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<xs:complexType name="ObjectA">
<xs:sequence>
<xs:element name="size" type="xs:string" />
<xs:element name="commonA" type="common:CommonType" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
而objectB.xsd看起来像:
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified" version="1.0"
targetNamespace="http://test.com/magic/objectB"
xmlns:common="http://test.com/magic/common"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<xs:complexType name="ObjectB">
<xs:sequence>
<xs:element name="version" type="xs:string" /> …Run Code Online (Sandbox Code Playgroud) 我想将我的Maven2构建文件切换为gradle.使用gradle从WSDL + XSD生成java类似乎没有进一步记录,没有gradle插件.我使用maven的以下配置并搜索gradle的等效项.
<!-- plugin for generating the classes from the WSDL+XSD -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.3</version>
<executions>
<execution>
<id>app1-stub-generation</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.build.directory}/wsdl/app1</schemaDirectory>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
<generatePackage>org.app1.ws.generated</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/app1</generateDirectory>
<strict>true</strict>
</configuration>
</execution>
<execution>
<id>app2-v1-stub-generation</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>v1/*.xsd</include>
</schemaIncludes>
<generatePackage>org.app2.ws.generated.v1</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/v1</generateDirectory>
<strict>true</strict>
</configuration>
</execution>
<execution>
<id>app2-v2-stub-generation</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>v2/*.xsd</include>
</schemaIncludes>
<generatePackage>org.app2.ws.generated.v2</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/v2</generateDirectory>
<strict>true</strict>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我浪费了很多天的时间试图弄清楚,看起来非常简单的事情(从 WSDL/XSD 生成代码)怎么会如此极其复杂。有什么办法吗?我觉得我已经尝试过所有这些,在不同的版本中使用不同的 jaxb 绑定和不同版本的实现
我尝试使用以下插件:
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)
没有插件能够输出 jakarta 注释并且总是失败,因为某些 javax.xml 注释或 com.sun.* 类丢失。此时我正在考虑自己编写一个插件,因为这很荒谬,我只需要一个简单的 POJO 和一些注释,并且不想在 xsd 或 wsdl 更改时自己编写它们。
你们在 Jakarta 4 中使用过哪些方法?
xml maven-jaxb2-plugin jaxb2-maven-plugin jaxws-maven-plugin
我正在使用jaxb2 xjc插件从a生成java文件XSD.因此,我曾经按如下方式配置我的pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.mypackage.model</packageName>
<schemaDirectory>${basedir}/src/main/resources/XSD</schemaDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我将我的开发环境改为Eclipse Indigo,这不再适用了.错误说:"生命周期配置未涵盖插件执行".我知道我必须以不同的方式定义我的插件的执行,以便它在我的新环境中工作.
我按照本页上的说明M2E插件执行未涵盖但执行generate-sources阶段时未生成源文件.
任何人都可以告诉我如何精确重构我的pom,以便我的文件正确生成?
谢谢你的帮助!
我使用jaxb2-maven-plugin从给定的XSD生成JaxB-Classes.它工作正常.但是现在我想在生成的Classes中使用java.util.Optional.但是JaxB生成了没有Optionals的类.所以我被迫对每个变量进行Null-Check.
有没有人知道如何配置jaxb2-maven-plugin来使用java.util.Optional?
谢谢你的帮助!