我试图将javax.persistence.Id添加为字段的注释,并通过Maven JAXB插件生成Java对象.但是我遇到javax.persistence.id的类找不到异常我确实确保javax.persistence包含在maven依赖项中,我看到maven将它作为依赖项,但是当我运行jaxb插件时它将无效.
<xsd:complexType name="MyTable">
<xsd:sequence>
<xsd:element name="id" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType><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)
这是我的相关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)我正在尝试让我的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
我有一个问题,当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" />)时,默认值按预期工作.
与此相反,插件 …
我在发送简单的 SOAP 请求并在我的 java 项目中获得响应时遇到问题。
我对通过 Java 执行此操作仍然很陌生,因此我一直在查看本教程,因为我还在项目的其余部分使用了 spring-boot。
目前我收到此错误(我确实必须删除细节,因为与公司相关并替换为通用字符串以便将它们粘贴在这里。我不得不删除我的实际 wsdl 和实际主机名):
[INFO] --- maven-jaxb2-plugin:0.12.3:generate (default) @ dcc-vm-validation ---
[INFO] Up-to-date check for source resources [[myWsdl, file:pom.xml]] and taret resources [[]].
[WARNING] The URI [myWsdl] seems to represent an absolute HTTP or HTTPS URL. Getting the last modification timestamp is only possible if the URL is accessible and if the server returns the [Last-Modified] header correctly. This method is not reliable and is likely to fail. In this …Run Code Online (Sandbox Code Playgroud) 我在这方面做了很多阅读。看起来非常的正直。如果您看到 pom 文件,您可以看到它不是从远程 URL 创建类文件,而是该文件必须是项目的一部分。注释掉的配置有效...找到 WSDL 并创建正确的文件。当我尝试在本地驱动它时,没有任何效果。我展示的版本是我尝试使用 maven ${project.basedir} 变量的地方。我尝试过“/src/main/java”、“src/main/java”,对路径进行硬编码。我该怎么做呢?我已经尝试了我看到的所有示例。这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.mycompany</groupId>
<artifactId>abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>abc</name>
<description>consume soap</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.mycompany.abc.domain</packageName>
<wsdl>true</wsdl>
<xmlschema>false</xmlschema>
<schemaFiles>abc.wsdl</schemaFiles>
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>true</clearOutputDir>
</configuration> …Run Code Online (Sandbox Code Playgroud) 我已经在我的项目中安装了 JAXB2 maven 插件。从我的 SOAP WebService 生成的 .WSDL 文件位于项目目录中,但我希望 JAXB2 直接使用 WSDL URL 而不是使用 .wsdl 文件。
我是 Maven 新手,我创建了一个 Maven 项目,其中只有模式。我的目的是将我的所有 XSD 保留在这个项目中,编译并创建 JAXB 生成的类的 jar。下面是我的POM
<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>
<groupId>com.ads</groupId>
<artifactId>adsSchema</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>adsSchema</name>
<pluginRepositories>
<pluginRepository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<!-- jaxb plugin -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>adsSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<param>-npa</param>
</args>
<!-- the package for the generated java classes -->
<generatePackage>com.ads.beans</generatePackage>
<npa>true</npa>
<!-- include the following schemas only; by default all …Run Code Online (Sandbox Code Playgroud) 旧站点上有一些文档, 但不清楚在使用绑定文件时如何应用配置。
这是我用来向生成的 JAXB 对象添加 toString、equals 等的 Maven 配置。
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
<args>
<arg>-Xfluent-api</arg>
<arg>-XautoNameResolution</arg>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-fluent-api</artifactId>
<version>3.0</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
</plugins>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我想使用 Affilinet API。其中一个 WSDL 文件位于此处:
我使用这个 Maven 插件来生成源代码:
我的 Pom.xml 插件配置:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.logon</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/Logon.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/PublisherInbox.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema3-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/AccountService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
因此,在编译时,我收到错误:
com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 2127; Two declarations cause a …Run Code Online (Sandbox Code Playgroud) 我是 Spring Boot 的新手,不熟悉 SOAP Web 服务的工作原理。
在 pom 文件中我有以下配置:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>calculator.wsdl</generatePackage>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<schemas>
<schema>
<url>http://www.dneonline.com/calculator.asmx?WSDL</url>
</schema>
</schemas>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
'generatePackage' 在 target/ generatedsources/calculator/wsdl 中创建源文件。
我希望它们在“{$basedir}/src/java”中生成,以便我可以在代码中使用这些服务。我尝试将上述条目放入“generatePackage”标签中。但文件仍然在“目标”中生成。
任何帮助将不胜感激。谢谢!
java ×4
jaxb ×4
maven ×4
jaxb2-basics ×2
soap ×2
xsd ×2
affiliate ×1
jpa-2.0 ×1
maven-3 ×1
self-signed ×1
soap-client ×1
spring-boot ×1
xjc ×1