国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Maven打包并生成運行腳本的示例代碼

Maven打包并生成運行腳本的示例代碼

2020-07-22 17:51sic777 Java教程

這篇文章主要介紹了Maven打包并生成運行腳本,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

1.定義插件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<properties>
        <maven-jar-plugin.version>2.4</maven-jar-plugin.version>
        <maven-assembly-plugin.version>2.4</maven-assembly-plugin.version>
        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
    </properties>
    
<plugins>
  <!-- compiler -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <encoding>${project.build.sourceEncoding}</encoding>
        </configuration>
        <executions>
            <execution>
                <phase>compile</phase>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <!--jar plugin -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${maven-jar-plugin.version}</version>
        <configuration>
            <archive>
                <addMavenDescriptor>true</addMavenDescriptor>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <!--<mainClass></mainClass>-->
                </manifest>
            </archive>
            <excludes>
                <!--<exclude></exclude>-->
            </excludes>
        </configuration>
    </plugin>
    <!--assembly plugin -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>${maven-assembly-plugin.version}</version>
        <configuration>
            <descriptors>
                <descriptor>${project.basedir}/../assembly/assembly.xml</descriptor>
            </descriptors>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

2.assembly配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<assembly>
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
 
    <dependencySets>
        <!-- runtime scope jar -->
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
            <scope>runtime</scope>
        </dependencySet>
        <!-- system scope jar -->
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
            <scope>system</scope>
        </dependencySet>
    </dependencySets>
 
    <fileSets>
        <!-- script -->
        <fileSet>
            <directory>${project.basedir}/../scripts</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>0644</fileMode>
            <directoryMode>0755</directoryMode>
            <filtered>true</filtered>
        </fileSet>
        <!-- config -->
        <fileSet>
            <directory>${project.basedir}/src/main/resources</directory>
            <outputDirectory>config</outputDirectory>
            <fileMode>0644</fileMode>
            <directoryMode>0755</directoryMode>
            <includes>
                <include>*.xml</include>
                <include>*.json</include>
                <include>*.properties</include>
            </includes>
            <filtered>true</filtered>
        </fileSet>
        <!-- the project jar -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <!-- Document -->
        <fileSet>
            <directory>${project.basedir}</directory>
            <outputDirectory>doc</outputDirectory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

3.腳本

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh
#server id -- change
SERVER_ID=
#java home
JAVA_HOME=
#java command
JAVA_CMD=`which java`
#jvm option
JVM_OPT="-Xmx1024M -Xms512M -server -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
#jar name
JAR=${project.artifactId}-${project.version}.jar
#main class
MAIN_CLASS=${MainClass}
# main class args
ARGS="${StartArgs}"
#environment
ENVIRONMENT=${profiles.environment}
 
#cd working path
cd_working_path(){
  cd `dirname $0`
  cd ..
}
 
#jar
jar(){
  WK_PATH=`pwd`
  /usr/bin/nohup ${JAVA_CMD} -Denvironment=${ENVIRONMENT} -Dlog4j.configurationFile=${WK_PATH}/config/log4j2.xml ${JVM_OPT} -cp ${WK_PATH}/lib/${JAR}:${WK_PATH}/lib/* ${MAIN_CLASS} ${ARGS} >/dev/null 2>&1 &
}
 
#get pid
get_pid(){
  echo `ps -ef | grep ${JAR} | grep server_id=${SERVER_ID} |grep -v 'grep' |awk '{print $2}'`
}
 
#check
check(){
  #check server id
  if [ ! -n "$SERVER_ID" ];then
    echo "Please set up the server id 'SERVER_ID'"
    exit
  fi
}
 
#start service
start(){
  #check
  check
 
  #check pid
  PID=`get_pid`
  if [ -n "$PID" ];then
    echo "Process exists, PID >> "${PID}
    exit
  fi
 
  #check java
  if [ -n "$JAVA_HOME" ];then
    JAVA_CMD=${JAVA_HOME}/bin/java
  fi
 
  #start service
  ${JAVA_CMD} -version
  jar
 
  #check
  if [ $? -ne 0 ];then
      echo "Service startup failed."
      exit
  fi
 
  #check service
  PID=`get_pid`
  if [ ! -n "$PID" ];then
    echo "Service startup failed."
  else
    echo "Service startup success, Current environment is ${ENVIRONMENT} , PID >> "${PID}
  fi
}
 
#stop service
stop(){
  #check
  check
 
  #check pid
  PID=`get_pid`
  if [ ! -n "$PID" ];then
    echo "Process not exists."
  else
   kill ${PID}
   echo "Kill pid >> '$PID'"
    if [ $? -ne 0 ];then
      echo "Service shutdown failed."
      exit
    else
      echo "Service shutdown success."
    fi
  fi
}
 
#restart service
restart(){
  #stop service
  stop
 
  COUNT=0
  while true
  do
  PID=`get_pid`
    if [ ! -n "$PID" ];then
      #start service
      start
      break
    else
      let COUNT++
      echo "Restarting..."
       if [ ${COUNT} -eq 3 ];then
         echo "Restart error"
         exit
       fi
    fi
  sleep 3
  done
}
 
#check state
state(){
  PID=`get_pid`
 
  if [ ! -n "$PID" ];then
    echo "Service not exists."
  else
    echo "Service status is normal, PID >> '$PID'"
  fi
}
 
#main
main(){
  #cd working path
  cd_working_path
 
  if [ ! -n "$1" ];then
      echo "***********************************************"
      echo "*   start     : Start service     *"
      echo "*   stop     : Stop service      *"
      echo "*   restart    : Restart service    *"
      echo "*   state     : Check service state  *"
      echo "***********************************************"
      read -p "Please choose >> ": CASE
      PARAMETER=${CASE}
  else
    PARAMETER=$1
  fi
 
  case "$PARAMETER" in
    start)
      start
   ;;
    stop)
      stop
   ;;
    restart)
      restart
   ;;
    state)
      state
   ;;
    *)
      main
  ;;
  esac
}
 
main $1

PS:下面看下Maven打包生成可運行bat/sh腳本文件

利用Maven的appassembler-maven-plugin插件,就可以實現自動打包可運行的腳本,還可以跨平臺。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>appassembler-maven-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
      <repositoryLayout>flat</repositoryLayout>
      <repositoryName>lib</repositoryName>
      <configurationSourceDirectory>src/main/resources/conf</configurationSourceDirectory>
      <!-- Set the target configuration directory to be used in the bin scripts -->
      <configurationDirectory>conf</configurationDirectory>
      <!-- Copy the contents from "/src/main/config" to the target configuration
         directory in the assembled application -->
      <copyConfigurationDirectory>true</copyConfigurationDirectory>
      <!-- Include the target configuration directory in the beginning of
         the classpath declaration in the bin scripts -->
      <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
      <!-- prefix all bin files with "mycompany" -->
      <binPrefix>startup</binPrefix>
      <!-- set alternative assemble directory -->
      <assembleDirectory>${project.build.directory}/server</assembleDirectory>
      <!-- Extra JVM arguments that will be included in the bin scripts -->
      <extraJvmArguments>-Xms768m -Xmx768m -XX:PermSize=128m
        -XX:MaxPermSize=256m -XX:NewSize=192m -XX:MaxNewSize=384m
      </extraJvmArguments>
      <!-- Generate bin scripts for windows and unix pr default -->
      <platforms>
        <platform>windows</platform>
        <platform>unix</platform>
      </platforms>
      <programs>
        <program>
          <mainClass>com.coderli.onecoder.server.HypervisorServer</mainClass>
          <name>startup</name>
        </program>
      </programs>
    </configuration>
</plugin>

然后選擇要編譯的工程,右鍵->maven build… 命令如下圖:

package appassembler:assemble 

Maven打包并生成運行腳本的示例代碼

然后執行run,一個可執行的腳本文件就生成好了。startup.bat是windows下的,startup.sh是linux下的

Maven打包并生成運行腳本的示例代碼

總結

 

原文鏈接:https://blog.csdn.net/zzxjan/article/details/81205204

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩视频精品在线 | 99精品欧美一区二区三区 | 91精品国产91久久久 | 日韩国产欧美 | 午夜视频在线免费观看 | 91精品国产综合久久福利软件 | 日韩精品极品视频在线观看免费 | 亚洲成人久久久久 | 国产黄色91视频 | 日韩欧美在线播放 | 亚洲综合无码一区二区 | 中文成人在线 | 性高潮一级片 | 久久久久久国产精品 | 日韩av怡红院 | 亚洲精品国产精品国自产在线 | 欧美第一网站 | 日韩中文一区二区三区 | 91麻豆精品国产91久久久更新时间 | 天天干夜干 | 亚洲精品日韩综合观看成人91 | www.xxx在线观看 | 国产精品一区二区三区四区五区 | 日韩欧美一级精品久久 | 亚洲精品第一区在线观看 | 91精品久久久久久久久久 | 毛片av在线播放 | 亚洲免费一区二区 | 成人在线 | 国产高清美女一级a毛片久久 | 中文字幕亚洲综合久久久软件 | 欧美成人综合 | 91久久精品国产91久久性色tv | 91在线观看视频 | 国产一级毛片电影 | 日韩电影一区二区三区 | 国产精品第十页 | 欧美日一区 | 日韩免费av一区二区 | 亚洲国产一区二区三区 | 久久精品无码一区二区三区 |