外部jar /库launch4j问题

时间:2016-11-12 21:41:52

标签: java jar jsoup external launch4j

我目前正在开发一个使用名为jsoup-1.10.1的外部库的程序。在我开始使用launch4j jar之前我使用了jsoup但是现在我必须使用这个库我无法弄清楚如何将jsoup与我的项目结合起来以便我可以生成一个正常工作的exe。我已就此事进行了一些研究,但似乎没有任何效果。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

使用onejar创建一个jar 然后在launch4j中使用此jar。

适用于许多外部罐子。只加载资源可能有点棘手,但是可能。

pom.xml中的示例部分:

<build>
    <plugins>
        <plugin>
            <groupId>com.jolira</groupId>
            <artifactId>onejar-maven-plugin</artifactId>
            <version>1.4.4</version>
            <executions>
                <execution>
                    <configuration>
                        <mainClass>com.xy.Mainclass</mainClass>
                        <attachToBuild>false</attachToBuild>
                        <classifier>onejar</classifier>
                    </configuration>
                    <goals>
                        <goal>one-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.akathist.maven.plugins.launch4j</groupId>
            <artifactId>launch4j-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>l4j-clui</id>
                    <phase>package</phase>
                    <goals>
                        <goal>launch4j</goal>
                    </goals>
                    <configuration>
                        <headerType>console</headerType>
                        <jar>${project.build.directory}/${project.artifactId}-${project.version}.one-jar.jar</jar>
                        <outfile>${project.build.directory}/${project.artifactId}.exe</outfile>
                        <downloadUrl>http://java.com/download</downloadUrl>
                        <classPath>
                            <mainClass>com.simontuffs.onejar.Boot</mainClass>
                            <preCp>anything</preCp>
                        </classPath>

                        <singleInstance>
                            <mutexName>${project.artifactId}</mutexName>
                        </singleInstance>
                        <jre>
                            <minVersion>1.6.0</minVersion>
                            <jdkPreference>preferJre</jdkPreference>
                            <initialHeapSize>128</initialHeapSize>
                            <maxHeapSize>1024</maxHeapSize>
                        </jre>
                        <versionInfo>
                            <fileVersion>1.0.0.0</fileVersion>
                            <txtFileVersion>${project.version}</txtFileVersion>
                            <fileDescription>${project.name}</fileDescription>
                            <copyright>...</copyright>
                            <productVersion>0.0.0.1</productVersion>
                            <txtProductVersion>0.0.0.1</txtProductVersion>
                            <productName>${project.name}</productName>
                            <companyName>...</companyName>
                            <internalName>${project.artifactId}</internalName>
                            <originalFilename>${project.artifactId}.exe</originalFilename>
                        </versionInfo>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-exe</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.directory}/${project.artifactId}.exe</file>
                                <type>exe</type>
                                <classifier>executable</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>