Skip to content

Maven 打包之启停脚本

Kervin edited this page Jul 5, 2021 · 1 revision

1.启动脚本

<plugin>  
    <groupId>org.codehaus.mojo</groupId>  
    <artifactId>appassembler-maven-plugin</artifactId>  
    <version>2.0.0</version>  
    <configuration>  
        <!-- 生成linux, windows两种平台的执行脚本 -->  
        <platforms>  
            <platform>windows</platform>  
            <platform>unix</platform>  
        </platforms>  
        <!-- 根目录 -->  
        <assembleDirectory>${project.build.directory}/mall</assembleDirectory>  
        <!-- 打包的jar,以及maven依赖的jar放到这个目录里面 -->  
        <repositoryName>lib</repositoryName>  
        <!-- 可执行脚本的目录 -->  
        <binFolder>bin</binFolder>  
        <!-- 配置文件的目标目录 -->  
        <configurationDirectory>conf</configurationDirectory>  
        <!-- 拷贝配置文件到上面的目录中 -->  
        <copyConfigurationDirectory>true</copyConfigurationDirectory>  
        <!-- 从哪里拷贝配置文件 (默认src/main/config) -->  
        <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>  
        <!-- lib目录中jar的存放规则,默认是${groupId}/${artifactId}的目录格式,flat表示直接把jar放到lib目录 -->  
        <repositoryLayout>flat</repositoryLayout>  
        <encoding>UTF-8</encoding>  
        <logsDirectory>logs</logsDirectory>  
        <tempDirectory>tmp</tempDirectory>  
        <programs>  
            <program>  
                <id>mall</id>  
                <!-- 启动类 -->  
                <mainClass>com.mall.Main</mainClass>  
                <jvmSettings>  
                    <extraArguments>  
                        <extraArgument>-server</extraArgument>  
                        <extraArgument>-Xmx2G</extraArgument>  
                        <extraArgument>-Xms2G</extraArgument>  
                    </extraArguments>  
                </jvmSettings>  
            </program>  
        </programs>  
    </configuration>  
</plugin>  

2.系统服务

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>appassembler-maven-plugin</artifactId>
	<version>2.0.0</version>
	<configuration>
	    <repositoryLayout>flat</repositoryLayout>
	    <repositoryName>lib</repositoryName>
	    <binFileName>service</binFileName>
	    <binFolder>bin</binFolder>
	    <configurationDirectory>conf</configurationDirectory>
	    <copyConfigurationDirectory>true</copyConfigurationDirectory>
	    <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
	    <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
	    <target>${project.build.directory}</target>
	    <daemons>
		<daemon>
		    <id>${project.name}</id>
		    <platforms>
				<!-- <platform>windows</platform>  
						<platform>unix</platform> 
						<platform>linux</platform> --> 
				<platform>jsw</platform>
			    </platforms>
		    <mainClass>com.ucloudlink.css.Application</mainClass>
		    <wrapperLogFile>logs/${project.name}.log</wrapperLogFile>
		    <generatorConfigurations>
			<generatorConfiguration>
			    <generator>jsw</generator>
			    <includes>
				<include>macosx-universal-64</include>
				<include>linux-x86-32</include>
				<include>linux-x86-64</include>
				<include>windows-x86-32</include>
				<include>windows-x86-64</include>
			    </includes>
			    <configuration>
				<property>
				    <name>configuration.directory.in.classpath.first</name>
				    <value>conf</value>
				</property>
				<property>
				    <name>set.default.REPO_DIR</name>
				    <value>lib</value>
				</property>
				<property>
				    <name>wrapper.ping.timeout</name>
				    <value>300</value>
				</property>
				<property>
				    <name>wrapper.startup.timeout</name>
				    <value>300</value>
				</property>
			    </configuration>
			</generatorConfiguration>
		    </generatorConfigurations>
		    <jvmSettings>
			<extraArguments>
			    <extraArgument>-server</extraArgument>
			    <extraArgument>-Xms128m</extraArgument>
			    <extraArgument>-Xmx128m</extraArgument>
			    <extraArgument>-Xmn60m</extraArgument>
			    <extraArgument>-XX:+UseG1GC</extraArgument>
			    <extraArgument>-Xloggc:/tmp/log/gc.log</extraArgument>
			    <extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument>
			    <extraArgument>-XX:+PrintGCDetails</extraArgument>
			    <extraArgument>-XX:+PrintGCTimeStamps</extraArgument>
			    <!--火焰图,只支持JDK8-->
			    <!--<extraArgument>-XX:+PreserveFramePointer</extraArgument>-->
			    <!--测试SSL-->
			    <!--<extraArgument>-Djavax.net.debug=ssl</extraArgument>-->
			    <!--定位OOM时启用-->
			    <!--<extraArgument>-Dio.netty.leakDetectionLevel=paranoid</extraArgument>-->
			    <!--<extraArgument>-Dio.netty.allocator.tinyCacheSize=0</extraArgument>-->
			    <!--<extraArgument>-Dio.netty.allocator.smallCacheSize=0</extraArgument>-->
			    <!--<extraArgument>-Dio.netty.allocator.normalCacheSize=0</extraArgument>-->
			</extraArguments>
		    </jvmSettings>
		</daemon>
	    </daemons>
	</configuration>
	<executions>
	    <execution>
		<id>generate-jsw-scripts</id>
		<phase>package</phase>
		<goals>
		    <goal>generate-daemons</goal>
		    <goal>create-repository</goal>
		</goals>
	    </execution>
	</executions>
</plugin>

3.maven打包

mvn clean package