mvn配置,启动脚本,及遇到的常见问题
2018-02-05 10:43
363 查看
介绍mvn配置,启动脚本,及遇到的常见问题
这两种方式都可以放在子项目下进行
复杂启动脚本
注意1 windows平台路径分隔符不是冒号是分好
注意2 文件保存为utf-8形式
注意3 windwo平台的换行符(\r\n)与linux(\n)平台不一致,需要在IDEA中转换一下,否则脚本可能会有问题
这两种方式都可以放在子项目下进行
1打包成一个jar
用maven-shade-plugin 会把配置文件打到一起,如果需要改配置文件很不方便,适于配置文件动态读取zk的情况1.1 代码
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.hnmzhc.daemon.Main</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
1.2启动命令
如:java -jar -Xmx512m -Xms256m fyt-task-1.0-SNAPSHOT.jar2精细化打包
用maven-dependency-plugin,maven-resources-plugin,maven-jar-plugin ,可以指定哪些配置文件不放入打包中2.1 mavn配置
<!-- 把依赖的jar包拷到lib目录下 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>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> <!-- 以utf-8编码拷贝配置文件,拷贝过程中是可以做变量替换的,也就是说你的配置文件可以是个模板,里面的${}所包含的内容是可以拷贝过程中替换的 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}</outputDirectory><!-- 把配置文件拷到和jar包同一个路径下 --> <resources> <resource> <directory>src/main/resources/</directory> <includes> <include>beans.xml</include> <include>jdbc.properties</include> <include>logback.xml</include> <include>startup.sh</include> </includes> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- 打jar包时需要把配置文件给排除在外 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <classifier>lib</classifier> <excludes> <exclude>beans.xml</exclude> <exclude>jdbc.properties</exclude> <exclude>logback.xml</exclude> <exclude>*.bat</exclude> </excludes> </configuration> </execution> </executions> </plugin> </plugins> </build>
2.2 启动脚本
java -Dfile.encoding=UTF-8 -classpath "lib/:.:" 包名.含mian的类名复杂启动脚本
#kconfig: - 95 15 # description: exce导入程序 start/stop/status script #Location of JAVA_HOME (bin files) export JAVA_HOME=/data/installed/jdk1.8.0_112 #Add Java binary files to PATH export PATH=$JAVA_HOME/bin:$PATH #需要启动的Java主程序(main方法类) PROGRAM_NAME="com.hnmzhc.daemon.Main" #USAGE is the message if this script is called without any options USAGE="Usage: $0 {start,stop,status,restart}" #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop SHUTDOWN_WAIT=20 tomcat_pid() { echo `ps -ef | grep $PROGRAM_NAME | grep -v grep | tr -s " "|cut -d" " -f2` } start() { pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "$PROGRAM_NAME is already running (pid: $pid)" else echo -e "Starting $PROGRAM_NAME" nohup java -Dfile.encoding=UTF-8 -classpat a7e4 h "lib/*:.:*" com.hnmzhc.daemon.Main > /dev/null 2>&1 & status fi return 0 } status(){ pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "$PROGRAM_NAME is running with pid: $pid" else echo -e "$PROGRAM_NAME is not running" fi } stop() { pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "Stoping $PROGRAM_NAME" # shutdown.sh #let kwait=$SHUTDOWN_WAIT count=0; #until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ] #do # echo -n -e "waiting for processes to exit"; # sleep 1 # let count=$count+1; #done if [ $count -gt $kwait ];then echo -n -e "killing processes which didn't stop after $SHUTDOWN_WAIT seconds" kill -9 $pid fi else echo -e "spider is not running" fi return 0 } user_exists(){ if id -u $1 >/dev/null 2>&1; then echo "1" else echo "0" fi } case $1 in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo -e $USAGE ;; esac exit 0 http://blog.csdn.net/u012152619/article/details/51485297 这个配置文件写的不错,可以参考
2.3 常见问题
打包完毕会有两个文件xxx.jar和xxx-lib.jar,前者还是包含配置文件,后者不包含,不要部署前者,两者会互相干扰注意1 windows平台路径分隔符不是冒号是分好
注意2 文件保存为utf-8形式
注意3 windwo平台的换行符(\r\n)与linux(\n)平台不一致,需要在IDEA中转换一下,否则脚本可能会有问题
相关文章推荐
- 配置了集群迁移后遇到的启动MS的问题
- 遇到不同vim配置时python脚本缩进对齐问题
- SVN安装配置及遇到的常见问题
- sqlplus 运行大量sql脚本时遇到问题分析(很常见)
- Android Studio启动配置gradle遇到的问题
- Windows7下MySQL5.5.20免安装版的配置 - (补上了我遇到的几个问题,以及mysql启动优化)
- 入职第一天就遇到这样tomcat配置问题,eclipse启动了tomcat正常,可页面还是404。
- 在配置并启动springmvc中遇到的问题
- sqlplus 运行大量sql脚本时遇到问题分析(很常见)
- mysql免安装配置教程及遇到1067服务启动不成功的问题解决方法
- iOS启动图片配置及遇到的一些问题解决
- Jenkins配置slave遇到“无法启动该应用程序”的问题
- hadoop配置时遇到的常见问题
- 配置crontab定时执行调用java程序的shell脚本遇到的问题
- 网店版重生系列:Linux下Jboss启动、关闭、端口配置等常见问题FAQ
- Hadoop 配置-启动 过程中遇到的问题
- 使用Jenkins 启动shell脚本所遇到的问题
- oracle安装常见问题-安装过程中遇到网络配置需求检查失败
- MySQL5.6性能调优 my.cnf 配置详解 和 启动失败遇到的问题
- IDEA 启动项目前的配置--或过程遇到的问题