diff --git a/pom.xml b/pom.xml
index 09c6777..2a7e1dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,19 @@
+
+ maven-assembly-plugin
+
+
+
+ io.xjar.XJar
+
+
+
+ jar-with-dependencies
+
+
+
org.apache.maven.plugins
maven-source-plugin
diff --git a/src/main/java/io/xjar/XInjector.java b/src/main/java/io/xjar/XInjector.java
index f5eb6ef..3557fa4 100644
--- a/src/main/java/io/xjar/XInjector.java
+++ b/src/main/java/io/xjar/XInjector.java
@@ -4,6 +4,7 @@
import io.loadkit.Resource;
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
+import org.apache.commons.compress.utils.Sets;
import java.io.IOException;
import java.io.InputStream;
@@ -18,6 +19,9 @@
* 2018/11/25 10:34
*/
public class XInjector {
+
+ public static HashSet ignoreClass = Sets.newHashSet("io/xjar/XInjector.class", "io/xjar/XGo.class",
+ "io/xjar/XJar.class");
/**
* 往JAR包中注入XJar框架的classes
@@ -31,6 +35,9 @@ public static void inject(JarArchiveOutputStream zos) throws IOException {
while (resources.hasMoreElements()) {
Resource resource = resources.nextElement();
String name = resource.getName();
+ if (ignoreClass.contains(name)) {
+ continue;
+ }
String directory = name.substring(0, name.lastIndexOf('/') + 1);
if (directories.add(directory)) {
JarArchiveEntry xDirEntry = new JarArchiveEntry(directory);
diff --git a/src/main/java/io/xjar/XJar.java b/src/main/java/io/xjar/XJar.java
new file mode 100644
index 0000000..c8f6392
--- /dev/null
+++ b/src/main/java/io/xjar/XJar.java
@@ -0,0 +1,47 @@
+package io.xjar;
+
+public class XJar {
+
+ public static void main(String[] args) throws Exception {
+ String sourceJar = System.getProperty("xjar.source");
+ if (stringIsEmpty(sourceJar)) {
+ System.err.println("请使用-Dxjar.source系统属性指定要加密的jar包。");
+ return;
+ }
+ String destJar = System.getProperty("xjar.dest");
+ if (stringIsEmpty(destJar)) {
+ System.err.println("请使用-Dxjar.dest系统属性指定加密后的jar包。");
+ return;
+ }
+ String password = System.getProperty("xjar.password");
+ if (stringIsEmpty(password)) {
+ System.err.println("请使用-Dxjar.password系统属性指定加密秘钥,长度小于256字节。");
+ return;
+ }
+ String algorithm = System.getProperty("xjar.algorithm");
+ String keysize = System.getProperty("xjar.keysize");
+ String ivsize = System.getProperty("xjar.ivsize");
+ String include = System.getProperty("xjar.include");
+ String exclude = System.getProperty("xjar.exclude");
+ XEncryption encryption = XCryptos.encryption().from(sourceJar);
+ if (stringIsEmpty(algorithm) || stringIsEmpty(keysize) || stringIsEmpty(ivsize)) {
+ encryption = encryption.use(password);
+ }
+ else {
+ encryption = encryption.use(algorithm, Integer.parseInt(keysize), Integer.parseInt(ivsize), password);
+ }
+ if (!stringIsEmpty(include)) {
+ encryption = encryption.include(include);
+ }
+ if (!stringIsEmpty(exclude)) {
+ encryption = encryption.exclude(exclude);
+ }
+ System.out.println("正在进行加密操作,请稍候...");
+ encryption.to(destJar);
+ }
+
+ private static boolean stringIsEmpty(String str) {
+ return str == null || str.trim().length() <= 0;
+ }
+
+}