基于classfinal对java项⽬加密1 单个jar包加密
将下载好的jar包和需要加密的包放到⼀个⽂件夹,执⾏下⾯命令
java -jar classfinal-fatjar-1.2.1.jar -file 换成你的jar包 -packages com.itl.iap -pwd 123 -Y
具体参数说明,可以⾃⾏增减
-file 加密的jar/war完整路径
-packages 加密的包名(可为空,多个⽤","分割)
-libjars jar/war包lib下要加密jar⽂件名(可为空,多个⽤","分割)
-cfgfiles 需要加密的配置⽂件,⼀般是classes⽬录下的yml或properties⽂件(可为空,多个⽤","分割)
-exclude 排除的类名(可为空,多个⽤","分割)
-classpath 外部依赖的jar⽬录,例如/tomcat/lib(可为空,多个⽤","分割)
-pwd 加密密码,如果是#号,则使⽤⽆密码模式加密
-
code 机器码,在绑定的机器⽣成,加密后只可在此机器上运⾏
-Y ⽆需确认,不加此参数会提⽰确认以上信息
加密后的⽂件多了个encrypted
2 查看加密效果
怎么对文件夹加密classfinal主要加密class⽂件,主要是对⽅法返回null处理
3 jar包部署
启动jar包,我把encrypted去掉了
nohup java -javaagent:iap-system-provider-1.0.jar="-pwd 123"-jar iap-system-provider-1.0.jar
(这种⽅式通过ps -ef|grep jar查看进程可以查到密码)
so
另⼀种⽅式启动推荐
nohup java -javaagent:iap-system-provider-1.0.jar -jar iap-system-provider-1.0.jar
使⽤nohup命令启动时,如果系统⽀持gui,会弹出输⼊密码的界⾯,如果是纯命令⾏下,不⽀持gui,则需要在同级⽬录下的或中写⼊密码,项⽬读取到密码后会清空此⽂件。
为了保险起见请⾃⾏删除此⽂件
启动时再加上这个参数-XX:+DisableAttachMechanism(防⽌连接上部署好的jar包来反编译)
关闭⼯具关联JVM的功能。默认情况下,该选项开启,此时可以使⽤诊断⼯具如:jcmd,jstack,jma
p和jinfo。
nohup java -XX:+DisableAttachMechanism -javaagent:iap-system-provider-1.0.jar -jar iap-system-provider-1.0.jar
3 maven集成
对于⾃⼰项⽬的build,⾃⾏增删,版本和参数可以提取到最⼤的pom⽂件⾥
<build>
<plugins>
<!-- spring boot maven 打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.7.RELEASE</version>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加密插件,防⽌反编译 -->
<plugin>
<!-- gitee/roseboy/classfinal -->
<groupId&seboy</groupId>
<artifactId>classfinal-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<!--加密密码,如果是#号,则使⽤⽆密码模式加密,【加密后没有pom⽂件,不⽤担⼼泄漏】-->
<password>123</password>
<!--加密的包名(可为空,多个⽤","分割)-->
<packages>com.itl</packages>
<!--需要加密的配置⽂件,⼀般是classes⽬录下的yml或properties⽂件(可为空,多个⽤","分割)-->
<cfgfiles>*.properties,/mapper/*l</cfgfiles>
<!--外部依赖的jar⽬录,例如/tomcat/lib(可为空,多个⽤","分割)-->
<!--<classpath></classpath>-->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>classFinal</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
将插件配置在pom⽂件⾥,执⾏maven的package时,在target下⾯会出现xxx-encrypted.jar,这个加密后的包,放到linux部署即可3 错误总结
在部署过程中遇到很多多多多多多多多多多多多多多多多问题
1. 打包插件不统⼀
就是标签⾥⾯有没有⽤的其他标签,打包后⽆法运⾏,最好⽤我上⾯的
2. 远程调⽤bean注⼊冲突
The bean 'XXX.FeignClientSpecification', defined in null, could not be registered
@FeignClient注解⾥⾯加⼀个contextId = “isp-form”
@FeignClient(name="common-service", contextId ="example")
3. mybatisplus模板注⼊冲突、Redis模板冲突
将项⽬⾥⾯的多个模板合成⼀个放到common⾥⾯,其他模块引⽤即可
4. 最恶⼼的错重新打包就好了
nohup: ignoring input
Failed to find Premain-Class manifest attribute in iap-snaker-provider.jar
Error occurred during initialization of VM
agent library failed to init: instrument
5. 更恶⼼的错mapUnderscoreToCamelCase
2021-03-15 16:07:11.165 WARN 7770 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'iapChangeDetailLogContr oller': Unsatisfied dependency expressed through field 'iapChangeDetailLogService'; nested exception is org.springframework.beans.factory.BeanCreation Exception: Error creating bean with name 'iapChangeDetailLogTServiceImpl': Injection of resource dependencies failed; nested exception is org.springfram ework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'iapChangeDetailLogTMapper' defined in URL [jar:file:/data1/iap/iap-system-provider-1.0.jar!/BOOT-INF/classes!/com/itl/iap/system/provider/mapper/IapChangeDetailLogTMapper.class]: Unsatisfied dependency expressed t hrough bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via fa ctory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSession Factory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoSuchFieldError: mapUnderscoreToCamelCase
这个错误的原因是配置⽂件typeAliasesPackage配错了,然后⼀直报map-underscore-to-camel-case的问题,我⼀直以为是我xml配置⽂件没有驼峰命名
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论