Java Webstart ClassNotFoundException WebSockets

时间:2018-11-26 17:58:32

标签: java classnotfoundexception java-web-start jnlp maven-webstart-plugin

我正在尝试将使用多个模块的相当复杂的应用程序转换为使用webstart而不是等效的C#。 (我知道不建议使用webstart,并且将不使用。这是一个临时解决方案。)我正在使用maven-webstart-plugin,并且在尝试加载Java-Websockets库时似乎遇到ClassNotFoundException的问题。问题是websockets包含在其中一个应用程序模块的POM文件中(我什至尝试将其添加为主应用程序中的显式依赖项)。它确实进入了JNLP文件,并且肯定在webstart插件生成的lib文件夹中,因此我很困惑为什么找不到它。任何帮助将不胜感激。我已经尝试了所有我能想到的一切(主项目中的显式依赖关系,将对websockets的调用移至主应用程序中-它只是将异常移至该处)。我还启用了Java调试器,以便在加载网页JNLP并看到它加载WebSocket JAR时显示控制台:

例外:

java.lang.ClassNotFoundException: org.java_websocket.client.WebSocketClient
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.joy.system.SystemAppLaunch.main(SystemAppLaunch.java:329)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javaws.Launcher.executeApplication(Unknown Source)
    at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

控制台输出:

Java Web Start 11.181.2.13 x86
Using JRE version 1.8.0_181-b13 Java HotSpot(TM) Client VM
User home directory = C:\Users\user
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
m:   print memory usage
o:   trigger logging
p:   reload proxy configuration
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
0-5: set trace level to <n>
----------------------------------------------------
CacheEntry[file:/C:/Users/user/Desktop/Alpha/apache-tomcat-9.0.0.M26/webapps/FB2HMI/lib/Java-WebSocket-1.3.0.jar]: updateAvailable=false,lastModified=Mon Nov 26 11:39:44 EST 2018,length=113538
Sep 11 15:24:07 EDT 2018,length=12913
System Application is started. Please wait......
#### Java Web Start Error:
#### org.java_websocket.client.WebSocketClient

JNLP文件:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="" href="launch.jnlp">
    <information>
        <title>SystemApp</title>
        <vendor></vendor>
        <homepage href=""/>
        <description>System Application</description>
    <icon kind="splash" href="kom.jpeg"/>
            </information>
        <security>
     <all-permissions/>
  </security>

    <resources>
        <j2se version="1.7+"/>
    <jar href="lib/DaExecutive.jar"/>


    <jar href="lib/SystemApp-10.0.60.jar" main="true"/>

    <jar href="lib/DDS-10.0.60.jar"/>

    <jar href="lib/jackson-core-2.2.3.jar"/>

    <jar href="lib/jackson-coreutils-1.8.jar"/>

    <jar href="lib/msg-simple-1.1.jar"/>

    <jar href="lib/btf-1.2.jar"/>

    <jar href="lib/jackson-databind-2.2.3.jar"/>

    <jar href="lib/guava-16.0.1.jar"/>

    <jar href="lib/jsr305-2.0.1.jar"/>

    <jar href="lib/json-schema-core-1.2.5.jar"/>

    <jar href="lib/uri-template-0.9.jar"/>

    <jar href="lib/rhino-1.7R4.jar"/>

    <jar href="lib/json-schema-validator-2.2.6.jar"/>

    <jar href="lib/joda-time-2.3.jar"/>

    <jar href="lib/libphonenumber-6.2.jar"/>

    <jar href="lib/mailapi-1.4.3.jar"/>

    <jar href="lib/activation-1.1.jar"/>

    <jar href="lib/jopt-simple-4.6.jar"/>

    <jar href="lib/Utilities-10.0.60.jar"/>

    <jar href="lib/zip4j-1.2.3.jar"/>

    <jar href="lib/jackson-dataformat-xml-2.9.5.jar"/>

    <jar href="lib/jackson-annotations-2.9.0.jar"/>

    <jar href="lib/jackson-module-jaxb-annotations-2.9.5.jar"/>

    <jar href="lib/stax2-api-3.1.4.jar"/>

    <jar href="lib/woodstox-core-5.0.3.jar"/>

    <jar href="lib/Carousel-10.0.60.jar"/>

    <jar href="lib/CoreControls-10.0.60.jar"/>

    <jar href="lib/CommonInterface-1.0.0.jar"/>

    <jar href="lib/log4j-1.2.17.jar"/>

    <jar href="lib/json-20090211.jar"/>

    <jar href="lib/gson-1.4.jar"/>

    <jar href="lib/commons-io-2.4.jar"/>

    <jar href="lib/jna-4.1.0.jar"/>

    <jar href="lib/platform-3.4.0.jar"/>

    <jar href="lib/TableLayout-20050920.jar"/>

    <jar href="lib/CoreHMIAppBuilder-10.0.60.jar"/>

    <jar href="lib/Fb2HmiCm-10.0.64.jar"/>

    <jar href="lib/commons-collections4-4.0.jar"/>

    <jar href="lib/CoreStandardFeatures-10.0.60.jar"/>

    <jar href="lib/commons-net-3.6.jar"/>

    <jar href="lib/Java-WebSocket-1.3.0.jar"/>

    <jar href="lib/commons-configuration-1.6.jar"/>

    <jar href="lib/commons-collections-3.2.1.jar"/>

    <jar href="lib/commons-lang-2.4.jar"/>

    <jar href="lib/commons-logging-1.1.1.jar"/>

    <jar href="lib/commons-digester-1.8.jar"/>

    <jar href="lib/commons-beanutils-1.7.0.jar"/>

    <jar href="lib/commons-beanutils-core-1.8.0.jar"/>



    <property name="jnlp.serverip" value="192.168.0.50"/>
    <property name="jnlp.serverport" value="8080"/>
    </resources>
    <application-desc main-class="com.joy.system.SystemAppLaunch" name="SystemApp">
    <argument>8887</argument>
    <argument>192.168.0.50</argument>
    </application-desc>
</jnlp>

我的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">
    <parent>
        <groupId>ParentProject</groupId>
        <artifactId>ParentProject</artifactId>
        <version>10.0.60</version>
        <relativePath>../ParentProject/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>SystemApp</groupId>
    <artifactId>SystemApp</artifactId>
    <name>SystemApp</name>
    <description>System Application</description>

    <dependencies>
        <dependency>
            <groupId>DDS</groupId>
            <artifactId>DDS</artifactId>
            <version>${dds-version}</version>
        </dependency>
        <dependency>
            <groupId>utility</groupId>
            <artifactId>Utilities</artifactId>
            <version>${utilities-version}</version>
        </dependency>
        <dependency>
            <groupId>Carousel</groupId>
            <artifactId>Carousel</artifactId>
            <version>${carousel-version}</version>
        </dependency>
        <dependency>
            <groupId>CoreControls</groupId>
            <artifactId>CoreControls</artifactId>
            <version>${coreControls-version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20090211</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>platform</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>tablelayout</groupId>
            <artifactId>TableLayout</artifactId>
            <version>20050920</version>
        </dependency>
        <dependency>
            <groupId>CoreHMIAppBuilder</groupId>
            <artifactId>CoreHMIAppBuilder</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Tell maven to compile using Java 1.8 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                    <executable>${JAVA_1_8_HOME}</executable>
                </configuration>
            </plugin>       
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>webstart-maven-plugin</artifactId>
                <version>1.0-beta-6</version>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>keytool-api-1.7</artifactId>
                        <version>1.5</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jnlp-inline</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <excludeTransitive>false</excludeTransitive>
                    <makeArchive>false</makeArchive>
                    <filenameMapping>simple</filenameMapping>
                    <versionEnabled>false</versionEnabled>
                    <jnlpFiles>
                        <jnlpFile>
                            <templateFilename>template.vm</templateFilename>
                            <outputFilename>launch.jnlp</outputFilename>
                            <jarResources>
                                <jarResource>
                                    <groupId>SystemApp</groupId>
                                    <artifactId>SystemApp</artifactId>
                                    <name>SystemApp</name>
                                    <version>${project.version}</version>
                                    <mainClass>com.joy.system.SystemAppLaunch</mainClass>                                                       
                                </jarResource>
                            </jarResources>
                        </jnlpFile>
                    </jnlpFiles>
                    <unsignAlreadySignedJars>true</unsignAlreadySignedJars>
                    <canUnsign>true</canUnsign>
                    <libPath>lib</libPath>
                    <codebase></codebase>
                    <updateManifestEntries>
                        <Application-Name>SystemApp</Application-Name>
                        <Class-Path>resources/ resources/images/ resources/properties/ resources/config/</Class-Path>
                        <Trusted-Library>true</Trusted-Library>
                        <Permissions>all-permissions</Permissions>
                        <Codebase>*</Codebase>
                        <Trusted-Only>true</Trusted-Only>
                    </updateManifestEntries>
                    <jnlp>
                        <j2seVersion>1.7+</j2seVersion>
                        <outputFile>launch.jnlp</outputFile>
                        <mainClass>com.joy.system.SystemAppLaunch</mainClass>
                    </jnlp>
                    <sign>
                        <keystore>${project.basedir}/myKeystore.jks</keystore>
                        <storepass>password</storepass>
                        <alias>key_2017</alias>
                        <verify>false</verify>
                    </sign>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:0)

如果有人遇到这个问题,我要做的就是手动将应用程序中需要的一个单独的JAR添加到jar模板列表的顶部。您可以在我上面的JNLP文件中以DaExecutive.jar的形式查看它。有一个问题,我还没有解决,但是这阻止了列表中它下面的所有.jar依赖项的加载。删除后即可加载它们。