JAVA中MAVEN的使用
2016-02-17 00:00
555 查看
MAVEN可以方便的进行JAVA项目的管理,创建,包括部署到tomcat,都很便捷
一、MAVEN环境以及maven eclipse插件安装
安装方法参照:
http://blog.csdn.net/maosijunzi/article/details/21160965
在这里需要说明的一点是,我们在运行maven的时候,会发现每次都要重新下载一遍依赖库,原因就是我们的maven没本地化,如下是本地化方法:
1、修改maven的settings.xml【我的在D:\maven\apache-maven-3.3.3\conf目录】
<localRepository>D:/maven/apache-maven-3.3.3/repository/</localRepository>
2、修改eclipse的maven的插件为本地
window->preferences->Maven选择Installations
添加一个外部【external】的maven,Installation home选择我们安装maven的位置,我的是【D:\maven\apache-maven-3.3.3】
window->preferences->Maven选择User Settings
将User Settings【是User而不是Global Settings,不然改了我们在java build path看到的M2_REPO还是默认地址】 选择为D:\maven\apache-maven-3.3.3\conf\settings.xml可以看到下面的Local Repository为我们上面设置的。
3、打开命令行,输入mvn help:system
mvn dependency:sources
如下是常用的Maven命令:
mvn archetype:create :创建 Maven 项目
mvn compile :编译源代码
mvn test-compile :编译测试代码
mvn test : 运行应用程序中的单元测试
mvn site : 生成项目相关信息的网站
mvn clean :清除目标目录中的生成结果
mvn package : 依据项目生成 jar 文件
mvn install :在本地 Repository 中安装 jar
mvn eclipse:eclipse :生成 Eclipse 项目文件
mvn -Dmaven.test.skip=true : 忽略测试文档编译
==============================
mvn eclipse:clean
mvn eclipse:eclipse
mvn help:system
4、部署到tomcat
在部署之前,必须先启动tomcat7服务,C:\Program Files\apache-tomcat-7.0.39\bin\startup.bat
找到要部署的工程文件根目录下,执行如下maven命令
> mvn clean:install //clean是清理输出文件,install编译打包,在每次打包之前必须执行clean,才能保证发布为最新文件
> mvn tomcat7:redeploy //第一次发布 tomcat7:deploy,再次发布 tomcat7:redeploy
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
<repositories>
<repository>
<id>people.apache.snapshots</id>
<url> http://repository.apache.org/content/groups/snapshots-group/ </url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url> http://repository.apache.org/content/groups/snapshots-group/ </url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
将如下的加入到build里面,用于支持tomcat6,tomcat7部署:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>tomcat</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
<username>admin</username>
<password>123456</password>
</configuration>
</plugin>
</plugins>
</build>
一、MAVEN环境以及maven eclipse插件安装
安装方法参照:
http://blog.csdn.net/maosijunzi/article/details/21160965
在这里需要说明的一点是,我们在运行maven的时候,会发现每次都要重新下载一遍依赖库,原因就是我们的maven没本地化,如下是本地化方法:
1、修改maven的settings.xml【我的在D:\maven\apache-maven-3.3.3\conf目录】
<localRepository>D:/maven/apache-maven-3.3.3/repository/</localRepository>
2、修改eclipse的maven的插件为本地
window->preferences->Maven选择Installations
添加一个外部【external】的maven,Installation home选择我们安装maven的位置,我的是【D:\maven\apache-maven-3.3.3】
window->preferences->Maven选择User Settings
将User Settings【是User而不是Global Settings,不然改了我们在java build path看到的M2_REPO还是默认地址】 选择为D:\maven\apache-maven-3.3.3\conf\settings.xml可以看到下面的Local Repository为我们上面设置的。
3、打开命令行,输入mvn help:system
mvn dependency:sources
如下是常用的Maven命令:
mvn archetype:create :创建 Maven 项目
mvn compile :编译源代码
mvn test-compile :编译测试代码
mvn test : 运行应用程序中的单元测试
mvn site : 生成项目相关信息的网站
mvn clean :清除目标目录中的生成结果
mvn package : 依据项目生成 jar 文件
mvn install :在本地 Repository 中安装 jar
mvn eclipse:eclipse :生成 Eclipse 项目文件
mvn -Dmaven.test.skip=true : 忽略测试文档编译
==============================
mvn eclipse:clean
mvn eclipse:eclipse
mvn help:system
4、部署到tomcat
在部署之前,必须先启动tomcat7服务,C:\Program Files\apache-tomcat-7.0.39\bin\startup.bat
找到要部署的工程文件根目录下,执行如下maven命令
> mvn clean:install //clean是清理输出文件,install编译打包,在每次打包之前必须执行clean,才能保证发布为最新文件
> mvn tomcat7:redeploy //第一次发布 tomcat7:deploy,再次发布 tomcat7:redeploy
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
<repositories>
<repository>
<id>people.apache.snapshots</id>
<url> http://repository.apache.org/content/groups/snapshots-group/ </url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url> http://repository.apache.org/content/groups/snapshots-group/ </url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
将如下的加入到build里面,用于支持tomcat6,tomcat7部署:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>tomcat</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
<username>admin</username>
<password>123456</password>
</configuration>
</plugin>
</plugins>
</build>
相关文章推荐
- JAVA依托axis2实现计划任务
- JAVA类的继承派生
- JAVA多线程
- java 遍历arrayList的四种方法
- java解析json字符串
- JAVA遍历HASHMAP
- 40个JAVA问题
- eclipse中使用ctrl无法追踪函数(右键无法定位到相应的类)解决方案
- 内存管理机制-JVM 垃圾回收算法
- Java代码块
- 转: Rest简介及Spring实现
- 关于字符串的几个常见问题
- 全排列的递归实现(java代码)
- eclipse里怎么用命令行输入args
- 从头认识Spring-2.6 在注解中使用表达式@Value(2)-使用表达式注入其他对象的值
- java如何将一个序列化对象添加到压缩文件中
- Java学习之静态修饰符:static
- xwiki 7.14 Windows安装教程(jetty + MySQL5.7+jdk1.7)
- Java中 ==和equals方法的区别
- 从头认识Spring-2.6 在注解中使用表达式@Value(1)-注入普通值