将Maven项目的一键部署从原来的http上传改为:
compile的时候连接linux,关闭tomcat,删除logs、work,再启动tomcat,最后打包部署。
考虑了采用maven-antrun-plugin插件,但是开始一直报错,找不到jsch这些jar,但是单独运行build.xml又是好的。后来干脆直接在build.xml里面引入jar了,解决问题了,配置文件如下:
?
Pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>compile</id> <phase>compile</phase> <configuration> <target> <ant antfile="${basedir}/build.xml"> <target name="test"/> </ant> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
?
build.xml
<?xml version="1.0" ?> <project name ="DKSNS-Java-Pro" default ="test" basedir ="."> <property environment="env"/> <target name="test"> <echo message="compile classpath: ${env.ANT_HOME}"/> <path id="jsch.path"> <pathelement location="${env.ANT_HOME}\lib\ant-jsch.jar" /> <pathelement location="${env.ANT_HOME}\lib\jsch-20130131.jar" /> </path> <!-- <taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch.path" /> --> <taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jsch.path" /> <sshexec host="192.168.81.132" username="root" password="123456" trust="true" command="cd /usr/local/tomcat/bin; ./shutdown.sh; cd /usr/local/tomcat/logs; rm -rf *; cd /usr/local/tomcat/work; rm -rf *;"> </sshexec> </target> </project>
?
?