簡化java項目部署流程

  • 將依賴包和代碼程序進行分離。
  • 將靜態文件分離。

maven打包程序和依賴分離

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>xx.xx.xx.xx</mainClass>
                        </manifest>
                    </archive>
                    <!-- 排除掉一些class-->
                                       <excludes>
                                           <exclude>*.**</exclude>
                                           <exclude>*/*.xml</exclude>
                                       </excludes>

                        
                </configuration>
            </plugin>
            <plugin>
                <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>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>    <!-- hot deploy  -->
                    <includes> 
                        <include>
                            <groupId>xx.xx</groupId>
                            <artifactId>xx</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>

分離配置文件

<resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>static/**</exclude>
                    <exclude>config/**</exclude>
                </excludes>
            </resource>
        </resources>

spring.resources.static-locations= classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/,file:D:/uploads/


        
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章