执行Maven launch4j .exe

时间:2018-01-20 13:38:04

标签: java netbeans maven-plugin

launch4j到exe文件。这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.mycompany</groupId>
    <artifactId>InsertMySQL</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.mycompany.insertmysql.insert</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <id>l4j-gui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>gui</headerType>
                            <outfile>target/Project.exe</outfile>
                            <jar>target/InsertMySQL-1.0-SNAPSHOT.jar</jar>
                            <!-- if <dontWrapJar>true</dontWrapJar> change to this conf <jar>${project.artifactId}-${project.version}.jar</jar> -->
                            <dontWrapJar>false</dontWrapJar>
                            <errTitle>Error in launch4j plugin</errTitle>
                            <classPath>
                                <mainClass>com.mycompany.insertmysql.insert</mainClass>
                            </classPath>

                            <jre>
                                <minVersion>1.7.0</minVersion>
                                <maxVersion>1.9.0</maxVersion>
                                <initialHeapSize>512</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>1.0.0.0</txtFileVersion>
                                <fileDescription>des</fileDescription>
                                <copyright>Copyright (c) 2014 </copyright>
                                <companyName>comp</companyName>
                                <productVersion>3.0.0.0</productVersion>
                                <txtProductVersion>${project.version}</txtProductVersion>
                                <productName>Project</productName>
                                <internalName>Project</internalName>
                                <originalFilename>Project.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            </plugins>
  </build>
</project>

以上是我的POM.xml

问题
当双击project.exe时,没有执行任何操作。没有任何内容。执行project.exe后没有任何反应 这段代码有什么不对吗? 我错过了什么?还需要安装什么或什么?是的,请一步一步指导我,thx =)

enter image description here

更新
在我运行cmd java -cp C:\Users\chiny\Desktop\InsertMySQL\target\InsertMySQL-1.0-SNAPSHOT.jar com.mycompany.insertmysql.insert来解决java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

之后

所以,我已经搜索了解决方案,只是提到添加依赖项,正如您所看到的,我的pom.xml已经附加了依赖mysql连接器。我不知道如何解决它

更新2

enter image description here

我得到这个错误怎么样?这是什么?

所有问题都是CLASSPATH,java找不到mysql-connector-java.jar路径。怎么解决?

但是当我使用java -cp .;C:\Users\chiny\.m2\repository\mysql\mysql-connector-java\5.1.45\mysql-connector-java-5.1.45.jar;C:\Users\chiny\Desktop\InsertMySQL\target\InsertMySQL-1.0-SNAPSHOT.jar com.mycompany.insertmysql.insert运行mysql-connector-java-5.1.45.jar时,project.exe能够运行..如何以编程方式设置nysql连接器类路径?

1 个答案:

答案 0 :(得分:0)

您正在创建一个阴影jar文件以包含所有必需的依赖项,但在launch4j插件的配置中,您引用了无阴影的jar文件。更新插件配置以使用正确的jar:

<jar>target/InsertMySQL-1.0-SNAPSHOT-shaded.jar</jar>