0%

lombok

2018年3月8日 上午10:35

主要功能:

Lombok是一个可以通过简单的注解形式来帮助我们简化消除一些必须有但显得很臃肿的Java代码的工具,通过使用对应的注解,可以在编译源码的时候生成对应的方法。

官网:

lombok:Project Lombok
反编译软件:Java Decompiler 功能:class->java

lombok原理


注意:

  1. @data注解会自动生成toString,EqualsAndHashCode(默认全变量),get,set方法
  2. 我们一般不使用@data,而是使用:
    1
    2
    3
    4
    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor

在项目中配置:





使用maven打包时跳过单元测试,生成class文件

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
localhost:mmallv4.0 czh$ mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com:mmall:war:2.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 292, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mmall Maven Webapp 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ mmall ---
[INFO] Deleting /Users/czh/IdeaProjects/mmallv4.0/target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ mmall ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 12 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ mmall ---
[INFO] Compiling 70 source files to /Users/czh/IdeaProjects/mmallv4.0/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ mmall ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/czh/IdeaProjects/mmallv4.0/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ mmall ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ mmall ---
[WARNING] The POM for org.apache.maven:maven-plugin-api:jar:2.0.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ mmall ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mmall] in [/Users/czh/IdeaProjects/mmallv4.0/target/mmall]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/czh/IdeaProjects/mmallv4.0/src/main/webapp]
[INFO] Webapp assembled in [647 msecs]
[INFO] Building war: /Users/czh/IdeaProjects/mmallv4.0/target/mmall.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.264s
[INFO] Finished at: Thu Mar 08 11:16:04 CST 2018
[INFO] Final Memory: 23M/369M
[INFO] ------------------------------------------------------------------------
localhost:mmallv4.0 czh$


最后,将class文件用反编译软件打开