idea自动部署springboot jar包到远程服务器并通过脚本启动jar

 1.连接远程服务器:Tools->Deployment->Configuration


2.1配置好之后打开远程服务就可以直接在idea中进行拖拽查看

2.2.也可以通过项目右击deployment上传jar到服务器,此时jar会上传到第一步图三中配置的目录下。

2.3.此处后期也可以直接通过idea查看服务器上jar和本地开发中的jar包异同

如图配置文件中一行配置本地和服务器不同可直接通过idea查看到,再也不用去服务器下载该jar包到本地用压缩工具查看了,哈哈。

3.配置ssh直接进行远程服务器操作

4.将如下脚本拷贝到远程服务器jar包同目录,然后再通过上图控制台运行sh start.sh命令启动脚本即可启动服务(此处有个坑,如果自己在idea中编写脚本请将换行符设置为linux下的LF格式)。

#!/usr/bin/env bash
#!/bin/sh
RESOURCE_NAME=cnntest-1.0.0.jar

tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi

tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'App is running.'
else
    echo 'App is NOT running.'
fi

rm -f tpid
nohup java -jar ./$RESOURCE_NAME  & tail -f nohup.out
echo $! > tpid
echo Start Success!

如上,就可以做到仅通过idea将一个jar包部署到服务器并运行,简单,高效。

仅作记录。

  • 11
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 如果您在使用 Spring Boot 时依赖了两个具有相同类路径的 JAR 包,您可以通过在 Maven 或 Gradle 的依赖中指定版本号,来选择特定的 JAR 包。 例如,假设您有以下 Maven 依赖声明: ``` <dependency> <groupId>com.example</groupId> <artifactId>example-lib</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>example-lib</artifactId> <version>2.0.0</version> </dependency> ``` 在这个例子中,您可以选择使用 1.0.0 版本的 `example-lib` JAR 包,如下所示: ``` <dependency> <groupId>com.example</groupId> <artifactId>example-lib</artifactId> <version>1.0.0</version> </dependency> ``` 或者,您可以选择使用 2.0.0 版本的 `example-lib` JAR 包,如下所示: ``` <dependency> <groupId>com.example</groupId> <artifactId>example-lib</artifactId> <version>2.0.0</version> </dependency> ``` 请注意,如果您选择使用一个特定版本的 JAR 包,则在代码中使用的类应该来自您选择的版本,而不是其他版本的 JAR 包。 ### 回答2: 在使用Spring Boot时,如果依赖了两个具有相同类路径的jar包,我们可以通过以下几种方式指定要使用的jar包: 1. 排除不需要的jar包:在pom.xml文件中,可以通过<exclusions>标签排除不需要的jar包。 例如: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> ``` 通过以上配置,我们将排除了spring-boot-starter-web的默认tomcat依赖。 2. 明确指定需要的jar包版本:在pom.xml文件中,可以通过<dependencyManagement>标签指定特定的jar包版本。 例如: ``` <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.5.2</version> </dependency> </dependencies> </dependencyManagement> ``` 通过以上配置,我们明确指定了spring-boot-starter-tomcat的版本为2.5.2,保证了使用的是指定版本的jar包。 3. 调整jar包的顺序:在构建项目时,可以调整jar包的顺序,使指定的jar包被优先加载。这可以通过在IDE的构建路径或构建脚本中进行配置。 需要注意的是,对于类路径相同的jar包,我们需要根据需求来选择合适的jar包,确保项目的正确运行和功能实现。在选择jar包时,可以参考官方文档、社区推荐或者项目的特殊要求。 ### 回答3: 当依赖的两个jar包的类路径一样,可以通过在pom.xml文件中使用<exclusions>标签来排除某个jar包的依赖,从而选择指定的jar包。 首先,在pom.xml文件中定位到依赖的部分。找到需要排除的jar包的依赖项,然后在此依赖项上方,添加<exclusions>标签,如下所示: <dependency> <groupId>com.example</groupId> <artifactId>dependency1</artifactId> <version>1.0.0</version> <exclusions> <exclusion> <groupId>com.example</groupId> <artifactId>dependency2</artifactId> </exclusion> </exclusions> </dependency> 在<exclusions>标签内指定需要排除的jar包的groupId和artifactId。这样在构建项目时,Maven会排除这个特定的jar包依赖。 另外,也可以通过在<dependency>标签内指定需要依赖的jar包的版本号来选择指定的jar包,如下所示: <dependency> <groupId>com.example</groupId> <artifactId>dependency1</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>dependency2</artifactId> <version>2.0.0</version> </dependency> 以上是两种常见的方法,根据具体的项目需求决定使用哪种方法来选择指定的jar包

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值