الأسماك الزجاجية المدمجة: java.lang.noclassdeffounderror: java/util/serviceloader
-
04-10-2019 - |
سؤال
أحاول تضمين الأسماك الزجاجية داخل برنامج Java الخاص بي باستخدام واجهة برمجة التطبيقات المضمنة ، وأنا أستخدم Maven2 و 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>orh.highmark</groupId>
<artifactId>glassfish-test1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>glassfish-test1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<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>
</repository>
<repository>
<id>glassfish-repository</id>
<name>GlassFish Nexus Repository</name>
<url>http://maven.glassfish.org/content/groups/glassfish</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>orh.highmark.App</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
برنامج:
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
Server.Builder builder = new Server.Builder("test");
builder.logger(true);
Server server = builder.build();
}
}
لكن لسبب ما ، فإنه يعطيني دائمًا خطأً java.lang.NoClassDefFoundError: java/util/ServiceLoader
ها هو الإخراج
C:\Users\sunils\glassfish-tests\glassfish-test1>mvn -e exec:java
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building glassfish-test1
[INFO] task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
Hello World!
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null
java/util/ServiceLoader
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured whi
le executing the Java class. null
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured
while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:694)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:290)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NoClassDefFoundError: java/util/ServiceLoader
at org.glassfish.api.embedded.Server.getMain(Server.java:701)
at org.glassfish.api.embedded.Server.<init>(Server.java:290)
at org.glassfish.api.embedded.Server.<init>(Server.java:75)
at org.glassfish.api.embedded.Server$Builder.build(Server.java:185)
at org.glassfish.api.embedded.Server$Builder.build(Server.java:167)
at orh.highmark.App.main(App.java:14)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Sat May 08 02:55:03 IST 2010
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
لم أستطع تخمين مشكلتها في برنامجي أو مع API Glassfish. هل يمكن لأي شخص مساعدتي في فهم ما يحدث هنا وكيفية تصحيحه؟
شكرا على أي فكرة ..
المحلول
لقد ذهب هذا الخطأ بعد تثبيت إصدار جديد من JDK :)
لا تنتمي إلى StackOverflow