gpt4 book ai didi

java - SOAP Web 服务 - 无法从 XSD 生成类

转载 作者:行者123 更新时间:2023-11-30 05:52:14 25 4
gpt4 key购买 nike

我一直按照this中的确切步骤进行操作。教程。但是,无论我尝试什么,我都会遇到相同的错误。

我有两个应在 xsd 文件中生成的元素:GetStudentDetailsRequest 和 GetStudentDetailsResponse。这是我的 .xsd 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://in28minutes.com/students"
xmlns:tns="http://in28minutes.com/students" elementFormDefault="qualified">

<xs:element name="GetStudentDetailsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name= "id" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="GetStudentDetailsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name= "StudentDetails" type="tns:StudentDetails"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="StudentDetails">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="passportNumber" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:schema>

还有我的 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.in28minutes.springboot.soap.web.services.example</groupId>
<artifactId>spring-boot-tutorial-soap-web-services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Assignment4OnlineTrackerSystem</name>
<description>OnlineTrackerSystem</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>

</plugins>
</build>


</project>

如果我运行 mvn clean install 我会收到以下错误:

> Exception in thread "main" java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:147)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:117)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:425)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
at com.sun.tools.xjc.Driver.run(Driver.java:333)
at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:316)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 30 more
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BindingComponent.getClassSelector(BindingComponent.java:65)
at com.sun.tools.xjc.reader.xmlschema.ColorBinder.<init>(ColorBinder.java:62)
at com.sun.tools.xjc.reader.xmlschema.BindGreen.<init>(BindGreen.java:63)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 38 more
Caused by: java.lang.NoClassDefFoundError: javax/activation/MimeTypeParseException
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
at java.base/java.lang.Class.getConstructor0(Class.java:3343)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2554)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:100)
at com.sun.tools.xjc.reader.xmlschema.DefaultClassBinder.<init>(DefaultClassBinder.java:98)
at com.sun.tools.xjc.reader.xmlschema.ClassSelector.<init>(ClassSelector.java:214)
... 43 more
Caused by: java.lang.ClassNotFoundException: javax.activation.MimeTypeParseException
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 50 more

我看到了一些从 java 9 切换到 java 8 的建议,尝试不同的 jdk,但似乎没有任何效果。

最佳答案

使用正确的artifactId更新您的javax.activation依赖项。它是 javax.activation 而不仅仅是激活

<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.1</version>
</dependency>

否则,使用 jdk 1.8 可以解决该问题,因为它将使用 jdk 版本的 javax.activation。

使用 jdk1.8 和当前的 pom 进行测试,它有效导出 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/

但是,使用 jdk 1.9,您需要按上述方式更新 pom 才能使其正常工作。

关于java - SOAP Web 服务 - 无法从 XSD 生成类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53697815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com