Jnlp running dependency library's functions

本小妞迷上赌 提交于 2021-01-07 02:54:39

问题


I have a SwingWorker which runs a dependency's functions

public class JarRunnerWorker extends SwingWorker<Void, Void> {

    private JnlpApp jnlpApp;

    public JarRunnerWorker(){}

    @Override
    protected Void doInBackground() {
        try {
            System.out.println("***  running jar  ***");
            jnlpApp = com.asd.bsign.App.startForJnlp();
            jnlpApp.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return null;
    }

    public void setThreadPillFalse(){
        jnlpApp.setThreadPillFalse();
    }

Maven dependency and build from pom.xml:

        <dependency>
            <groupId>com.asd.bsign</groupId>
            <artifactId>bsignclient</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/libs
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>libs/</classpathPrefix>
                        <mainClass>com.bermuda.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

This function works well in IDE and in my jar(jar and libs are in the same folder).

Here is my jnlp file(all jars in libs are added):

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="http://localhost:8080/bsign/" href="bsign.jnlp">
    <information>
        <title>Jnlp Testing</title>
        <vendor>bermuda</vendor>
        <homepage href="http://localhost:8080/bsign/" />
        <description>jnlp Testing</description>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+" />
        <jar href="bsignclient.jar" />

        <jar href="libs/commons-discovery-0.2.jar" />
        <jar href="libs/commons-io-2.8.0.jar" />
        <jar href="libs/commons-logging-1.1.1.jar" />
        .
        .
        .

    </resources>
    <application-desc main-class="com.bermuda.App" />
</jnlp>

When I run jnlp, jnlp executes System.out.println("*** running jar ***"); but it doesn't work, when I run setThreadPillFalse I get NullPointerException

We can think JnlpApp class like this:

public class JnlpApp implements Runnable{
    
    private boolean pill;


    public JnlpApp(){
        pill = true;
    }

    @Override
    public void run() {
        while(pill){
            System.out.println("Doing some job");
            Thread.sleep(5000);
        }

    }

    public void setThreadPillTrue(){
        connectionMonitor.setPill(true);
    }

    public void setThreadPillFalse(){
        connectionMonitor.setPill(false);
    }

}

And startForJnlp creates a JnlpApp and returns it.

How can I run this function from jnlp?

来源:https://stackoverflow.com/questions/65538810/jnlp-running-dependency-librarys-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!