javaFx已在jdk包含无需单独引用,性能还是挺好的只是现在资料太少!
编写javaFX工具类
package com.xym;
import io.xjar.XConstants;
import io.xjar.XKit;
import io.xjar.boot.XBoot;
import io.xjar.jar.XJarAntEntryFilter;
import io.xjar.key.XKey;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.ToolBar;
import javafx.scene.image.Image;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.File;
/**
* @Author: xym
* @Date: 2019/12/18
* @Description:
* @Version: 1.0
*/
public class xjarutil extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
//标签和html标签重合度挺高,学习成本较低
Label nameLb1 = new Label("输入原始jar名称:");
TextField nameFld = new TextField();
Label nameLb2 = new Label("输入最终jar名称:");
TextField nameFld1 = new TextField();
Label nameLb3 = new Label("密码:");
TextField nameFld3 = new TextField();
Label nameLb4 = new Label("加密通配包:");
TextField nameFld4 = new TextField();
Label msg = new Label();
Button sayHelloBtn = new Button("加密");
Button exitBtn = new Button("Exit");
ToolBar tb = new ToolBar();
tb.getItems().addAll(sayHelloBtn,exitBtn);
sayHelloBtn.setOnAction(event -> {
try {
//调用xjar对于自己jar包中的部分代码进行加密
String password = nameFld3.getText();
String oldjar = nameFld.getText();
String newJar = nameFld1.getText();
String pattern = nameFld4.getText();
//获取文件运行路径
String property = System.getProperty("user.dir");
newJar = property+ File.separator+newJar;
oldjar = property+ File.separator+oldjar;
XKey xKey = XKit.key(password);
XBoot.encrypt(oldjar, newJar, xKey, XConstants.MODE_DANGER,new XJarAntEntryFilter(pattern));
} catch (Exception e) {
msg.setStyle("-fx-text-fill: red;");
msg.setText("失败了!");
e.printStackTrace();
}
msg.setStyle("-fx-text-fill: green;");
msg.setText("加密成功!");
});
exitBtn.setOnAction(e-> Platform.exit());
// Text msg = new Text("hello JavaFx");
VBox root = new VBox();
root.setSpacing(5);
root.getChildren().addAll(nameLb1,nameFld,nameLb2,nameFld1,nameLb3,nameFld3,nameLb4,nameFld4,msg,tb);
Scene scene = new Scene(root,350,250);
primaryStage.setScene(scene);
//设置舞台logo
primaryStage.getIcons().add(new Image("icon.png"));
//设置舞台标题
primaryStage.setTitle("jar包加密");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
运行效果图:
maven 将自己的jar包,xjar的jar包一起打成可运行jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!--配置启动类-->
<mainClass>com.xym.xjarutil</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>