Maven项目管理(相关配置)
2015-11-20 18:24
417 查看
pom.xml右键run as 。maven build
在goals中填入(选填)
pom文件提示错误,信息如下
Description Resource Path Location Type
Failure to transfer com.thoughtworks.xstream:xstream:jar:1.4.3 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.thoughtworks.xstream:xstream:jar:1.4.3 from/to central (http://repo.maven.apache.org/maven2): No response received after 60000 pom.xml /testweb line 1 Maven Configuration Problem
或者
Failure to transfer org.apache.maven.plugins:maven-surefire-plugin
网上搜到的方案 如下
1 删除m2\repository 所有 .lastUpdated为扩展名的文件
2 打开cmd 在 工程目录执行 mvn clean install -U ,注意U 大写
这两个方案我本地都不好使。。。
最后用最笨的方法,把另一台电脑的 respository目录直接拷贝覆盖本地的,
问题解决
这里有以下规则:
在goals中填入(选填)
clean 清理 compile 编译 tes 测试 package 打包 install 部署
解决maven项目update project会更改jdk版本问题
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
pom文件提示错误,信息如下
Description Resource Path Location Type
Failure to transfer com.thoughtworks.xstream:xstream:jar:1.4.3 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.thoughtworks.xstream:xstream:jar:1.4.3 from/to central (http://repo.maven.apache.org/maven2): No response received after 60000 pom.xml /testweb line 1 Maven Configuration Problem
或者
Failure to transfer org.apache.maven.plugins:maven-surefire-plugin
网上搜到的方案 如下
1 删除m2\repository 所有 .lastUpdated为扩展名的文件
2 打开cmd 在 工程目录执行 mvn clean install -U ,注意U 大写
这两个方案我本地都不好使。。。
最后用最笨的方法,把另一台电脑的 respository目录直接拷贝覆盖本地的,
问题解决
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</>指定pom当前版本 <groupId>反写公司网址+项目名</>定义maven属于哪个实际项目 <artifactId>项目名+模块名</>实际项目中一个模块的标识 <version></> 第一个0标识大版本号 第二个0标识分支版本号 第三个0表示小版本号 0.0.1 snapshot快照 alpha内部测试 beta公测 Release稳定 GA正式发布 <packaging></> 默认是jar war zip pom <properties> 定义一些复用内容,方便统一修改 </> <name>项目名称</> <url>项目地址</> <description>项目描述</> <developers>开发人员列表</> <licenses>许可证信息</> <organization>组织信息</> <dependencies> 依赖列表 <dependency> 依赖项 <groupId></> <artifactId></> <verion></> <type></> <scope>test</> 依赖范围 <optional>设置依赖是否可选</> <!--排除依赖传递列表> <exclusions> <exclusion> </exclusion> </exclusions> </dependency> </dependencies> 依赖管理 <dependencyManagerment> 父模块中定义,子模块中直接继承就可以 <dependencies> <dependency></> </dependencies> </dependencyManagerment> <build> 插件列表 <plugin> <groupId></> <artifactId></> </plugin> </> <parent>继承于哪个maven</> <modules> <module>../com-a</> <module>../com-b</> <module>../com-c</> </> </project>
plugins
这里可以定义一个插件的版本等相关信息<properties> <!-- Plugin的属性定义 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <!-- 这里使用了java.version来引用上文的版本信息 --> <source>${java.version}</source> <target>${java.version}</target> <showWarnings>true</showWarnings> </configuration> </plugin> </plugins> <build>
依赖范围
<dependencies> 依赖列表 <dependency> 依赖项 <groupId>junit</> <artifactId>junit</> <verion>3.8.1</> <dependencyManagerment> <dependencies> compile:默认范围 编译测试运行都有效 provided:编译和测试有效 runtiome:测试和运行时有效 test:测试范围有效 system:编译和测试有效,与本机系统关联,可移植性差 import:只使用在中有用,表示从其他的pom中导入dependecy的配置 <scope>test</> </dependency> </dependencies>
依赖的传递
添加依赖 <dependencies> <dependency> <groupId>junit</> <artifactId>junit</> <verion>3.8.1</> </dependency> </dependencies>
排除依赖 <dependencies> <dependency> <groupId>junit</> <artifactId>junit</> <verion>3.8.1</> </dependency> <exclusions> <exclusion> <groupId>com.yy</> <artifactId>com-yy</> <verion>3.1.1</> </exclusion> </exclusions> </dependencies>
修改maven的jdk版本
找到setting.xml 200行左右, <profile> 其中有相关配置 </>
依赖冲突
比如a继承了b和c,但是b和c中各自导入了junit的不同的版本,那么a的junit应该是什么版本呢?这里有以下规则:
1.短路优先 (路径长度短的先解析) a->b->c->x(jar) a->d->x(jar)
2.先声明先优先 (在路径长度相同的时候,谁先声明就先解析谁) a->b->c->x(jar) a->d->e->x(jar) pom.xml中有如下配置 <dependencies> <dependency> <groupId>com-d</> <artifactId>dd</> <verion>3.7.1</> </dependency> <dependency> <groupId>com-b</> <artifactId>bb</> <verion>3.8.1</> </dependency> </dependencies> 这里是先定义的d所以这里的版本应该是更具d中的版本3.7.1
聚合和继承
聚合:将多个项目放到一起运行 新建maven项目juhe <modules> <module>../com-a</> <module>../com-b</> <module>../com-c</> </> 这样clean install这个juhe的时候就会产生上面三个jar
继承:比如过个项目都用到junit,那么可以向java一样创建一个jutint父类 新建一个parent项目 <packaging>pom</> <dependencyManagerment> <dependencies> <dependency> <groupId>junit</> <artifactId>junit</> <verion>${junit.version}</> <scope>test</> </dependency> </dependencies> </dependencyManagerment> 在子项目的pom文件中 <parent> 引入父类 <groupId>com.dd</> <artifactId>com-parent</> <verion>0.1.1-SNAPSHOT</> </parent> <dependencies> <dependency> <groupId>junit</> <artifactId>junit</> <!-- 这里verion和scope就不需要了 --> </dependency> </dependencies>
相关文章推荐
- android穿越之旅--如何弹出一个非比寻常的窗体
- QT中的各种MessageBox
- C++中的数组与指针
- 用jquery校验radio单选按钮(原创)
- 设计模式第十课 门面模式Facade Pattern
- 软件工程课程设计分组与选题名单
- ZOJ 3631超大背包问题(DFS || 折半搜索)
- U3D开发项目总结
- Zend Studio 导入项目:某些项目因位于工作空间目录而被隐藏
- 选择排序与冒泡排序
- 引导页面的现实
- Leetcode: Binary Tree Longest Consecutive Sequence
- OC基础
- 4、手把手教你Extjs5(四)主界面上加入顶部和底部区域
- CSS3的新属性
- ftp上传
- Jmeter接口测试(附件上传)
- oracle全备恢复后,再做0级增备恢复时的报错
- cobbler之ks文件编辑
- iOS开发进阶 利用Cocoapod管理代码