栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

web项目打包

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

web项目打包

项目打包 1.springBoot项目打包特有方式 1.pom文件

springBoot特有的打包插件

 
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
2.点击maven的install就可以直接打包成可执行jar包。


打包后就可以生产一个可执行jar包

3windows下运行

命令:java -jar -D系统参数 可执行jar包

4.linux运行

命令:java -jar backstage_web-0.0.1-SNAPSHOT.jar
别忘了更改数据库的账号密码、

server:
  port: 8081

#日志
logging:
  file:
    name: E:/logs/backstage_web.log
    #path: E:/logs/backstage_web.log
  level:
    root: info
    org.springframework: info
    com.zit.java: info
    org.mybatis: info
# mybatis配置
mybatis:
  config-location: classpath:mybatis-config.xml
  type-aliases-package: com.zit.java.pojo
  mapper-locations: mapper/*.xml

#连接四大参数
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mvc?useSSL=false&characterEncoding=utf-8&useUnicode=true&serverTimezone=Asia/Shanghai
    username: root
    password: root
  mvc:
    view:
      prefix: /templates/
      suffix: .html
  thymeleaf:
    cache: false

2.ass 1.把文件copy到目录中


编写sh文件

start.sh

#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf

APP_FILE=`sed '/spring.application.file/!d;s/.*=//' conf/boot.properties | tr -d 'r'`
SERVER_NAME=`sed '/spring.application.name/!d;s/.*=//' conf/boot.properties | tr -d 'r'`
SERVER_PORT=`sed '/spring.server.port/!d;s/.*=//' conf/boot.properties | tr -d 'r'`
SPRING_CONFIG_LOCATION=`sed '/spring.config.location/!d;s/.*=//' conf/boot.properties | tr -d 'r'`
LOGS_FILE=`sed '/spring.log.file/!d;s/.*=//' conf/boot.properties | tr -d 'r'`

if [ -z "$SERVER_NAME" ]; then
    SERVER_NAME=`hostname`
fi

# 根据进程id判断程序是否运行
PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
    echo "ERROR: The $SERVER_NAME already started!"
    echo "PID: $PIDS"
    exit 1
fi

# 查看端口号是否被占用
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
    fi
fi

LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then
    LOGS_DIR=`dirname $LOGS_FILE`
else
    LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
    mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log

#收集相关lib
#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 "
fi
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 "
fi
JAVA_MEM_OPTS=""
#java虚拟机参数
BITS=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then
    JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyonly -XX:CMSInitiatingOccupancyFraction=70 "
else
    JAVA_MEM_OPTS=" -server -Xms1g -Xmx1g -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi

# 运行java命令
echo -e "Starting the $SERVER_NAME ...c"
nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -jar -Dspring.application.name=$SERVER_NAME -Dserver.port=$SERVER_PORT -Dspring.config.location=file:$SPRING_CONFIG_LOCATION -Dlogging.file.name=$LOGS_FILE  $APP_FILE  > $STDOUT_FILE 2>&1 &


echo "OK!"
PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"

配置文件添加
confi/boot.properties

spring.application.file=backstage_web-0.0.1-SNAPSHOT.jar
spring.application.name=backstage_web
spring.server.port=8082
spring.config.location=../conf
spring.log.file=../logs/springboot.log

配置文件中添加yml文件。
config/application.yml

server:
  port: 8081

#日志
logging:
  file:
    name: E:/logs/backstage_web.log
    #path: E:/logs/backstage_web.log
  level:
    root: info
    org.springframework: info
    com.zit.java: info
    org.mybatis: info
# mybatis配置
mybatis:
  config-location: classpath:mybatis-config.xml
  type-aliases-package: com.zit.java.pojo
  mapper-locations: mapper/*.xml

#连接四大参数
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3307/mvc?useSSL=false&characterEncoding=utf-8&useUnicode=true&serverTimezone=Asia/Shanghai
    username: root
    password: root
  mvc:
    view:
      prefix: /templates/
      suffix: .html
  thymeleaf:
    cache: false

pom插件添加

   
        




                
                    
                    org.apache.maven.plugins
                    maven-jar-plugin
                    3.2.2
                    
                        
                            
                                
                                ../lib
                                
                                true
                                
                                com.zit.java.BackstageWebApplication
                            
                        
                    
                

                
                
                    maven-assembly-plugin
                    3.2.0
                    
                        
                        
                        
                            
                                assembly/assembly.xml
                            
                        
                    
                    
                        
                            make-assembly
                            package
                            
                                single
                            
                        
                    
                
        
    

打包

然后打包成tar.gz的包,点击maven的packaging 将tar.gz传到linux上,解压到/usr/local目录下。 linux下启动

安装net-tools
yum install net-tools -y
启动 start/start.sh
日志目录:与包文件同目录/logs/stdout.log

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/752316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号