jnlp

q43xntqr  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(254)

我有一个 SwingWorker 它运行依赖项的函数

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依赖和构建自 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>

这个函数在ide和myjar中运行良好(jar和libs在同一个文件夹中)。
这是我的jnlp文件(libs中的所有jar都已添加):

<?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>

当我运行jnlp时,jnlp执行 System.out.println("***running jar***"); 但当我跑的时候,它不起作用 setThreadPillFalse 我明白了 NullPointerException 我们可以思考 JnlpApp 像这样的班级:

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);
    }

}

以及 startForJnlp 创建一个jnlapp并返回它。
如何从jnlp运行此函数?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题