spring cloud项目部署为jsw、tomcat的pom脚本

it2022-05-05  248

1、部署为jsw pom文件

<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.macaitech</groupId> <artifactId>macaicloud</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>macaicloud-register</artifactId> <name>macaicloud-register</name> <description>注册中心</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <main.class.name>com.macaitech.macaicloud.register.macaicloudRegisterApp</main.class.name> <deploy.path>macaicloud-register</deploy.path> <!-- 发布后,部署路径 --> <app.deploy.path>/data/app</app.deploy.path> <!-- 替换运行脚本中pid文件目录,确保是绝对路径 --> <app.pid.replaceString>PIDDIR="$BASEDIR/logs"</app.pid.replaceString> <app.pid.path>PIDDIR=${app.deploy.path}/${project.name}/logs</app.pid.path> </properties> <!-- 环境 --> <profiles> <profile> <id>dev</id> <properties> <profileActive>dev</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profileActive>test</profileActive> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>local</id> <properties> <profileActive>local</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profileActive>prod</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles> <dependencies> <!--注册中心--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies> <build> <!-- 资源文件处理 --> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>logback-spring.xml</exclude> <exclude>mapper/**</exclude> <exclude>sql/**</exclude> </excludes> </resource> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <excludes> <exclude>application-dev.properties</exclude> <exclude>application-test.properties</exclude> <exclude>application-local.properties</exclude> <exclude>application-prod.properties</exclude> <exclude>application.properties</exclude> </excludes> </resource> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <includes> <include>application-${profileActive}.properties</include> <include>application.properties</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>${maven.version}</version> <executions> <execution> <id>default-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>target/classes</outputDirectory> <useDefaultDelimiters>false</useDefaultDelimiters> <delimiters> <delimiter>@</delimiter> </delimiters> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> <include>**/*.yml</include> <include>**/*.properties</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- clean插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>${maven.version}</version> <configuration> <filesets> <fileset> <directory>${basedir}/target</directory> <includes> <include>**/*</include> </includes> </fileset> </filesets> </configuration> </plugin> <!-- jar 插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>${maven.version}</version> <configuration> <archive> <manifest> <mainClass>${main.class.name}</mainClass> <addClasspath>true</addClasspath> <classpathPrefix>./</classpathPrefix> <useUniqueVersions>false</useUniqueVersions> </manifest> </archive> <includes> <include>com/**</include> </includes> <executions> <execution> <phase>clean</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </configuration> </plugin> <!--依赖jar拷贝--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>false</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <!-- 生成jsw执行脚本 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <version>2.0.0</version> <executions> <execution> <id>make-jsw</id> <phase>package</phase> <goals> <goal>generate-daemons</goal> </goals> </execution> </executions> <configuration> <!--lib下直接存放jar,没有路径文件夹(如com/apache),如果没有这个选项则放在lib下的jar包会被com/apache类似的多层文件夹包裹起来--> <repositoryLayout>flat</repositoryLayout> <repositoryName>lib</repositoryName> <configurationDirectory>conf</configurationDirectory> <configurationSourceDirectory>target/classes</configurationSourceDirectory> <copyConfigurationDirectory>false</copyConfigurationDirectory> <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath> <useWildcardClassPath>true</useWildcardClassPath> <!--生成的项目的目录位置,这里的client是项目的名称,你可以根据你的需要自己随便命名--> <target>${project.build.directory}</target> <binFileExtensions> <unix>.sh</unix> </binFileExtensions> <!-- <platforms> <platform>windows</platform> <platform>unix</platform> </platforms> --> <daemons> <daemon> <id>${project.name}</id> <platforms> <platform>jsw</platform> </platforms> <mainClass>${main.class.name}</mainClass> <generatorConfigurations> <generatorConfiguration> <generator>jsw</generator> <includes> <include>linux-x86-64</include> <!-- <include>windows-x86-64</include> <include>macosx-universal-64</include> --> </includes> <configuration> <property> <name>configuration.directory.in.classpath.first</name> <value>conf</value> </property> <property> <name>wrapper.console.loglevel</name> <value>ERROR</value> </property> <property> <name>wrapper.logfile.loglevel</name> <value>ERROR</value> </property> <property> <name>wrapper.logfile</name> <value>logs/wrapper.log</value> </property> <property> <name>wrapper.logfile.format</name> <value>M</value> </property> <property> <name>wrapper.logfile.maxsize</name> <value>10m</value> </property> <property> <name>wrapper.logfile.maxfiles</name> <value>5</value> </property> </configuration> </generatorConfiguration> </generatorConfigurations> <jvmSettings> <extraArguments> <extraArgument>-Xrs</extraArgument> <extraArgument>-server</extraArgument> <extraArgument>-Xmx2G</extraArgument> <extraArgument>-Xms512M</extraArgument> </extraArguments> </jvmSettings> </daemon> </daemons> </configuration> </plugin> <!-- 拷贝配置文件 --> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!-- <mkdir dir="${project.build.directory}/jsw/${project.name}/conf"/> --> <mkdir dir="${project.build.directory}/jsw/${project.name}/logs"/> <copy todir="${project.build.directory}/jsw/${project.name}/conf" overwrite="true" > <fileset dir="${project.build.directory}/classes" erroronmissingdir="false"> <!-- <include name="*.yml"/> <include name="*.xml"/> <include name="*.properties"/> --> <exclude name="com/**"/> <exclude name="sql/**"/> <exclude name="env/**"/> </fileset> </copy> <delete file="${project.build.directory}/${project.name}.tar"/> <tar destfile="${project.build.directory}/${project.name}.tar" basedir="${project.build.directory}/jsw"/> <replace file ="${project.build.directory}/jsw/${project.name}/bin/${project.name}" token="${app.pid.replaceString}" value="${app.pid.path}" /> <!-- <gzip destfile="${project.build.directory}/${project.name}.tar.gz" src="${project.build.directory}/${project.name}.tar"/> --> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>

2、部署到tomcat下的pom文件

<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.macaitech</groupId> <artifactId>macaitech-push</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>macaitech-push-server</artifactId> <name>macaitech-push-server</name> <description>推送服务端</description> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <profiles> <profile> <id>dev</id> <properties> <profileActive>dev</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profileActive>test</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>local</id> <properties> <profileActive>local</profileActive> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profileActive>prod</profileActive> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.corundumstudio.socketio</groupId> <artifactId>netty-socketio</artifactId> <version>1.7.17</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>io.socket</groupId> <artifactId>socket.io-client</artifactId> <version>1.0.0</version> </dependency> <!-- for deploy to tomcat start --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- for deploy to tomcat end --> </dependencies> <build> <filters> <filter>src/main/resources/env/application-${profileActive}.properties</filter> </filters> <!-- 资源文件处理 --> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>logback-spring.xml</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>application.properties</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>${maven.version}</version> <executions> <execution> <id>default-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>target/classes</outputDirectory> <useDefaultDelimiters>false</useDefaultDelimiters> <delimiters> <delimiter>@</delimiter> </delimiters> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**</include> </includes> <excludes> <exclude>env/**</exclude> </excludes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include name="*.xml"/> <include name="*.properties"/> <include name="*.json"/> <include name="*.txt"/> <include name="mapper/*.xml"/> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- clean插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>${maven.version}</version> <configuration> <filesets> <fileset> <directory>${basedir}/target</directory> <includes> <include>**/*</include> </includes> </fileset> </filesets> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>${maven.version}</version> </plugin> </plugins> </build> </project>

最新回复(0)