springboot 打包方式总结+proguard混淆+xjar加密

springboot 静态资源配置

war的使用习惯总感觉网页在jar包里非常不方便 以前总是用 下面的方式运行。

#以前总是通过这种方式将jar包和网页资源统统jar包外加载,总感觉不优雅。
java -jar -Dloader.path=lib,resource xxx.jar

利用spring得配置方式设置,在ide中的时候就把他注释掉,部署的时候打开

spring:
  #resources:
    #static-locations: file:./public/

分类打包lib和配置


<resource>
     <directory>src/main/resourcesdirectory>
      <excludes>
          <exclude>public/**exclude>
      excludes>
      <filtering>falsefiltering>
  resource>

<plugin>
    <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-maven-pluginartifactId>
    <configuration>
         <layout>ZIPlayout>
        <includes>
            <include>
                <groupId>nothinggroupId>
                <artifactId>nothingartifactId>
            include>
        includes>
     configuration>
     <executions>
         <execution>
             <goals>
                 <goal>repackagegoal>
             goals>
         execution>
     executions>
  plugin>


 <plugin>
     <groupId>org.apache.maven.pluginsgroupId>
     <artifactId>maven-dependency-pluginartifactId>
     <executions>
         <execution>
             <id>copy-dependenciesid>
             <phase>packagephase>
             <goals>
                 <goal>copy-dependenciesgoal>
             goals>
             <configuration>
                 <outputDirectory>target/liboutputDirectory>
                 <excludeTransitive>falseexcludeTransitive>
                 <stripVersion>falsestripVersion>
                 <includeScope>runtimeincludeScope>
             configuration>
         execution>
     executions>
 plugin>

通过以上几步,生成的jar会相当小,里面只有自己写的代码和配置文件。而所有的第三方的jar都在target/lib文件夹中。

progurd jar包混淆

<dependency>
     <groupId>net.sf.proguardgroupId>
      <artifactId>proguard-baseartifactId>
      <version>6.0.2version>
  dependency>
<plugin>
  <groupId>com.github.wvengengroupId>
  <artifactId>proguard-maven-pluginartifactId>
  <executions>
      <execution>
          <phase>packagephase>
          <goals><goal>proguardgoal>goals>
      execution>
  executions>
  <configuration>
      <proguardVersion>6.0.2proguardVersion>
      <injar>${project.build.finalName}.jarinjar>
      <outjar>${project.build.finalName}.jaroutjar>
      <obfuscate>trueobfuscate>
      <options>
          
          <option>-dontshrinkoption>
          
          <option>-dontoptimizeoption>
          
          <option>-dontskipnonpubliclibraryclassesoption>
          <option>-dontskipnonpubliclibraryclassmembersoption>
          
          <option>-allowaccessmodificationoption>
          
          <option>-useuniqueclassmembernamesoption>
          
          <option>-keeppackagenamesoption>
          <option>-adaptclassstringsoption>
          
          <option>-keepattributes
              Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethodoption>
          <option>-keepparameternamesoption>
          <option>-dontusemixedcaseclassnamesoption>
          <option>-dontskipnonpubliclibraryclassesoption>
          <option>-verboseoption>
          <option>-ignorewarningsoption>
          <option>-keepclassmembers class * {
              @org.springframework.beans.factory.annotation.Autowired *;
              @org.springframework.beans.factory.annotation.Value *;
              }
          option>
          
          <option>-keep class com.bh.sigApp { *; }option>

          
          <option>-keepclassmembers public class * {void set*(***);***
              get*();}option>
          

          
          <option>-keep class com.bh.controller.** option>
          <option>-keep class com.bh.service.** option>
          
          <option>-keep class com.bh.pojo.** {*;}option>
          <option>-keep class
              com.bh.dto.** {*;}option>

          <option>-keep class com.bh.config.**{*;}option>
          <option>-keep class com.bh.dao.** {*;}option>

      options>
      <libs>
          
          <lib>${java.home}/lib/rt.jarlib>
          <lib>${java.home}/lib/jce.jarlib>
      libs>
  configuration>
  <dependencies>
      <dependency>
          <groupId>net.sf.proguardgroupId>
          <artifactId>proguard-baseartifactId>
          <version>6.0.2version>
          <scope>runtimescope>
      dependency>
  dependencies>
plugin>

springboot 打包方式总结+proguard混淆+xjar加密_第1张图片
注释都没有了,工具类进行了完全混淆,其他类使用了部分混淆
springboot 打包方式总结+proguard混淆+xjar加密_第2张图片

xjar对于生成的jar 加密

<dependency>
     <groupId>com.github.core-libgroupId>
     <artifactId>xjarartifactId>
     <version>v2.0.6version>
 dependency>

在这里插入图片描述
springboot 打包方式总结+proguard混淆+xjar加密_第3张图片

你可能感兴趣的:(#,maven配置)