ClassNotFoundException: javax.xml.ws.Endpoint despite having the correct(?) maven dependency and only in CLI

huangapple go评论74阅读模式
英文:

ClassNotFoundException: javax.xml.ws.Endpoint despite having the correct(?) maven dependency and only in CLI

问题

我遇到了将一个 WebService 恢复在线状态的问题。直到现在它还不是一个 Maven 项目,但我决定使用 Maven 依赖项来进行重构。在此之前,所有的依赖项都是手动复制的。因此,我的 pom.xml 文件看起来像这样:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.iifleuchten.auth.webservice</groupId>
	<artifactId>AuthService</artifactId>
	<version>0.9</version>
	<name>AuthService</name>
	<properties>
		<maven.compiler.source>1.6</maven.compiler.source>
		<maven.compiler.target>1.6</maven.compiler.target>
	</properties>
	<dependencies>
		<!-- jax-ws maven dependency -->
		<dependency>
			<groupId>javax.xml.ws</groupId>
			<artifactId>jaxws-api</artifactId>
			<version>2.3.1</version>
		</dependency>
		<dependency>
			<groupId>com.sun.xml.ws</groupId>
			<artifactId>jaxws-rt</artifactId>
			<version>2.1.3</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api -->
		<dependency>
			<groupId>javax.jws</groupId>
			<artifactId>javax.jws-api</artifactId>
			<version>1.1</version>
		</dependency>
		<dependency>
			<groupId>com.sun.xml.messaging.saaj</groupId>
			<artifactId>saaj-impl</artifactId>
			<version>1.5.1</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>3.2.0</version>
				<configuration>
					<archive>
						<manifest>
							<mainClass>com.iifleuchten.auth.webservice.AuthPublisher</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

我正在使用 Eclipse,并且可以在 Eclipse 中运行 WebService。它可以工作,服务是可用的(在同一项目内使用另一个小程序进行测试,该程序调用本地 WebService),尽管在运行服务时我确实收到了一个警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/home/manoca/.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.6/jaxb-impl-2.1.6.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

当我通过 Eclipse 上下文菜单执行 Maven 安装操作时,构建正常工作并创建了 JAR 文件。然而,当我在命令行中使用 java -jar AuthService.jar 调用它时,这个 JAR 文件不起作用。我在那里收到一个类找不到的异常。它找不到 Endpoint 类:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/Endpoint

这是它遇到问题的代码部分:

Endpoint.publish("http://0.0.0.0:7779/ws/auth", authImpl);

我认为来自 javax.jws 包的其他类应该可以工作,因为在执行 WebService 相关的所有实现和相应的注解之前,Endpoint.publish 不应该引发任何异常?长话短说:这是我第一次使用 Maven 相关的尝试,在经过几个小时的尝试后,我真的不知道该怎么办了。非常感谢任何建议;)

英文:

I am having troubles bringing a WebService back online. It was not a Maven Project till now, but I decided to move on an bring it in shape with Maven dependencies. Before that point all of the dependencies were copied manually. So my pom.xml looks like this:

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;com.iifleuchten.auth.webservice&lt;/groupId&gt;
	&lt;artifactId&gt;AuthService&lt;/artifactId&gt;
	&lt;version&gt;0.9&lt;/version&gt;
	&lt;name&gt;AuthService&lt;/name&gt;
	&lt;properties&gt;
		&lt;maven.compiler.source&gt;1.6&lt;/maven.compiler.source&gt;
		&lt;maven.compiler.target&gt;1.6&lt;/maven.compiler.target&gt;
	&lt;/properties&gt;
	&lt;dependencies&gt;
		&lt;!-- jax-ws maven dependency --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.xml.ws&lt;/groupId&gt;
			&lt;artifactId&gt;jaxws-api&lt;/artifactId&gt;
			&lt;version&gt;2.3.1&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
			&lt;artifactId&gt;jaxws-rt&lt;/artifactId&gt;
			&lt;version&gt;2.1.3&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.jws&lt;/groupId&gt;
			&lt;artifactId&gt;javax.jws-api&lt;/artifactId&gt;
			&lt;version&gt;1.1&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.xml.messaging.saaj&lt;/groupId&gt;
			&lt;artifactId&gt;saaj-impl&lt;/artifactId&gt;
			&lt;version&gt;1.5.1&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
				&lt;version&gt;3.2.0&lt;/version&gt;
				&lt;configuration&gt;
					&lt;archive&gt;
						&lt;manifest&gt;
							&lt;mainClass&gt;com.iifleuchten.auth.webservice.AuthPublisher&lt;/mainClass&gt;
						&lt;/manifest&gt;
					&lt;/archive&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;
&lt;/project&gt;

I am using eclipse, and I can run the webservice inside eclipse. It works and the service is available (tested with another small program within the same project, which calls the local webservice) although I do get a warning when running the service:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/home/manoca/.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.6/jaxb-impl-2.1.6.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

When I do the maven install thing via the eclipse context menu the build works fine and the jar gets created. However, this jar does not work in the cli when calling it like java -jar AuthService.jar. I get a class not found exception there. He can't find the Endpoint class:

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/xml/ws/Endpoint

here's the code, where it stumbles upon:

Endpoint.publish(&quot;http://0.0.0.0:7779/ws/auth&quot;, authImpl);

I think other classes from for example the javax.jws package do work, as all the implementation of the WebService stuff and the corresponding annotations should "happen" before it comes to the Endpoint.publish and this does not cause any exceptions? Long story short: this are my first Maven related experiments and after a few hours now, I am really out of ideas what to do. Any suggestions are highly appreciated ClassNotFoundException: javax.xml.ws.Endpoint despite having the correct(?) maven dependency and only in CLI

答案1

得分: 0

非常感谢您的提示。我现在开始更加理解整个情况。这个链接真的提供了一些很有用的信息,尽管我一开始有些愚蠢:
https://medium.com/@randilfernando/when-to-use-maven-jar-maven-assembly-or-maven-shade-ffc3f76ba7a6

英文:

Thanks a lot for the hint. I do begin to understand the whole deal a lot more now. This link really has some good information although I was just stupid in the first place:
https://medium.com/@randilfernando/when-to-use-maven-jar-maven-assembly-or-maven-shade-ffc3f76ba7a6

huangapple
  • 本文由 发表于 2020年9月2日 02:13:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63693255.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定