构建MAVEN项目

mvn archetype:generate创建Java项目

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

构建MAVEN项目_第1张图片

分别在src/test/和src/main目录下创建resources目录

mkdir src/test/resources
mkdir src/main/resources

编译项目、结果在target/classes目录下

构建MAVEN项目_第2张图片

测试

mvn clean test

构建MAVEN项目_第3张图片

打包

mvn clean package

构建MAVEN项目_第4张图片

安装

mvn clean install
跳过测试:
mvn clean install -DskipTests

错误处理

[ERROR] Failed to execute goal on project hdfsUtils: Could not resolve dependencies for project com.changtu:hdfsUtils:jar:1.0-SNAPSHOT: Failure to find com.oracle:ojdbc6:jar:11.2.0.2.0 in https://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 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
mvn install:install-file -Dfile=/appl/scripts/lubinsu/changtu/lib/ojdbc6-11.2.0.2.0.jar-DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.2.0 -Dpackaging=jar

这是因为maven中央库并没有提供Oracle的jdbc包,我们手工添加到本地maven库中

mvn install:install-file -Dfile=/appl/scripts/lubinsu/changtu/lib/ojdbc6-11.2.0.2.0.jar-DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.2.0 -Dpackaging=jar

查看冲突的包依赖关系

mvn dependency:tree -Dverbose -Dincludes=commons-beanutils

你可能感兴趣的:(java,maven)