Use maven to jar package upload server runner steps
Step 1: Add this piece of code in pom.xml
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4.1</version> <configuration> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> <archive> <manifest> <mainClass>com.jd.broadway.server.Application</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Step 2: Create the assembly.xml file, ps: the directory here is src/main/assembly/bin , and pay attention to keep it consistent when modifying.
<assembly> <id>assembly</id> <formats> <format>zip</format> <format>dir</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>config</directory> <outputDirectory>config</outputDirectory> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> </dependencySet> </dependencySets> </assembly>
Step 3: start.sh script. Put the start.sh script in the bin directory, ps: pay attention to modify the file path in the script, which is the package name + class name, and keep it consistent.
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR = `pwd`
CONF_DIR = $ DEPLOY_DIR / config
SERVER_NAME=`sed '/name/!d;s/.*=//' config/application.conf | tr -d '"\t\r\n ' | head -n 1`
SERVER_PORT=`sed '/port/!d;s/.*=//' config/application.conf | tr -d '"\t\r\n ' | head -n 1`
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
be
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
exit 1
be
if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT = `netstat -tln | grep $ SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
exit 1
be
be
LOGS_DIR="/export/Logs/producer/"
if [ -z "$LOGS_DIR" ]; then
LOGS_DIR = $ DEPLOY_DIR / logs
be
if [ ! -d $LOGS_DIR ]; then
mkdir $ LOGS_DIR
be
STDOUT_FILE=$LOGS_DIR/stdout.log
LIB_DIR = $ DEPLOY_DIR / lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_DEBUG_OPTS=""
if [ "$1" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
be
JAVA_JMX_OPTS=""
if [ "$1" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
be
JAVA_MEM_OPTS=""
BITS=`file $JAVA_HOME/bin/java | grep 64-bit`
if [ -n "$BITS" ]; then
let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`
if [ $memTotal -gt 2500 ];then
JAVA_MEM_OPTS=" -server -Xmx8000m -Xms8000m -Xmn3000m -XX:PermSize=256m -Xss2048k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=256m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
else
JAVA_MEM_OPTS=" -server -Xmx1024m -Xms1024m -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
be
else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
be
echo -e "Starting the $SERVER_NAME ...\c"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.jd.producer.ProducerNum > $STDOUT_FILE 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
if [ $COUNT -gt 0 ]; then
break
be
done
echo "OK!"
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: ${STDOUT_FILE}"
Step 4: Package, double-click the package. After the package is complete, the corresponding zip package will be generated in the target directory.
Step 5: Upload the zip package to the corresponding directory of the corresponding development machine, decompress it, and run the start.sh script in the bin directory. The corresponding log directory is specified in the script, and please pay attention to modification.
Some basic commands:
Override upload: rz -bey
Unzip: unzip xxx.zip
Run the script: ./xxx.sh
Delete directory: \rm -rf xxx/
Kill process: kill -9 PID