SpringBoot项目打包
1.windows版
在完成项目后需要进打包上传服务器。
-
在idea的右侧找到maven 打开项目
-
在lifecycle中先进清除我们自己生成的target包,
-
在点击:
-
在使用package进行打包
-
在我们打包的位置进行打开cmd
-
在控制台上进行运行项目(执行启动指定) java -jar xxxxx.jar(在输入jar的前面的字段使用tab键可以自动补全)
jar支持命令行启动需要依赖的maven插件支持,
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 我们要注意maven的版本,有时版本不同引起打包时出错 -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
假如我在maven打版本下进行打包会报错:
下面是我的maven的版本号:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: E:\MAVEN_life\apache-maven-3.6.3\bin\..
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: E:\JDK_life\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"```
进行的报错信息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project demo1: Input length = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[WARNING] The POM for com.alibaba:druid:jar:1.2.6 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
The POM for com.alibaba:druid:jar:1.2.6 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 4 resources
我们需要添加下面的一下配置:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
2.处理在windows端口被占用
当我们打包完成后,找到打包的位置,需要在cmd控制台上运行打包后的项目:java -jar xxxx.jar
;其中的xxxx.jar就是我们打包后的项目,
上面我们可以看到我们的端口8080被占用,这就需要我们去把8080端口关闭后在运行项目;
关闭端口:
-
查询端口
netstat -ano
可以查看全部的端口 -
查询指定端口
netstat -ano |findstr "8080(这里的8080是我们需要查找的端口号)
-
根据进程PID查询进程名称:
tasklist |findstr “7744(上图标记处)"
可以看到我们电脑中在使用这个端口的程序,
-
根据PID结束任务进程:
taskkill /F /PID "进程PID号"
回车后,将会提示进行已经结束
-
也可以根据进行名称结束任务进程
taskkill -f -t -im "进程名称"
注意要是使用
taskkill -f -t -im "进程名称"
这个可能把关于进程名称的全部都关闭了,这样有时间会误关我们需要使用的端口
主要使用
taskkill /F /PID "进程PID号"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构