Java GUI 如何打包?
HJGL是一个java1.8 编写的 GUI软件,同时也是一个包含了mysql、hadoop以及maven的工程
如何打包?
策略1
第1步
MavenClean
第2步
Maven install
第3步
下载exe4j
exe4j_windows-x64_6_0_1.exe
第4步
按照百度教程打包:
https://jingyan.baidu.com/album/c275f6ba28e15ae33d756711.html?picindex=5
策略1的结果是,能够成功打包成exe但是,功能有损坏,一下jar包没有包裹进去:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
策略2
在策略1的基础上,修正百度教程中的部分内容
修改1:
配置mvn环境
下载maven并配置环境变量:
http://maven.apache.org/download.cgi
修改2:
导出maven工程所用到的包,用mvn指令:
https://www.cnblogs.com/goodbye-lazy/p/10589562.html
mvn dependency:copy-dependencies -DoutputDirectory=dependency_lib
然后写了一个matlab脚本,生成能够直接拷贝的字符串
%% 获得依赖包对应的所有文件名
clear all;close all;clc;
fatherPath = 'D:\JavaProject\hjgljava\dependency_lib';
fatherDir = dir(fatherPath);
len = length(fatherDir);
for i = 3:len
%do something
% disp(fatherDir(i).name);
headStr = '<archive location="D:/JavaProject/hjgljava/dependency_lib/';
endStr = '" failOnError="false" />';
result = [headStr fatherDir(i).name endStr];
disp(result);
end
得到类似以下的结果,然后用notebook打开.exe4j文件,将所有的依赖包,直接复制进去。
<archive location="D:/JavaProject/hjgljava/dependency_lib/activation-1.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/apacheds-i18n-2.0.0-M15.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/apacheds-kerberos-codec-2.0.0-M15.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/api-asn1-api-1.0.0-M20.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/api-util-1.0.0-M20.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/asm-3.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/avro-1.7.4.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-beanutils-1.7.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-beanutils-core-1.8.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-cli-1.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-codec-1.4.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-collections-3.2.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-compress-1.4.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-configuration-1.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-daemon-1.0.13.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-digester-1.8.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-httpclient-3.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-io-2.4.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-lang-2.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-logging-1.1.3.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-math3-3.1.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/commons-net-3.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/curator-client-2.7.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/curator-framework-2.7.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/curator-recipes-2.7.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/gson-2.2.4.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/guava-11.0.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/hadoop-annotations-2.7.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/hadoop-auth-2.7.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/hadoop-common-2.7.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/hadoop-hdfs-2.7.6.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/htrace-core-3.1.0-incubating.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/httpclient-4.1.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/httpcore-4.1.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jackson-core-asl-1.9.13.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jackson-jaxrs-1.8.3.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jackson-mapper-asl-1.9.13.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jackson-xc-1.8.3.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/java-xmlbuilder-0.4.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jaxb-api-2.2.2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jaxb-impl-2.2.3-1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jdk.tools-1.8.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jersey-core-1.9.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jersey-json-1.9.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jersey-server-1.9.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jets3t-0.9.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jettison-1.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jetty-6.1.26.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jetty-sslengine-6.1.26.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jetty-util-6.1.26.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jsch-0.1.54.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jsp-api-2.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/jsr305-3.0.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/leveldbjni-all-1.8.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/log4j-1.2.17.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/mysql-connector-java-5.1.44.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/netty-3.6.2.Final.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/netty-all-4.0.23.Final.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/paranamer-2.3.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/protobuf-java-2.5.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/servlet-api-2.5.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/slf4j-api-1.7.10.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/slf4j-log4j12-1.7.10.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/snappy-java-1.0.4.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/stax-api-1.0-2.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/xercesImpl-2.9.1.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/xml-apis-1.3.04.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/xmlenc-0.52.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/xz-1.0.jar" failOnError="false" />
<archive location="D:/JavaProject/hjgljava/dependency_lib/zookeeper-3.4.6.jar" failOnError="false" />
最后的步骤和百度中的教程一样,最后项目成功打包