Introduce how to encrypt spring boot project
Introduction
After a spring program is encrypted by Jar2Exe, 2 features will fail:
-
Any kind of
component-scan
will fail:Program could not automatically find and instantiate a
@Service
or@Controller
or@Mapper
bean. It could not find mapper xml file according to a wildcard such asclasspath:/mapper/*.xml
. -
Any kind of
@annotation
will fail:Such as
@Autowired
or@Value
will 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:
-
@Service
class: we split a service class into aparent class
and achild class
:-
parent class
is the real service class with business code to be encrypted. It has no annotations. -
child class
extends theparent class
, with@Service
to be auto-scaned, with@Autowired
to be injected to by spring.
-
-
@Mapper
class: 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. -
@Controller
class: usually we need not encrypt. If we want, do like@Service
class 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-web
is the original spring-boot project, keep un-encrypted.@Controller
and@Service
classes are in it. -
demo-core
is to be encrypted.parent class
of@Service
are in this project. This project is a dependency ofdemo-web
. -
demo-share
contains@Mapper
classes, keep un-encrypted. In order to let@Mapper
classes accessible indemo-core
during 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.4
or above for v2.2,v2.5.2
or 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-....jar
as the main jar. -
At the step 3, input
com.regexlab.j2e.demo.DemoWebApplication
as 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.jar
and allBOOT-INF/lib/*
files as dependencies. Keep../classes.jar
anddemo-share-....jar
NOT protected. As to other jar files, we need NOT to enableProtect
because 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