[Error record] The problem that the exe4j packaging program cannot set the jar package dependency (package the source code and the dependent library into the same jar package)





1. Problem description



Encountered in [Error Record] IntelliJ IDEA exported executable jar package execution error (java.lang.ClassNotFoundException | No dependent library was selected when packaging) blog

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)

Error message, here is the following strategy when packaging;

Since the second Jar package packaging method was selected when compiling the IntelliJ IDEA program, the main program and dependent libraries were packaged separately;

insert image description here

The final main program and dependent libraries are separated, when using the main program, additional dependent libraries must be configured;

insert image description here


Here is another problem involved, want to use exe4j to package the above jar package into a Windows program,

Package the Jar package with the Java virtual machine and bundle it into an executable exe program;

However, when exe4j is packaged, the dependent library of the jar package cannot be set, and only one jar package can be set;


After studying the documentation of exe4j, I got the following conclusions:

insert image description here

  • The exe4j packaging program cannot set jar package dependencies, but can only set a jni-related native .a static library and .so dynamic library dependency directory;
  • Exe4j also cannot set the java command execution parameters, if the parameters can be set, you can set the dependent library through the -classpath option;
  • There is another way to pass parameters through the command line, but the packaged program is a path interface program;

This is rather embarrassing, what IntelliJ IDEA packages is a jar package + several jar dependent libraries, which cannot be set into exe4j;


When exe4j is executed, an error will be reported, dependencies cannot be found, and related classes cannot be found naturally;

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)




Two, the solution



In IntelliJ IDEA, when exporting the jar package, select the first scheme setting, and then package all the java source code together;

insert image description here

The effect after packaging is as follows, all Java source codes are packaged in a jar package;

insert image description here

Note, to delete the signature file under the META-INF directory;
insert image description here

In [Error Record] IntelliJ IDEA packaged the Jar package containing the dependent library and reported an error (Invalid signature file digest for Manifest main attribute) blog, I encountered a problem with the signature file error;

Guess you like

Origin blog.csdn.net/han1202012/article/details/132608924