maven 플러그 인 assembly 사용 및 springboot 시작 스 크 립 트 start.sh 와 스 크 립 트 정지 stop.sh

우 리 는 프로젝트 에서 프로젝트 포장 을 만 날 수 있 으 며,assembly 를 통 해 우리 의 프로젝트 를 포장 할 수 있다.
1.우선 포장 전의 프로젝트 파일 구 조 를 살 펴 봅 니 다.
在这里插入图片描述
2.pom.xml 에 assembly 플러그 인 설정

 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
 <source>1.8</source>
 <target>1.8</target>
 </configuration>
 </plugin>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-assembly-plugin</artifactId>
 <version>2.4</version>
 <configuration>
 <appendAssemblyId>false</appendAssemblyId>
 <descriptors>
 <descriptor>src/main/assembly/assembly.xml</descriptor>
 </descriptors>
 </configuration>
 <executions>
 <execution>
 <id>make-assembly</id>
 <!--    package        -->
 <phase>package</phase>
 <goals>
 <goal>assembly</goal>
 </goals>
 </execution>
 </executions>
 </plugin>
 </plugins>
 </build>
3.assembly 이 디 렉 터 리 에 assembly.xml 파일 을 추가 합 니 다.

<assembly>
 <id>assembly</id>
 <formats>
 <!--       -->
 <format>tar.gz</format>
 </formats>

 <includeBaseDirectory>false</includeBaseDirectory>

 <fileSets>
 <fileSet>
 <directory>src/main/assembly/bin</directory>
 <outputDirectory>/bin</outputDirectory>
 <includes>
 <include>*.sh</include>
 </includes>
 <!--      -->
 <fileMode>0755</fileMode>
 </fileSet>

 <fileSet>
 <!--     -->
 <directory>src/main/resources</directory>
 <!--     -->
 <outputDirectory>/conf</outputDirectory>
 </fileSet>
 <!--        jar  -->
 <fileSet>
 <directory>${project.build.directory}</directory>
 <outputDirectory>/lib</outputDirectory>
 <includes>
 <include>*.jar</include>
 </includes>
 </fileSet>

 </fileSets>
 <!--   jar   -->
 <dependencySets>
 <dependencySet>
 <outputDirectory>lib</outputDirectory>
 </dependencySet>
 </dependencySets>

</assembly>
4.assembly:assembly 를 클릭 하면 포장 이 가능 합 니 다.
在这里插入图片描述
5.가방 을 정리 한 파일 보기
在这里插入图片描述
5、start.sh,stop.sh 파일 첨부
start.sh 파일

#!/usr/bin/env bash

#source $(dirname $0)/../../env.sh
SERVERJAR="database-project-0.0.1-SNAPSHOT.jar"
base_dir=$(dirname $0)
cd ..


if [ "$JAVA_HOME" != "" ]; then
 JAVA="$JAVA_HOME/bin/java"
else
 JAVA=java
fi



JAVA_OPTS="-server -Xms32m -Xmx32m -Xmn24m -Xss256K \
-XX:SurvivorRatio=4 -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection \
-XX:CMSInitiatingOccupancyFraction=60 -XX:+PrintGCDateStamps \
-XX:+PrintGCDetails -Xloggc:$base_dir/gc.log"

echo -n "Starting server ..."
 PID=$(ps -ef | grep database-project-0.0.1-SNAPSHOT.jar | grep -v grep |awk '{print $2}')
if [ -z "$PID" ]; then
 echo Application is already stopped
else
 echo kill $PID
 kill -9 $PID
fi

echo `pwd`
echo $SERVERJAR
echo $JAVA
echo $JAVA_OPTS
echo $JAVA_DEBUG_OPT

nohup $JAVA $JAVA_OPTS $JAVA_DEBUG_OPT -jar lib/$SERVERJAR > $base_dir/nohup.out &

if [ $? -eq 0 ];then
 # echo -n $! > "$PIDFILE"
 if [ $? -eq 0 ]
 then
 sleep 1
 echo STARTED
 else
 echo FAILED TO WRITE PID
 exit 1
 fi
else
 echo SERVER DID NOT START
 exit 1
fi
stop.sh

#!/usr/bin/env bash


SERVERJAR="database-project-0.0.1-SNAPSHOT.jar"

base_dir=$(dirname $0)

echo -n "Stopping server ..."
 PID=$(ps -ef | grep database-project-0.0.1-SNAPSHOT.jar | grep -v grep |awk '{print $2}')
if [ -z "$PID" ]; then
 echo Application is already stopped
else
 echo kill $PID
 kill -9 $PID
fi
exit 0
파일 압축 풀기 start.sh 파일 실행
스 크 립 트 의 뜻 은 참고 할 수 있다
https://www.jb51.net/article/39506.htm
로 그 는 참고 할 수 있 습 니 다.
https://www.jb51.net/article/152599.htm
시작 실행 매개 변 수 를 참고 할 수 있 습 니 다.
https://www.jb51.net/article/161958.htm
https://www.jb51.net/article/107058.htm
스 크 립 트 를 시작 할 때.../start.sh 스 크 립 트 를 시작 할 때 오류 가 발생 할 수 있 습 니 다.
No such file or directory
이것 은 윈도 우즈 에서 작 성 된 스 크 립 트 파일 로 리 눅 스에 서 형식 을 식별 할 수 없 기 때문에 start.sh 와 stop.sh 스 크 립 트 파일 을 편집 하고 set ff=unix 를 linux 환경 으로 설정 합 니 다
set ff=unix
在这里插入图片描述
스 크 립 트 시작 상황 보기
tail -f -n 500 nohup.out
在这里插入图片描述
총결산
Maven 플러그 인 assembly 사용 및 springboot 시작 스 크 립 트 start.sh 와 스 크 립 트 정지 stop.sh 에 관 한 이 글 은 여기까지 소개 합 니 다.더 많은 관련 Maven 플러그 인 assembly 는 springboot 를 사용 하여 스 크 립 트 정지 내용 을 시작 합 니 다.이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 지원 바 랍 니 다!

좋은 웹페이지 즐겨찾기