java项目pom文件详解_java相关:基于Maven的pom.xml文件详解

java相关:基于Maven的pom.xml文件详解

发布于 2020-7-14|

复制链接

下面小妖就为大家带来一篇基于Maven的pom.xml文件详解。小妖觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小妖过来看看吧

如下所示:

```java

xxx

xxx

xxx

xxx

4.0.0

xxx

xxx

jar

1.0-SNAPSHOT

xxx-maven

http://maven.apache.org

A maven project to study maven.

jira

http://jira.baidu.com/banseon

Demo

banseon@126.com

banseon@126.com

banseon@126.com

http:/hi.baidu.com/banseon/demo/dev/

HELLO WORLD

banseon

banseon@126.com

Project Manager

Architect

demo

http://hi.baidu.com/xxx

No

-5

Project Manager

Architect

No

Apache 2

http://www.baidu.com/banseon/LICENSE-2.0.txt

repo

A business-friendly OSS license

scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)

scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk

http://svn.baidu.com/banseon

demo

http://www.baidu.com/banseon

true/false

true/false

true/false

true/false

true/false

true/false

true/false

jdk版本,如:1.7

Windows XP

Windows

x86

5.1.2600

mavenVersion

2.0.3

/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/

/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/

true/false

true/false

true/false

true/false

true/false

true/false

banseon-repository-proxy

banseon-repository-proxy

http://192.168.1.169:9999/repository/

default

org.apache.maven

maven-artifact

3.8.1

jar

test

spring-core

org.springframework

true

true/false

true/false

banseon-maven2

banseon maven2

file://${basedir}/target/deploy

banseon-maven2

Banseon-maven2 Snapshot Repository

scp://svn.baidu.com/banseon:/usr/local/maven-snapshot

banseon-site

business api website

scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web

value。 -->

value

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中读取Mavenpom.xml文件可以使用以下步骤: 1. 创建文件对象 首先需要创建一个File对象,用于表示pom.xml文件的路径。可以使用以下代码创建File对象: ``` File pomFile = new File("pom.xml"); ``` 2. 加载pom.xml文件 使用Java的DOM解析器来加载pom.xml文件。可以使用以下代码来加载pom.xml文件: ``` DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(pomFile); ``` 3. 获取根元素 通过Document对象获取pom.xml文件的根元素。可以使用以下代码获取根元素: ``` Element root = doc.getDocumentElement(); ``` 4. 获取元素值 通过Element对象获取pom.xml文件中的元素值。可以使用以下代码获取元素值: ``` String groupId = root.getElementsByTagName("groupId").item(0).getTextContent(); String artifactId = root.getElementsByTagName("artifactId").item(0).getTextContent(); String version = root.getElementsByTagName("version").item(0).getTextContent(); ``` 以上代码将获取pom.xml文件中的groupId、artifactId和version元素的值。您可以根据需要获取其他元素的值。 完整的代码示例: ``` import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; public class ReadPomXml { public static void main(String[] args) throws Exception { File pomFile = new File("pom.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(pomFile); Element root = doc.getDocumentElement(); String groupId = root.getElementsByTagName("groupId").item(0).getTextContent(); String artifactId = root.getElementsByTagName("artifactId").item(0).getTextContent(); String version = root.getElementsByTagName("version").item(0).getTextContent(); System.out.println("groupId: " + groupId); System.out.println("artifactId: " + artifactId); System.out.println("version: " + version); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值