idea打jar包无法运行

写项目时遇到一个问题,在idea里能正常启动的springboot项目,打成jar包运行后报Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at com.gdky.invoice.InvoiceApplication.main(InvoiceApplication.java:12)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:203)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153)
        ... 8 common frames omitted

在网上找到一个可以解决的方案,方便以后查看

https://blog.csdn.net/qq_36159851/article/details/79699193

IDEA,你可以使用两种方法来打包Java程序为jar包。第一种方法适用于含有多个主类的jar包,而第二种方法适用于可直接执行的runnable jar包。 对于含有多个主类的jar包打包方法,你需要依次执行以下步骤: 1. 确保你已经在IDEA编写好了要打包的Java程序。 2. 在IDEA右上角点击"Artifacts",然后点击加号来创建一个新的jar包。 3. 设置jar包的名称、保存路径以及添加工程编译文件。 4. 点击OK后,返回IDEA界面,选择你的jar包名,点击"build",这样你的jar包就会打包。你可以在之前设置的路径下找到你的jar包。 5. 运行jar包程序时,使用以下命令:java -cp jar包路径 主类全类名。 对于可直接执行的runnable jar包打包方法,你需要完前四个步骤,并且执行以下额外操作: 1. 点击"Create Manifest"选项,选择你的工程名称,然后点击OK。 2. 选择你的jar文件,点击"Main Class"选项,选择你要执行的main方法所在的类,然后点击OK。 3. 回到IDEA主界面,继续之前的步骤6-7来进行操作。 4. 运行jar包程序时,使用以下命令:java -jar jar包路径。 请注意,这两种方法的运行命令是不同的,所以在使用时要确保不要搞混了。希望这些步骤能帮助你功地在IDEA打包jar包。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [ideajava程序打jar包的两种方式(超详细)](https://blog.csdn.net/qq_42239765/article/details/123236019)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [如何使用 IDEA 打 jar 包](https://blog.csdn.net/weixin_40025107/article/details/125134913)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值