0
点赞
收藏
分享

微信扫一扫

Mvn 插件Demo

芒果六斤半 2022-06-28 阅读 81


Mvn 插件Demo

  • ​​一、编译打包​​
  • ​​1. maven-assembly-plugin​​
  • ​​2. 资源打包​​
  • ​​3. spring-boot-maven-plugin​​
  • ​​4. maven-compiler-plugin​​
  • ​​二、scp上传、sshexec运行​​

一、编译打包

1. maven-assembly-plugin

<!-- This plugin will generate JAR MANIFEST file inside the JAR in order to make our applicationeasily runnable -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${pi.main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

2. 资源打包

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

3. spring-boot-maven-plugin

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

4. maven-compiler-plugin

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

二、scp上传、sshexec运行

<properties>
<!-- DEFAULT RASPBERRY PI PROPERTIES -->
<pi.host>192.168.1.222</pi.host>
<pi.port>22</pi.port>
<pi.user>pi</pi.user>
<pi.password>password</pi.password>
<pi.deployDirectory>/home/pi/target</pi.deployDirectory>
<pi.main.class>com.cn.testclass</pi.main.class>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- ensure the target directory exists on the Raspberry Pi -->
<sshexec host="${pi.host}" port="${pi.port}" username="${pi.user}" password="${pi.password}"
trust="true" failonerror="false" verbose="true"
command="mkdir --parents ${pi.deployDirectory}"/>

<!-- copy the JAR file to the Raspberry Pi -->
<scp
file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
todir="${pi.user}:${pi.password}@${pi.host}:${pi.deployDirectory}"
port="${pi.port}" trust="true" verbose="true" failonerror="true">
</scp>

<!-- run the JAR file on the Raspberry Pi -->
<sshexec host="${pi.host}" port="${pi.port}" username="${pi.user}"
password="${pi.password}" trust="true" failonerror="false"
verbose="true"
command="java -jar ${pi.deployDirectory}/${project.build.finalName}-jar-with-dependencies.jar"/>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</plugin>


举报

相关推荐

0 条评论