tianyunperfect 4 лет назад
Родитель
Сommit
acb9be236c
2 измененных файлов с 84 добавлено и 3 удалено
  1. 4 2
      app/bin/boot.sh
  2. 80 1
      app/pom.xml

+ 4 - 2
app/bin/boot.sh

@@ -38,8 +38,10 @@ JAVA_OPTS=" -XX:+UnlockExperimentalVMOptions"
 JAVA_OPTS="$JAVA_OPTS -server "
 # 垃圾收集器、设置分层编译、
 JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:+TieredCompilation"
-# 配置文件存放位置,如果有多个,则以逗号分隔
-JAVA_OPTS="$JAVA_OPTS -Dloader.path=config -Djava.io.tmpdir=./ "
+# 自定义配置文件和lib目录,多个目录用冒号分割
+# 已修改为分离 lib和 resource,所以 Dloader.path暂时不用
+#JAVA_OPTS="$JAVA_OPTS -Dloader.path=config -Djava.io.tmpdir=./tmp "
+JAVA_OPTS="$JAVA_OPTS -Djava.io.tmpdir=./tmp "
 # 服务器模式、兼容IPV4、编码(避免乱码)、禁止代码调用gc、
 JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8  -XX:+DisableExplicitGC"
 # gc 日志

+ 80 - 1
app/pom.xml

@@ -13,13 +13,92 @@
 
     <build>
         <plugins>
+            <!-- 分离lib -->
+            <plugin>
+                <!--这个插件就是把依赖的jar包复制出来放到编译后的target/lib目录,并且在打包时候排除内部依赖-->
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                            <overWriteIfNewer>true</overWriteIfNewer>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- 分离资源文件 -->
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-resources</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <resources>
+                                <resource>
+                                    <directory>src/main/resources</directory>
+                                </resource>
+                            </resources>
+                            <outputDirectory>${project.build.directory}/resources</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <!--打包jar-->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <!-- 指定资源文件目录,与打包的jar文件同级目录 -->
+                        <manifestEntries>
+                            <Class-Path>resources/</Class-Path>
+                        </manifestEntries>
+                        <manifest>
+                            <addClasspath>true</addClasspath>
+                            <classpathPrefix>lib/</classpathPrefix>
+                            <mainClass>com.alvin.Application</mainClass>
+                        </manifest>
+                    </archive>
+                    <!-- 打包时忽略的文件(也就是不打进jar包里的文件),本例将resources下的.yml、.xml、.db文件全部排除 -->
+                    <excludes>
+                        <exclude>**/*.yml</exclude>
+                        <exclude>**/*.xml</exclude>
+                        <exclude>**/*.db</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <!-- spring boot repackage -->
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <configuration>
-                    <fork>true</fork>
                     <layout>ZIP</layout>
+                    <includes>
+                        <include>
+                            <groupId>non-exists</groupId>
+                            <artifactId>non-exists</artifactId>
+                        </include>
+                    </includes>
                 </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>