项目构建之maven篇:2.HelloWorld项目构建过程

news/2024/7/7 21:37:16

文件结构说明:





项目构建生命周期:


清理

编译

測试

打包

执行

部署


清理与编译


hello\pom.xml


POM:Project Object Model,项目对象模型

pom.xml与ant的build.xml类似

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.hello</groupId><artifactId>hello-world</artifactId><version>1.0.0-SNAPSHOT</version>	<name>hello</name>
</project>

说明:


modelVersion:指定当前POM模型的版本号,Maven2及Maven3仅仅能是4.0.0

groupId:项目组名称

artifactId:当前Maven项目在组中的唯一的id

version:版本号


hello\src\main\java下的Hello.java

package com.demo ;
public class Hello {public void sayHi(){System.out.println("hello world");}public static void main(String [] args){new Hello().sayHi();}
}

执行清理及编译命令:


进入hello的目录路径,执行

mvn clean compile

执行结果





查看target目录的内容






查看本地仓库






測试:


hello\pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.hello</groupId><artifactId>hello-world</artifactId><version>1.0.0-SNAPSHOT</version>	<name>hello</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency></dependencies>
</project>

dependencies:指明这个项目所须要的依赖包

hello\src\test\java\HelloTest.java

package com.demo;import org.junit.Test;public class HelloTest {@Testpublic void testHello(){new Hello().sayHi();	}
}

执行測试命令

mvn clean test


查看结果





查看本地仓库





打包

执行命令


mvn clean package


查看结果






执行


又一次改造pom.xml,增加插件

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.hello</groupId><artifactId>hello-world</artifactId><version>1.0.0-SNAPSHOT</version>	<name>hello</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.5</source><target>1.5</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>1.2.1</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"><mainClass>com.demo.Hello</mainClass></transformer></transformers></configuration></execution></executions></plugin></plugins></build>
</project>


又一次执行打包命令:


mvn clean package


执行完成后,进入hello/target下,执行命令


java -jar hello-world-1.0.0-SNAPSHOT.jar



查看结果:





安装到本地仓库,供其他项目依赖


执行命令


mvn clean install



查看本地仓库





源码下载



http://lihuaxi.xjx100.cn/news/245413.html

相关文章

余承东安卓鸿蒙,鸿蒙亮点多,网友嗨了!华为P50还没定,余承东:最强大操作系统...

一生万物&#xff0c;万物归一&#xff0c;这就是鸿蒙。6月2日晚间&#xff0c;华为正式发布HarmonyOS(鸿蒙)系统&#xff0c;及多款搭载HarmonyOS的新产品&#xff0c;包括HUAWEI Mate 40系列、P40系列、Mate X2、nova 8系列等设备。这也意味着&#xff0c;鸿蒙已变成面向市场…

一对一直播app源码功能操详解方案分享

一&#xff1a;登录页面&#xff1a;1.快捷登录&#xff1a;可以利用第三方账号进行快捷登录2.手机登录&#xff1a;可以让用户通过输入手机号码和密码进行登录.3.注册&#xff1a;可以使用手机号获取验证码注册账号二&#xff1a;打开一对一直播APP首页打开APP&#xff0c;会显…

20160115广州MVP线下聚会

2016年1月15日&#xff08;星期五&#xff09;广州MVP聚会《云应该这么玩》微软公司 管震《SQL Server 磁盘瓶颈延伸讨论》 MVP舒永春《Azure与云端应用开发》 MVP李贵江《Exchange2016必须知道的几件事》 MVP丁国茂课件分享链接http://pan.baidu.com/s/1pKlnbmF &#xff08;位…

堆和栈的差别(转过无数次的文章)

一、预备知识—程序的内存分配 一个由C/C编译的程序占用的内存分为下面几个部分 1、栈区&#xff08;stack&#xff09;— 由编译器自己主动分配释放 &#xff0c;存放函数的參数值&#xff0c;局部变量的值等。其 操作方式相似于数据结构中的栈。 2、堆区&…

android活动是什么意思,android – 活动生命周期方法:onPostResume的意义

关于Activity的官方文件列出了7种生命周期方法.onPostResume()没有引用为生命周期方法.但我觉得这种方法是重要的方法.在生命周期中,当一个活动从隐藏到显示状态可见时,onRestart()onStart()onResume()onPostResume()已被调用顺序.我的代码段&#xff1a;package ravindra.proj…

debian手动安装java两种方法

2019独角兽企业重金招聘Python工程师标准>>> 方法一&#xff1a;下载后修改~/.bashrc文件 方法二&#xff1a;使用update-alternatives进行命令安装 相关配置记录 法一&#xff1a; 官网下载压缩包&#xff0c;解压&#xff0c;然后复制到/usr/lib/jvm目录下&#x…

Linux中断处理驱动程序编写【转】

转自&#xff1a;http://blog.163.com/baosongliang126/blog/static/1949357020132585316912/ 本章节我们一起来探讨一下Linux中的中断中断与定时器:中断的概念:指CPU在执行过程中&#xff0c;出现某些突发事件急待处理&#xff0c;CPU暂停执行当前程序&#xff0c;转去处理突发…

《Objective-c》Foundation框架 -(字符串:NSString和NSMutableString)

一、NSString&#xff08;不可变字符串&#xff09; 1.创建字符串的方式&#xff1a;&#xff08;利用对象方法&#xff09; 方式一&#xff1a;最快速的创建 方式二&#xff1a; 方式三&#xff1a; 方式四&#xff1a; 方式五&#xff1a;NSUTF8StringEncoding 用到中文就可以…