标签: jaxb2-maven-plugin

无法通过maven jaxb插件生成注释

我试图将javax.persistence.Id添加为字段的注释,并通过Maven JAXB插件生成Java对象.但是我遇到javax.persistence.id的类找不到异常我确实确保javax.persistence包含在maven依赖项中,我看到maven将它作为依赖项,但是当我运行jaxb插件时它将无效.

  1. 这是我的XML <xsd:complexType name="MyTable"> <xsd:sequence> <xsd:element name="id" type="xsd:int"/> </xsd:sequence> </xsd:complexType>
  2. 这是我的binding.xjb文件
<jaxb:bindings version="2.1"
   xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
   xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox">

<jaxb:bindings schemaLocation="mytable.xsd">

  <jaxb:bindings node="xs:complexType[@name='MyTable']/xs:sequence/xs:element[@name='id']">
       <annox:annotate target="field">
             <annox:annotate annox:class="javax.persistence.Id"/>
       </annox:annotate>
  </jaxb:bindings> 

</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)

  1. 这是我的相关Pom.xml

    <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.9</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics-annotate</artifactId>
            <version>0.6.4</version>
        </dependency>
        <dependency>
         <groupId>javax.persistence</groupId>
         <artifactId>persistence-api</artifactId>
         <version>1.0.2</version>
         <scope>provided</scope>
    </dependency>
     </dependencies>
    
     <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.8.3</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <configuration>
                            <forceRegenerate>true</forceRegenerate>
                            <schemaDirectory>myschema</schemaDirectory>
                            <bindingIncludes>
                                <include>binding.xjb</include>
                            </bindingIncludes>
                            <extension>true</extension>
                           <args>
                            <arg>-Xvalue-constructor</arg>
                            <arg>-XtoString</arg>
                            <arg>-Xequals</arg>
                            <arg>-XhashCode</arg>
                            <arg>-Xcopyable</arg> …
    Run Code Online (Sandbox Code Playgroud)

xsd maven-3 jpa-2.0 maven-jaxb2-plugin jaxb2-maven-plugin

2
推荐指数
1
解决办法
6267
查看次数

JAXB等于和Hashcode:给出错误

我正在尝试让我的pom.xml在我的JAXB对象上生成hashCode()和equals methods().

<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">
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>org.jvnet.jaxb2_commons</groupId>
        <artifactId>jaxb2-commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <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>
                <extension>true</extension>
                <args>
                    <arg>-XtoString</arg>
                    <arg>-Xequals</arg>
                    <arg>-XhashCode</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.2</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

这会产生以下错误......

package org.jvnet.jaxb2_commons.lang does not exist
package org.jvnet.jaxb2_commons.locator does not exist
package org.jvnet.jaxb2_commons.locator.util does not exist
cannot find symbol symbol: class Equals
cannot find symbol symbol: class HashCode
cannot find symbol symbol: …
Run Code Online (Sandbox Code Playgroud)

jaxb maven maven-jaxb2-plugin jaxb2-basics jaxb2-maven-plugin

2
推荐指数
1
解决办法
1万
查看次数

jaxb2-maven-plugin为默认值= INF的双精度生成无效源

我有一个问题,当XSD文件包含双精度的默认值时,jaxb2-maven-plugin会生成无效的源代码.

我使用jaxb2-maven-plugin(org.codehaus.mojo)1.5版:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
    </configuration>
    <executions>
        <execution>
            <id>analysis_jaxb</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <clearOutputDir>false</clearOutputDir>
                <schemaFiles>Analysis.xsd</schemaFiles>
                <packageName>xx.xx.xx.analysis</packageName>
                <generateDirectory>${project.build.directory}/generated-sources/jaxb/analysis</generateDirectory>
                <verbose>true</verbose>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

从以下XSD文件生成Java Source:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="MinMax" type="MinMaxType"/>

    <xs:complexType name="MinMaxType">
        <xs:attribute name="min" type="xs:double" default="-INF" />
        <xs:attribute name="max" type="xs:double" default="INF" />
    </xs:complexType>

</xs:schema> 
Run Code Online (Sandbox Code Playgroud)

生成的Java文件包含以下方法:

public double getMin() {
    if (min == null) {
        return -InfinityD; //UNDEFINED
    } else {
        return min;
    }
}
Run Code Online (Sandbox Code Playgroud)

该字段-InfinityD未在任何地方定义.

使用布尔值(例如<xs:attribute name="minInclusive" type="xs:boolean" default="false" />)时,默认值按预期工作.

与此相反,插件 …

xsd jaxb maven maven-jaxb2-plugin jaxb2-maven-plugin

2
推荐指数
1
解决办法
877
查看次数

XJC Maven插件(jaxb2-maven-plugin)Java 11迁移问题

我目前正在从事Java 11迁移项目,其中jaxb2-maven-plugin已用于XJC任务。由于JDK 11版本中没有XJC可执行文件,因此出现以下错误。

    [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc-schema1) on project paymaster-service: Execution xjc-schema1 of goal org.codehaus.mojo:jaxb2-maven-plugin:2.2
:xjc failed: A required class was missing while executing org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc: com/sun/codemodel/CodeWriter
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:jaxb2-maven-plugin:2.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/voletis/.m2/repository/org/codehaus/mojo/jaxb2-maven-plugin/2.2/jaxb2-maven-plugin-2.2.jar
[ERROR] urls[1] = file:/C:/Users/voletis/.m2/repository/javax/xml/bind/jaxb-api/2.2.11/jaxb-api-2.2.11.jar
[ERROR] urls[2] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-core/2.2.11/jaxb-core-2.2.11.jar
[ERROR] urls[3] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
[ERROR] urls[4] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
[ERROR] urls[5] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-jxc/2.2.11/jaxb-jxc-2.2.11.jar
[ERROR] urls[6] = file:/C:/Users/voletis/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M3/qdox-2.0-M3.jar
[ERROR] urls[7] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[8] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[9] = file:/C:/Users/voletis/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] …
Run Code Online (Sandbox Code Playgroud)

java jaxb maven-plugin jaxb2-maven-plugin

2
推荐指数
3
解决办法
3688
查看次数

Spring boot - 服务器无法识别 HTTP Header SOAPAction 的值

我想使用 jaxb 使用肥皂服务。jaxb 生成的请求是

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
      <ns2:Add xmlns:ns2="http://tempuri.org/">
         <ns2:intA>10</ns2:intA><ns2:intB>20</ns2:intB>
      </ns2:Add>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

但是响应是标题中所述的soap异常。

Caused by: org.springframework.ws.soap.client.SoapFaultClientException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
Run Code Online (Sandbox Code Playgroud)

下面是我的肥皂配置代码。源码示例:https : //howtodoinjava.com/spring-boot/spring-soap-client-webservicetemplate/

    public class ConsumeSoapApplication {
            public static String wsdlurl = "http://www.dneonline.com/calculator.asmx?wsdl";
            public static void main(String[] args) {
                try {
                    JAXBContext.newInstance(com.dxc.service.soap.service.calc.ObjectFactory.class.getPackage().getName(),
                            com.dxc.service.soap.service.calc.ObjectFactory.class.getClassLoader());
                } catch (JAXBException e) {
                    // TODO Auto-generated catch block …
Run Code Online (Sandbox Code Playgroud)

soap web-services jaxb jaxb2-maven-plugin spring-boot

0
推荐指数
1
解决办法
2487
查看次数