feat:增加launcher-maven-plugin
This commit is contained in:
23
pom.xml
23
pom.xml
@@ -28,6 +28,7 @@
|
|||||||
<module>springboot-message</module>
|
<module>springboot-message</module>
|
||||||
<module>springboot-encrypt</module>
|
<module>springboot-encrypt</module>
|
||||||
<module>springboot-annotation</module>
|
<module>springboot-annotation</module>
|
||||||
|
<module>springboot-launcher</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -108,6 +109,12 @@
|
|||||||
<version>0.1.9</version>
|
<version>0.1.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tiesheng</groupId>
|
||||||
|
<artifactId>springboot-launcher</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>easyexcel</artifactId>
|
<artifactId>easyexcel</artifactId>
|
||||||
@@ -126,6 +133,17 @@
|
|||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.tiesheng</groupId>
|
||||||
|
<artifactId>launcher-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>initScript</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
@@ -134,10 +152,7 @@
|
|||||||
<includeSystemScope>true</includeSystemScope>
|
<includeSystemScope>true</includeSystemScope>
|
||||||
<!-- 打包后的jar可直接执行 -->
|
<!-- 打包后的jar可直接执行 -->
|
||||||
<executable>true</executable>
|
<executable>true</executable>
|
||||||
<embeddedLaunchScriptProperties>
|
<embeddedLaunchScript>${basedir}/target/launchScript</embeddedLaunchScript>
|
||||||
<logFolder>/dev</logFolder>
|
|
||||||
<logFilename>null</logFilename>
|
|
||||||
</embeddedLaunchScriptProperties>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@@ -37,12 +37,13 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.tiesheng</groupId>
|
||||||
|
<artifactId>launcher-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
|
||||||
<embeddedLaunchScript>../script/launchScript</embeddedLaunchScript>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
32
springboot-launcher/pom.xml
Normal file
32
springboot-launcher/pom.xml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.tiesheng</groupId>
|
||||||
|
<artifactId>launcher-maven-plugin</artifactId>
|
||||||
|
<packaging>maven-plugin</packaging>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-annotations</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.tiesheng.launcher;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定调用本类execute()方法的目标
|
||||||
|
**/
|
||||||
|
@Mojo(name = "initScript", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)
|
||||||
|
public class CopyLauncherScriptMojo extends AbstractMojo {
|
||||||
|
|
||||||
|
@Parameter(defaultValue = "${basedir}/target", required = true)
|
||||||
|
private File outputDirectory;
|
||||||
|
|
||||||
|
public void setOutputDirectory(File outputDirectory) {
|
||||||
|
this.outputDirectory = outputDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws MojoExecutionException {
|
||||||
|
try {
|
||||||
|
copy("launchScript");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new MojoExecutionException("copy launchScript error!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制脚本
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void copy(String filename) throws IOException {
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream("/" + filename);
|
||||||
|
BufferedWriter writer = null;
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
|
File target = new File(outputDirectory + "/" + filename);
|
||||||
|
target.setExecutable(true, false);
|
||||||
|
target.setWritable(true, false);
|
||||||
|
target.setReadable(true, false);
|
||||||
|
writer = new BufferedWriter(new FileWriter(target));
|
||||||
|
while (true) {
|
||||||
|
String line = reader.readLine();
|
||||||
|
if (line == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
writer.write(line);
|
||||||
|
writer.newLine();
|
||||||
|
}
|
||||||
|
writer.flush();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -105,7 +105,7 @@ await_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Determine the script mode
|
# Determine the script mode
|
||||||
action="run"
|
action="config"
|
||||||
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
|
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
|
||||||
action="$1"
|
action="$1"
|
||||||
shift
|
shift
|
||||||
@@ -220,6 +220,21 @@ run() {
|
|||||||
return "$result"
|
return "$result"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config() {
|
||||||
|
|
||||||
|
## 设置自启动
|
||||||
|
ln -s $jarfile /etc/init.d/$1
|
||||||
|
chkconfig --add $1
|
||||||
|
|
||||||
|
## 生成配置文件
|
||||||
|
working_dir=$(dirname "$jarfile")
|
||||||
|
conf_file="$working_dir/$configfile"
|
||||||
|
echo "LOG_FOLDER=/dev" > $conf_file
|
||||||
|
echo "LOG_FILENAME=null" >> $conf_file
|
||||||
|
echo "RUN_ARGS='--server.port=$2 --spring.profiles.active=$3'" >> $conf_file
|
||||||
|
echo "JAVA_OPTS='-Dfile.encoding=utf-8'" >> $conf_file
|
||||||
|
}
|
||||||
|
|
||||||
# Call the appropriate action function
|
# Call the appropriate action function
|
||||||
case "$action" in
|
case "$action" in
|
||||||
start)
|
start)
|
||||||
@@ -232,8 +247,10 @@ status)
|
|||||||
status "$@"; exit $?;;
|
status "$@"; exit $?;;
|
||||||
run)
|
run)
|
||||||
run "$@"; exit $?;;
|
run "$@"; exit $?;;
|
||||||
|
config)
|
||||||
|
config "$1" "$2" "$3" ; exit $?;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 {start|stop|restart|status|run}"; exit 1;
|
echo "Usage: $0 {start|stop|restart|status|run|config}"; exit 1;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
Reference in New Issue
Block a user