今天闲来没事,因为测试需要,所以需要自己做一个jar包,但是不太懂java,目前还在学习阶段,所以使用都困难,别说使用IDEA进行打包了,我这里下载了一个springboot,学习第一课写一个HELLO WORD,所以看看springboot的结构,可以参考:https://www.wulaoer.org/?p=564
这里没有写什么,就是使用IDEA进行打包,刚过已经创建了一个demo项目,下面加载一下相关信息:
加载了springboot的插件,下面写一个hello接口
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @GetMapping("/hello") public String hello() { return "hello www.wulaoer.org"; } }
写好后,直接运行一下,使用浏览器访问一下localhost:8080/hello是否有return返回的数据,我这里就不测试了,我这里直接打包,在IDEA的右侧有一个Maven,点击一下如下图:
先是Maven---pligins---jar---jar.jar直接打包后在demon项目下有一个target目录生成一个demo-0.0.1-SNAPSHOT.jar包,就是项目的jar包。使用这个打包的时候运行jar包会出现
[root@www.wulaoer.org wulaoer]# java -jar demo-0.0.1-SNAPSHOT.jar no main manifest attribute, in demo-0.0.1-SNAPSHOT.jar
这是个错误的打包方式,看下面的
运行jar包
已经打好了jar包,就需要在服务器上运行,前提是服务上已经安装了java,这个java版本需要和你的系统中的java版本一样,我先把jar包上传到服务上。
[root@www.wulaoer.org wulaoer]# ls demo-0.0.1-SNAPSHOT.jar [root@www.wulaoer.org wulaoer]# java -jar demo-0.0.1-SNAPSHOT.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.6.RELEASE) 2020-04-28 22:29:17.013 INFO 7996 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT on CentOS1 with PID 7996 (/usr/local/wulaoer/demo-0.0.1-SNAPSHOT.jar started by root in /usr/local/wulaoer) 2020-04-28 22:29:17.022 INFO 7996 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default 2020-04-28 22:29:20.083 INFO 7996 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-04-28 22:29:20.127 INFO 7996 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-04-28 22:29:20.128 INFO 7996 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33] 2020-04-28 22:29:20.324 INFO 7996 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-04-28 22:29:20.325 INFO 7996 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3045 ms 2020-04-28 22:29:20.744 INFO 7996 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-04-28 22:29:21.160 INFO 7996 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-04-28 22:29:21.168 INFO 7996 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 5.976 seconds (JVM running for 8.227)
demo已经启动了,下面验证一下访问是否正常。
[root@www.wulaoer.org ~]# curl http://localhost:8080/hello hello www.wulaoer.org [root@www.wulaoer.org ~]#
使用idea打jar包已经完成,也使用view---tool windows----maven就可以把idea右边的maven调出来。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏