Introduce how to encrypt spring boot project
Introduction
After a spring program is encrypted by Jar2Exe, 2 features will fail:
-
Any kind of
component-scanwill fail:Program could not automatically find and instantiate a
@Serviceor@Controlleror@Mapperbean. It could not find mapper xml file according to a wildcard such asclasspath:/mapper/*.xml. -
Any kind of
@annotationwill fail:Such as
@Autowiredor@Valuewill not work.
Solution
Because of the incompatibility of spring and encryption, we choose to encrypt part of the program, and keep the spring part un-encrypted:
-
@Serviceclass: we split a service class into aparent classand achild class:-
parent classis the real service class with business code to be encrypted. It has no annotations. -
child classextends theparent class, with@Serviceto be auto-scaned, with@Autowiredto be injected to by spring.
-
-
@Mapperclass: they are interfaces, we need not encrypt them. -
mapper/xxx.xml: there are sql statements, if we want to encrypt, we need to declare them one by one explicitly. -
@Controllerclass: usually we need not encrypt. If we want, do like@Serviceclass does. -
/static/and/templates/, these files are referred by their names, encyption compatible, encrypt if we want. -
/application.properties, this file is used by its name, encryption compatible.
Project Structure
In order to be partially encrypted, we split a spring-boot project into 3 projects, please refer to the demo project:
-
demo-webis the original spring-boot project, keep un-encrypted.@Controllerand@Serviceclasses are in it. -
demo-coreis to be encrypted.parent classof@Serviceare in this project. This project is a dependency ofdemo-web. -
demo-sharecontains@Mapperclasses, keep un-encrypted. In order to let@Mapperclasses accessible indemo-coreduring developing, as a dependency ofdemo-core.
Encrypt using Jar2Exe
Run mvn build at the parent directory, then we will get the result /demo-web/target/demo-web-0.0.1-SNAPSHOT.jar:
-
First, please download the most recent Jar2Exe
v2.2.4or above for v2.2,v2.5.2or above for v2.5. -
unzip the
demo-web-0.0.1-SNAPSHOT.jar, we will get:demo-web-0.0.1-SNAPSHOT ├── BOOT-INF │ ├── classes │ │ └── ……… │ └── lib │ ├── ……… │ ├── demo-core-0.0.1-SNAPSHOT.jar │ ├── demo-share-0.0.1-SNAPSHOT.jar │ └── ……… ├── META-INF │ ├── MANIFEST.MF │ └── ……… └── org └── springframework └── boot └── loader └── ………because Jar2Exe has provided a ClassLoader, so we only need those files under
/BOOT-INF/and ignore other files. -
Pack the contents under
/BOOT-INF/classes/into a zip or jar file:cd BOOT-INF/classes/ jar cvf ../classes.jar *
-
Run Jar2Exe:
-
At the step 1, choose
/BOOT-INF/lib/demo-core-....jaras the main jar. -
At the step 3, input
com.regexlab.j2e.demo.DemoWebApplicationas the main class, ignore the warning when we clickNext. -
At the step 4, we check the
Encrypt and hide. -
At the step 5, we add
BOOT-INF/classes.jarand allBOOT-INF/lib/*files as dependencies. Keep../classes.jaranddemo-share-....jarNOT protected. As to other jar files, we need NOT to enableProtectbecause it will slow down the startup of program if we choose more jars to be protected.
-
Demo Spring Boot Project
Demo spring boot project for Jar2Exe
Demo2 encrypt springboot using script

Comments
spring boot application
when im encrypt the the spring boot applcation im getting error
Spring Boot Exe is Running but does not receive Request
Deat Support Team,
I have created webservices.exe from webservices.jar as provided information.
webservices.exe is running perfectly but does not entertain any request however jar file is working perfectly.
kindly help to solve the issue.
Spring boot application with Joinfaces its not working
Hi ,
hear is my sample code links for Demo web.jar and exe which i have created. if you extract demo.jar you will get demo-core.jar and demo-share.jar. and i made classes.jar using "jar cvf ../classes.jar *" . please give solution for this so that i can buy your product.
Demo.exe=>
https://drive.google.com/file/d/1l3PUdgjsF-T0VfEubKZC1QnMLM7tGw62/view?u...
demo-web.jar=>
https://drive.google.com/file/d/1fEjcweDX9HVVrFcvbGbWj3d762F_b46H/view?u...
class.jar=>
https://drive.google.com/file/d/1VhbghhsqOapGLt6thct56Ezi4zZzpmte/view?u...
Spring boot application with Joinfaces its not working
Hi ,
I have Spring boot(2.1.4) with Joinfaces application, i am trying to make my app as Exe file using Jar2exe 2.5 v. i did all steps which was provided in http://www.jar2exe.com/solutions/springboot link ( core, demo, share ) and finally made Exe file but its not working its throwing
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
java.lang.ClassCastException: com.regexlab.j2e.Handler$1 cannot be cast to java.net.JarURLConnection
please do some need full to solve this problem. if problem was solved i am planing to purchase your product.
please reply back as soon as posible.
Thanks & Regards,
Dinesh
Could you send the demo jar files
demo jar files and created exe files
Spring boot application with Joinfaces its not working
Hi ,
I have replyed with jar files long back ago but till now i did not got reply from your end. please let me know if you dont have any solution for that problem i will try some other solution if you dont have solution. please replay at least.
my contact email id: dineshkumarg1991@gmail.com
Regards,
Dinesh
Add new comment