我是靠谱客的博主 怕孤独吐司,最近开发中收集的这篇文章主要介绍SpringBoot项目打包为jar包My Environment打jar包生成jar包运行jar包,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
My Environment
- IDEA2018.3
- JDK1.8
- SpringBoot2.3.0
- 360浏览器
项目部署一般是两种方式:
一种是打包成 jar 包直接执行,另一种是打包成 war 包放到 Tomcat 服务器下,SpringBoot一般情况下默认为jar包方式。
pom.xml:
< packaging>jar< /packaging> (默认)
< packaging>war< /packaging>
打jar包
选择 File -> Project Structure->Artifacts->Jar->Form modules with dependencies后点ok:
根据 下图内容创建 jar。如图所示,选择项目,入口类等。最后一项 META-INF,默认放到 srcmainjava 目录里,如果使用默认值,没有进行其他配置,生成的 jar 有可能不会包含 META-INF 目录,导致运行 jar 出错。最好放在 srcmainresource目录中。点击ok保存。按下图所示配置:
点击ok会出现如图所示信息:
生成jar包
点击idea菜单栏中的build,依次选择:
点Build:
在保存路经中查找所打包的jar包如果存在则说明打包成功。
运行jar包
开始运行jar包,打开cmd进入jar所在的路径,输入java -jar xxx.jar (jar名称) ,点击回车按键。
Microsoft Windows [版本 10.0.18362.959]
(c) 2019 Microsoft Corporation。保留所有权利。
C:Users92895>D:
D:>cd D:data_viewoutartifactsdata_view_jar
D:data_viewoutartifactsdata_view_jar>Java -jar data_view_jar
Error: Unable to access jarfile data_view_jar
D:data_viewoutartifactsdata_view_jar>java -jar data_view_jar
Error: Unable to access jarfile data_view_jar
D:data_viewoutartifactsdata_view_jar>java -jar data_view.jar
_________ ____.__ __
_ ___ | / /
/ / | // /
____/__| | /
______ /________| __/ /
/ /
2020-07-20 09:51:27.016 INFO 12564 --- [ restartedMain] com.dvms.DataViewApplication : Starting DataViewApplication on 4C501 with PID 12564 (D:data_viewoutartifactsdata_view_jardata_view.jar started by 92895 in D:data_viewoutartifactsdata_view_jar)
2020-07-20 09:51:27.020 INFO 12564 --- [ restartedMain] com.dvms.DataViewApplication : No active profile set, falling back to default profiles: default
2020-07-20 09:51:27.068 INFO 12564 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-07-20 09:51:27.068 INFO 12564 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-07-20 09:51:28.817 INFO 12564 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-07-20 09:51:28.831 INFO 12564 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-07-20 09:51:28.832 INFO 12564 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-07-20 09:51:28.896 INFO 12564 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-07-20 09:51:28.896 INFO 12564 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1827 ms
2020-07-20 09:51:29.631 INFO 12564 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@56cf4f3a, org.springframework.security.web.context.SecurityContextPersistenceFilter@45e169c9, org.springframework.security.web.header.HeaderWriterFilter@26d4eefe, org.springframework.security.web.authentication.logout.LogoutFilter@f17fdd6, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@5f33f6b3, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@70ffa278, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@109a14b8, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@54857a49, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@423bad4c, org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter@7e8ca12a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@3ee5e690, org.springframework.security.web.session.SessionManagementFilter@7139411a, org.springframework.security.web.access.ExceptionTranslationFilter@1ec9ee0a, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@bf4c490]
2020-07-20 09:51:29.711 INFO 12564 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-20 09:51:29.929 INFO 12564 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-07-20 09:51:29.967 INFO 12564 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-07-20 09:51:29.976 INFO 12564 --- [ restartedMain] com.dvms.DataViewApplication : Started DataViewApplication in 3.27 seconds (JVM running for 3.828)
2020-07-20 09:51:44.774 INFO 12564 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-07-20 09:51:44.775 INFO 12564 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-07-20 09:51:44.782 INFO 12564 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms
2020-07-20 09:51:56.052 INFO 12564 --- [nio-8080-exec-5] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} init
浏览器输入:localhost8080:/index(根据实际项目)显示网页说明打包成功!!!
最后
以上就是怕孤独吐司为你收集整理的SpringBoot项目打包为jar包My Environment打jar包生成jar包运行jar包的全部内容,希望文章能够帮你解决SpringBoot项目打包为jar包My Environment打jar包生成jar包运行jar包所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复