更新时间:2022-08-13 10:33:42
mvn install:install-file -Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar
-DgroupId=org.springframework -DartifactId=spring-context-support
-Dversion=3.1.0.RELEASE -Dpackaging=jar
高版本自带maven,需要注意的是eclipse的JRE环境目录要选择jdk下的JRE
<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">
<!--当前pom的版本号-->
<modelVersion>4.0.0</modelVersion>
<groupId>反写的公司名+项目名</groupId>
<artifactId>项目名+模块名</artifactId>
<!--
第一个 0 是大版本号
第二个 0 是分支版本号
第三个 0 是小版本号
snapshot 快照
alpha 内部测试
beta 公测
Release 稳定
GA 正式发布
-->
<version>0.0.1-SNAPSHOT</version>
<!--jar war zip pom-->
<packaging>jar</packaging>
<!--项目描述名-->
<name>test</name>
<!--项目地址-->
<url>http://maven.apache.org</url>
<!--项目描述-->
<description></description>
<developers></developers>
<licenses></licenses>
<orgnazation></orgnazation>
<!--
依赖
-->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<!--
test 表明这个构件只在junit 中可以被引用
compile 默认的
provided 只在编译中引用
runtime 编译和运行都有效
-->
<scope>test</scope>
<!--设置依赖是否可选,默认是false-->
<optional></optional>
<!--排除依赖传递列表-->
<exclusions></exclusions>
</dependency>
</dependencies>
<dependencyManagement>
</dependencyManagement>
<build>
<plugins>
构件三要素
</plugins>
</build>
<!--继承-->
<parent></parent>
<modules>
<module></module>
</modules>
<project>
......
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
项目A依赖B
A项目 pom.xml中配置依赖 (构件三要素)
B项目 先clean package
然后build 的 install
A 项目 compile
新建一个项目作为父项目,可以删除Test目录(无用)
然后在需要引用父项目pom文件的地方加上parent 标签里面写上 父项目的三要素
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<!-- <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version> -->
<executions>
<execution>
<!-- 在打包成功后使用jetty:run来运行 -->
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<stopKey>stop</stopKey>
<stopPort>9999</stopPort>
<scanIntervalSeconds>1</scanIntervalSeconds>
<contextXml>${project.basedir}/src/main/resources/jetty-context.xml</contextXml>
<webApp>
<contextPath>/</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>80</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<!-- 在打包成功后使用tomcat6:deploy来运行 -->
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 注意此处的url -->
<url>http://localhost:8080/manager/text</url>
<server>tomcat6</server> <!-- 此处的名字必须和setting.xml中配置的ID一致 -->
<path>/mavenProject</path> <!-- 此处的名字是项目发布的工程名 -->
</configuration>
javax.servlet
javax.servlet-api
3.0.1
provided
1.ant脚本是可以直接运行在maven中的。maven和ant最大的差别就是在于maven的编译以及所有的脚本都有一个基础,就是POM(project object model)。这个模型定义了项目的方方面面,然后各式各样的脚本在这个模型上工作,而ant完全是自己定义,显然maven更胜一筹。
2.maven对所依赖的包有明确的定义,如使用那个包,版本是多少,一目了然。而ant则通常是简单的inclde 所有的jar。导致的最终结果就是,你根本无法确定JBoss中的lib下的common-logging 是哪个版本的,唯一的方法就是打开 META-INF 目录下MANIFEST.MF。
3.maven是基于中间仓库的编译,即把编译所需要的资源放在一个中间仓库里,如jar,tld,pom,等。当编译的时候,maven会自动在仓库中找到相应的包,如果本地仓库没有,则从设定好的远程仓库中下载到本地。这一切都是自动的,而ant需要自己定义了。这个好处导致的结果就是,用maven编译的项目在发布的时候只需要发布源码,小得很,而反之,ant的发布则要把所有的包一起发布,显然maven又胜了一筹。
4.maven有大量的重用脚本可以利用,如生成网站,生成javadoc,sourcecode reference,等。而ant都需要自己去写。
5.maven目前不足的地方就是没有象ant那样成熟的GUI界面,不过mavengui正在努力中。目前使用maven***的方法还是命令行,又快又方便