java项目部署常见问题

文章介绍了如何在SpringBoot项目中将jar包和依赖包分离,通过maven插件实现,并修改启动脚本以加载lib目录下的依赖。同时,配置文件被外置到config目录,便于管理和切换环境。Nginx的配置包括路由到特定服务和web服务,以及集群配置。此外,还提到了使用Redis进行session共享的设置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、jar包和依赖包分离

在pom文件中新增:

  <!-- 注释后和依赖包一起打包 取消注释则不打包依赖-->       

 <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                
                    <includes>
                        <include>
                            <groupId>nothing</groupId>
                            <artifactId>nothing</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>

  <!-- 生成lib包-->   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-lib</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 修改启动脚本-增加-Dloader.path=lib


nohup  java -XX:+UseG1GC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -Xloggc:./gclog/gc.log  -Xms3g -Xmx3g -jar -Dloader.path=lib -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5219 opera-system.jar > default.log 2>&1 &
~    

二、配置文件外置

java -jar  启动的时候会优先读取config目录下的配置文、可以把配置文件外置到config目录下、可以通过spring.profiles.active:dev 读取特定文件

三、nginx配置

3.1 路由到特定服务

在配置文件中加如下代码

    location /ds {
        proxy_pass http://172.16.102.11:18088;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }
3.2 路由特定web 服务
  location /siling_gzxd_face/ {
        alias /u01/isi/gzdx_face/;
    }
3.3集群配置

upstream dsServer {
        server 172.16.101.31:18091;
        server 172.16.101.33:18090;
}

    location /ds {
        proxy_pass http://dsServer;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }

四、session共享

1、在pom文件中引入

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
</dependency>

2、在启动类上添加注解

@EnableRedisHttpSession(redisNamespace = "ds_system_v2:session")

五、涉及的到常见linux命令

查看端口号:  lsof -i: 18090 

[isi@meixuan-33 dqgz-system]$ lsof -i:18090
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    20633  isi  285u  IPv6 83827872      0t0  TCP *:18090 (LISTEN)
 

对 jar 解压:jar -xvf dqgz-system.jar 

springboot 项目jar包解压后、修改配置文件后、在不依赖开发工具的情况下、重新压缩jar包、命令是:jar -cvfM0 xxx.jar .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值