One, you need to add plugin in the Pom.xml file,
Project directory Structure
1<build>2<plugins>3 4<plugin>5<artifactId>maven-assembly-plugin</artifactId>6<version>2.6</version>7<configuration>8<!--g:\ideaworkspace\sic_platform\probe\chromprobe\src\assembly\assembly.xml-->9<!--description file path--Ten<descriptor>src/assembly/assembly.xml</descriptor> One</configuration> A<executions> -<execution> -<id>make-assembly</id> the<!--binding to the package life cycle phase-- -<phase> Package</phase> -<goals> -<goal>single</goal> +</goals> -</execution> +</executions> A</plugin> at -</plugins> -</build>
Under Bin is the startup script, conf is the configuration file, inside can configure script parameters
Second, the Assembly.xml file is as follows: There are many configuration can refer to the official website: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
1<!---Copyright 1999-2011 Alibaba Group. - -Licensed under the Apache License,2Version 2.0 (the "License"); -You are not a use Thisfile except in compliance3With the License. -Obtain a copy of the License at--http://www.apache.org/licenses/LICENSE-2.04--unless required by applicable or agreed to writing, software-5Distributed under the License is distributed on a "as is" BASIS,-without6Warranties or CONDITIONS of any KIND, either express OR implied. - See the7License forThe specific language governing permissions and-Limitations8Under the License. -9<assembly>Ten<id>assembly</id> One<formats> A<format>tar.gz</format> -</formats> -<includeBaseDirectory>true</includeBaseDirectory> the<fileSets> -<fileSet> -<directory>src/assembly/bin</directory> -<outputDirectory>bin</outputDirectory> +<!--<fileMode>0100</fileMode>-- -</fileSet> +<fileSet> A<directory>src/assembly/conf</directory> at<outputDirectory>conf</outputDirectory> -</fileSet> -<!--If the project relies on the conf of other projects, it can be added here-- -<!--<fileSet> - -<directory>, .... /pre-api/src/main/assembly/conf</directory> in<outputDirectory>conf</outputDirectory> -</fileSet> to<fileSet> +<directory>, .... /pre-api/src/main/assembly/lib</directory> -<outputDirectory>lib</outputDirectory> the</fileSet>--> *</fileSets> $<dependencySets>Panax Notoginseng<dependencySet>
<!--package The project's dependencies into the Lib directory. - -<outputDirectory>lib</outputDirectory> the</dependencySet> +</dependencySets> A</assembly>
Three, the following is the script of start.sh, just change the path of the main method to start: Com.topsec.sic.collector.urlProbe.HeadlessChromeTest
Will output the log logs, you can view the log file in the logs to determine whether the main method is executed!
1#!/bin/Bash2CD ' DirName`3Bin_dir=' pwd '4 CD..5Deploy_dir=' pwd '6conf_dir= $DEPLOY _dir/conf7 8Server_name= ' sed '/application.host.name/!d;s/.*=//' conf/config.properties | Tr-d ' \ r '`9 Tenlogs_dir= $DEPLOY _dir/logs One if[ ! -d $LOGS _dir]; Then A mkdir $LOGS _dir - fi -stdout_file= $LOGS _dir/Stdout.log the -lib_dir= $DEPLOY _dir/Lib -lib_jars= ' ls $LIB _dir|grep. Jar|awk ' {print ' $LIB _dir '/' $} ' |tr ' \ n ' ":"` - +Java_opts= "-djava.awt.headless=true-djava.net.preferipv4stack=true-duser.timezone=asia/shanghai" -Java_debug_opts= "" + if["$" = "Debug" ]; Then AJava_debug_opts= "-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,address=8000,server=y, Suspend=n " at fi -Java_jmx_opts= "" - if["$" = "JMX" ]; Then -Java_jmx_opts= "-dcom.sun.management.jmxremote.port=1099-dcom.sun.management.jmxremote.ssl=false- Dcom.sun.management.jmxremote.authenticate=false " - fi -Java_mem_opts= "" inbits= ' Java-version 2>&1 | Grep-i 64-bit ' - if[-N "$BITS" ]; Then to# java_mem_opts= "-server-xmx2g-xms2g-xmn256m-xx:permsize=128m-xss256k-xx:+disableexplicitgc-xx:+useconcmarkswee pgc-xx:+cmsparallelremarkenabled-xx:+usecmscompactatfullcollection-xx:largepagesizeinbytes=128m-xx:+ Usefastaccessormethods-xx:+usecmsinitiatingoccupancyonly-xx:cmsinitiatingoccupancyfraction=70 " +Java_mem_opts= "-server-xmx512m-xms512m-xmn256m-xx:permsize=128m-xss256k-xx:+disableexplicitgc-xx:+ useconcmarksweepgc-xx:+cmsparallelremarkenabled-xx:+usecmscompactatfullcollection-xx:largepagesizeinbytes=128m -xx:+usefastaccessormethods-xx:+usecmsinitiatingoccupancyonly-xx:cmsinitiatingoccupancyfraction=70 " - Else the# java_mem_opts= "-SERVER-XMS1G-XMX1G-XX:PERMSIZE=128M-XX:SURVIVORRATIO=2-XX:+USEPARALLELGC" *Java_mem_opts= "-SERVER-XMS256M-XMX256M-XX:PERMSIZE=128M-XX:SURVIVORRATIO=2-XX:+USEPARALLELGC" $ fiPanax Notoginseng -Echo-e "Starting the $SERVER _name ... \c" the# nohup Java $JAVA _opts $JAVA _mem_opts $JAVA _debug_opts $JAVA _jmx_opts-classpath $CONF _dir: $LIB _jars Com.topsec.trd.sc Anner.leack.check.Main > $STDOUT _file 2>&1 & +Java $JAVA _opts $JAVA _mem_opts $JAVA _debug_opts $JAVA _jmx_opts-classpath $CONF _dir: $LIB _jars Com.topsec.sic.collector.urlProbe.HeadlessChromeTest > $STDOUT _file 2>&1 A theCount=0 + while[$COUNT-lt 1]; Do -Echo-e ". \c" $Sleep 1 $ -Count= ' Ps-ef | grep java | grep "$DEPLOY _dir" | awk ' {print $} ' | WC-l ' - the if[$COUNT-GT 0 ]; Then - BreakWuyi fi the Done - Wuecho "ok!" -Pids= ' Ps-ef | grep java | grep "$DEPLOY _dir" | awk ' {print $} '` Aboutecho "PID: $PIDS" $echo "STDOUT: $STDOUT _file"
Four, upload files to the server, execute the script
Using idea click Clean,package Package, generate Sic-probe-chromprobe-assembly.tar in target directory, upload file to server, execute command: TAR-ZXVF Sic-probe-chromprobe-assembly.tar.gz decompression, the directory structure after decompression is as follows:
1 drwxr-xr-x 6 sqy root $ 9 17:31 sic-probe-chromprobe2 -rw-r--r--1 sqy root 3414 5112 9 17:30 sic-probe-chromprobe-assembly.tar.gz3 [[email protected] prep-url-sqy]# CD sic-probe-chromprobe4 [[email protected] sic-probe-chromprobe]# ll5 Total 4 6 drwxr-xr-x 2 sqy root 9 11:35 bin7 drwxr-xr-x 2 sqy root may
9 17:00 conf8 drwxr-xr-x 2 sqy root 4096 may 9 17:30 Lib
Under the bin is the startup script, it should be noted that the script only read and write permissions, need to execute the chmod command to the script plus execute permissions
1 -rw-r--r--1 root root 2534 may 9 11:35 start.sh2 [[email protected] bin]# chmod 755 /c4>3[[email protected] bin]# ll4 Total 45 -rwxr-xr-x 1 root root 2534 may 9 11:35 start.sh
Start the script and look at the logs.
1 $./start.sh
Java,maven Project hit tar.gz package execution Main method