好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Quarkus篇入门创建项目搭建debug环境

前言

在学习一个新的框架技术前,肯定要先来一套hello word,搭建基本的运行环境和调试环境。

先来创建一个Quarkus的应用

搭建Quarkus项目

下面介绍三种创建Quarkus项目的方式

纯手工方式

1、创建maven工程,这个不多赘述,是个java程序员都会的

2、添加Quarkus依赖,下面贴出基本的依赖

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

< properties >

         < quarkus-plugin.version >1.6.0.Final</ quarkus-plugin.version >

         < quarkus.platform.version >1.6.0.Final</ quarkus.platform.version >

         < surefire-plugin.version >2.22.1</ surefire-plugin.version >

         < compiler-plugin.version >3.8.0</ compiler-plugin.version >

         < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding >

         < project.reporting.outputEncoding >UTF-8</ project.reporting.outputEncoding >

     </ properties >

     < dependencyManagement >

         < dependencies >

             < dependency >

                 < groupId >io.quarkus</ groupId >

                 < artifactId >quarkus-bom</ artifactId >

                 < version >${quarkus.platform.version}</ version >

                 < scope >import</ scope >

                 < type >pom</ type >

             </ dependency >

         </ dependencies >

     </ dependencyManagement >

     < dependencies >

         < dependency >

             < groupId >io.quarkus</ groupId >

             < artifactId >quarkus-resteasy-jsonb</ artifactId >

         </ dependency >

         <!-- Testing: -->

         < dependency >

             < groupId >io.quarkus</ groupId >

             < artifactId >quarkus-junit5</ artifactId >

             < scope >test</ scope >

         </ dependency >

         < dependency >

             < groupId >io.rest-assured</ groupId >

             < artifactId >rest-assured</ artifactId >

             < scope >test</ scope >

         </ dependency >

     </ dependencies >

     < build >

         < plugins >

             < plugin >

                 < groupId >org.apache.maven.plugins</ groupId >

                 < artifactId >maven-compiler-plugin</ artifactId >

                 < version >${compiler-plugin.version}</ version >

                 < configuration >

                     < source >1.8</ source >

                     < target >1.8</ target >

                     <!-- the parameters=true option is critical so that RESTEasy works fine -->

                     < parameters >true</ parameters >

                 </ configuration >

             </ plugin >

             < plugin >

                 <!-- you need this specific version to integrate with the other build helpers -->

                 < artifactId >maven-surefire-plugin</ artifactId >

                 < version >${surefire-plugin.version}</ version >

                 < configuration >

                     < systemPropertyVariables >

                         < java.util.logging.manager >org.jboss.logmanager.LogManager</ java.util.logging.manager >

                         < maven.home >${maven.home}</ maven.home >

                     </ systemPropertyVariables >

                 </ configuration >

             </ plugin >

             < plugin >

                 <!-- This is what injects the magic Quarkus bytecode -->

                 < groupId >io.quarkus</ groupId >

                 < artifactId >quarkus-maven-plugin</ artifactId >

                 < version >${quarkus-plugin.version}</ version >

                 < executions >

                     < execution >

                         < goals >

                             < goal >build</ goal >

                         </ goals >

                     </ execution >

                 </ executions >

             </ plugin >

         </ plugins >

     </ build >

官网装配器方式

地址:https://code.quarkus.io/

用法和spring的https://start.spring.io/一样。填好你的maven基础信息,选好依赖就可以下载工程了

IDEA方式

IDEA里已经支持创建Quarkus项目了,和spring boot的原理一样,也是基于https://code.quarkus.io/来的,所以操作的方式和网页上一样,如:

编写第一个Quarkus接口

?

1

2

3

4

5

6

7

8

9

@Produces (MediaType.TEXT_PLAIN)

@Path ( "/hello" )

public class HelloResource {

     @GET

     @Path ( "/{name}" )

     public String hello( @PathParam ( "name" ) String name) {

         return "hello" + name;

     }

}

Quarkus基于标准的jax-rs规范来写web的,当然,它也扩展了spring web的@Controller的方式,这个后面会介绍

启动你的应用并调试

1、通过运行 mvn quarkus:dev,可以启动应用,启动应用后,会发现打印了:

Listening for transport dt_socket at address: 5005

说明开启了5005调试端口,在IDEA中,可以通过

run-》Attach to process

来直接连接这个端口进行调试

2、可以新建一个main方法,直接debug模式启动,来进行运行和调试,如:

?

1

2

3

4

5

6

@QuarkusMain

public class Main {

     public static void main(String ... args) {

         Quarkus.run(args);

     }

}

以上就是Quarkus篇入门创建项目搭建debug环境的详细内容,更多关于Quarkus入门搭建debug环境的资料请关注其它相关文章!

原文链接:http://HdhCmsTestkailing.pub/article/index/arcid/286.html

查看更多关于Quarkus篇入门创建项目搭建debug环境的详细内容...

  阅读:28次