apache官网下载,都是构建工具
ant和maven:
apache-ant-1.8.2-bin.zip
apache-maven-3.0.3-bin.zip
配置环境变量:window系统变量
ANT_HOME:E:\apache-ant-1.8.2
PATH:%ANT_HOME%\BIN
MAVEN_HOME:E:\apache-maven-3.0.3-bin.zip
PATH:%MAVEN_HOME%\BIN
ant打包:jar文件命令 首先去它的目录 然后运行命令 ant -cvf hello.jar *.*
war 将上面的改成 ant -cvf hello.war *.*
mavan默认存放jar的位置
C:\Documents and Settings\Administrator\.m2\repository存放项目所使用到jar文件
如果要修改默认jar文件存放的位置:
D:\OpenSources\apache-maven-3.0.3\conf\settings.xml
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
修改为
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository-->
<localRepository>D:/OpenSources/repository</localRepository>
按照maven规定的目录结构创建工程
写pom.xml
1.运行mvn compile
2.pom.xml增加
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
</dependencies>
HelloTest.java必须放在src/test/java里面
运行mvn test
3.mvn eclipse:eclipse
使用eclipse导入工程
报错:junit-4.8.jar没有成功导入:M2_REPO/junit/junit/4.8/junit-4.8.jar
点击Add Variable,在点击Configu...,在点击New
Name:M2_REPO
Path:D:\OpenSources\repository
再次运行一下mvn eclipse:eclipse
注意事项:1、参考struts2的源码的项目管理
2、maven操作时候,dos要到项目目录,再运行mvn war:war
3、maven会自动到网络上下载包
4、pom.xml中,加自己需要的包 例如spring-2.5.6,能够准确的选择版本号的包
maven命令:
mvn archetype:create 创建Maven项目
mvn compile 编译源代码
mvn test-compile 编译测试源代码
mvn test 运行应用程序中的单元测试
mvn site 生成项目相关信息的网站
mvn clean 清除项目目录中的生成结果
mvn package 根据项目生成的jar
mvn eclipse:eclipse 生成eclipse项目文件
mvn install 在本地Respository中安装jar
mvn compile 编译源代码
mvn test 运行应用程序中的单元测试
mvn run:jutry
mvn run:tomcat
mvn war:war
ant和maven:
apache-ant-1.8.2-bin.zip
apache-maven-3.0.3-bin.zip
配置环境变量:window系统变量
ANT_HOME:E:\apache-ant-1.8.2
PATH:%ANT_HOME%\BIN
MAVEN_HOME:E:\apache-maven-3.0.3-bin.zip
PATH:%MAVEN_HOME%\BIN
cmd -> ant 出现build.xml 配置成功
1、ant build.xml
<?xml version="1.0" encoding="utf-8" ?>
<project>
<project name="HelloWorld" default="run" basedir="."> //default 表示要运行的目标
//定义属性
<property name="src" value="src" />
<property name="dest" value="classes" />
<property name="hello_jar" value="hello.jar" />
//创建目录
<target name="init">
<mkdir dir="${dest}" />
</target>
//编译 到dest目录下面 depend表示依赖其他的target
<target name="jar" depends="compile">
<jar jarfile="${hello_jar}" basedir="${dest}" />
</target>
//运行 名称上面property的hello.jar
<target name="run" depends="jar">
<java classname="com.ant.Hello" classpath="${hello_jar}" />
</target>
//清理打包的垃圾文件
<target name="clean">
<delete dir="${dest}" />
<delete file="${hello_jar}" />
</target>
//depends 可以依赖多个target
<target name="rerun" depends="clean, run">
<ant target="clean" />
<ant target="run" />
</target>
</project>
</project>
ant打包:jar文件命令 首先去它的目录 然后运行命令 ant -cvf hello.jar *.*
war 将上面的改成 ant -cvf hello.war *.*
2、maven
契约式编程:有严格的目录关系
B2C:
src
main
java
hello.java //java 文件
resources
struts.xml //各种配置文件
webapp
WEB-INF
web.xml
lib
classes
test
java
helloTest.java
resources
application-test.xml
cmd -> mvn
mavan默认存放jar的位置
C:\Documents and Settings\Administrator\.m2\repository存放项目所使用到jar文件
如果要修改默认jar文件存放的位置:
D:\OpenSources\apache-maven-3.0.3\conf\settings.xml
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
修改为
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository-->
<localRepository>D:/OpenSources/repository</localRepository>
按照maven规定的目录结构创建工程
写pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven</groupId>
<artifactId>maven-hello</artifactId>
<version>1.0</version>
<name>Maven Hello</name>
</project>
1.运行mvn compile
2.pom.xml增加
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
</dependencies>
HelloTest.java必须放在src/test/java里面
运行mvn test
3.mvn eclipse:eclipse
使用eclipse导入工程
报错:junit-4.8.jar没有成功导入:M2_REPO/junit/junit/4.8/junit-4.8.jar
点击Add Variable,在点击Configu...,在点击New
Name:M2_REPO
Path:D:\OpenSources\repository
再次运行一下mvn eclipse:eclipse
注意事项:1、参考struts2的源码的项目管理
2、maven操作时候,dos要到项目目录,再运行mvn war:war
3、maven会自动到网络上下载包
4、pom.xml中,加自己需要的包 例如spring-2.5.6,能够准确的选择版本号的包
maven命令:
mvn archetype:create 创建Maven项目
mvn compile 编译源代码
mvn test-compile 编译测试源代码
mvn test 运行应用程序中的单元测试
mvn site 生成项目相关信息的网站
mvn clean 清除项目目录中的生成结果
mvn package 根据项目生成的jar
mvn eclipse:eclipse 生成eclipse项目文件
mvn install 在本地Respository中安装jar
mvn compile 编译源代码
mvn test 运行应用程序中的单元测试
mvn run:jutry
mvn run:tomcat
mvn war:war