0

launch4j to an exe file. Here is my 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>

above is my POM.xml

Question
when double click on project.exe , nothing is executed.nothing is appear.nothing happen after execute the project.exe
anything wrong at this code?? what i have missed? still need to install anything or what? is yes, please step by step guide me, thx =)

enter image description here

UPDATE
after i had run the cmd java -cp C:\Users\chiny\Desktop\InsertMySQL\target\InsertMySQL-1.0-SNAPSHOT.jar com.mycompany.insertmysql.insert to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

so, i had searched the solution, just mention to add the dependency, as you can see, my pom.xml is attached with dependency mysql connector already. i have no idea how to solve it

UPDATE 2

enter image description here

how about i get this error? what is this?

ALL THE PROBLEM IS the CLASSPATH, java can't find the mysql-connector-java.jar path. how to solve it?

but when i m runing with 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 with mysql-connector-java-5.1.45.jar then the project.exe able to run..how to set the nysql connector classpath in programmatically ?

John Walker
  • 1,121
  • 4
  • 26
  • 68

1 Answers1

0

You are creating a shade jar file to include all needed dependencies, but in the configuration of the launch4j plugin you are referencing the unshaded jar file. Update the plugin configuration to use the correct jar:

<jar>target/InsertMySQL-1.0-SNAPSHOT-shaded.jar</jar>
Georg Leber
  • 3,470
  • 5
  • 40
  • 63
  • error with `com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure` – John Walker Jan 20 '18 at 18:53
  • Seems you are doing some logic in the main class of your jar. Make sure that communication to the MySQL server is possible. This exception has nothing todo with te problem you are facing in your question. Do you get this exception, if you run your code from your IDE? – Georg Leber Jan 20 '18 at 18:54
  • Maybe this: https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – Georg Leber Jan 20 '18 at 18:58
  • Did you change your pom to the mentioned (shaded) jar in the launch4j configuration? So then please update the code of the pom.xml in your question. – Georg Leber Jan 21 '18 at 10:49
  • I had solved my problem with copy the MySQL-connector-java.jar and paste it at the project.exe same directory. How to specific the jar path in somewhere? – John Walker Jan 21 '18 at 10:58