关于maven

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wangyh19870928/article/details/84698157
Maven库:

http://repo2.maven.org/maven2/

Maven依赖查询:

http://mvnrepository.com/
参考:http://www.cnblogs.com/phoebus0501/archive/2011/05/10/2042511.html

Maven常用命令:
1. 创建Maven的普通java项目:
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.archetypes
-DgroupId=packageName
-DartifactId=projectName
2. 创建Maven的Web项目:
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.archetypes
-DgroupId=packageName
-DartifactId=webappName
-DarchetypeArtifactId=maven-archetype-webapp
3. 编译源代码: mvn compile
4. 编译测试代码:mvn test-compile
5. 运行测试:mvn test
6. 产生site:mvn site
7. 打包:mvn package
8. 在本地Repository中安装jar:mvn install
9. 清除产生的项目:mvn clean
10. 生成eclipse项目:mvn eclipse:eclipse
11. 生成idea项目:mvn idea:idea
12. 组合使用goal命令,如只打包不测试:mvn -Dtest package
13. 编译测试的内容:mvn test-compile
14. 只打jar包: mvn jar:jar
15. 只测试而不编译,也不测试编译:mvn test -skipping compile -skipping test-compile
( -skipping 的灵活运用,当然也可以用于其他组合命令)
16. 清除eclipse的一些系统设置:mvn eclipse:clean
一般使用情况是这样,首先通过cvs或svn下载代码到本机,然后执行mvn eclipse:eclipse生成ecllipse项目文件,然后导入到eclipse就行了;修改代码后执行mvn compile或mvn test检验,也可以下载eclipse的maven插件。

mvn -version/-v 显示版本信息
mvn archetype:generate 创建mvn项目
mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app 创建mvn项目

mvn package 生成target目录,编译、测试代码,生成测试报告,生成jar/war文件
mvn jetty:run 运行项目于jetty上,
mvn compile 编译
mvn test 编译并测试
mvn clean 清空生成的文件
mvn site 生成项目相关信息的网站
mvn -Dwtpversion=1.0 eclipse:eclipse 生成Wtp插件的Web项目
mvn -Dwtpversion=1.0 eclipse:clean 清除Eclipse项目的配置信息(Web项目)
mvn eclipse:eclipse 将项目转化为Eclipse项目

在应用程序用使用多个存储库
<repositories>
<repository>
<id>Ibiblio</id>
<name>Ibiblio</name>
<url>http://www.ibiblio.org/maven/</url>
</repository>
<repository>
<id>PlanetMirror</id>
<name>Planet Mirror</name>
<url>http://public.planetmirror.com/pub/maven/</url>
</repository>
</repositories>


mvn deploy:deploy-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar -DrepositoryId=maven-repository-inner -Durl=ftp://xxxxxxx/opt/maven/repository/


发布第三方Jar到本地库中:

mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar


-DdownloadSources=true

-DdownloadJavadocs=true

mvn -e 显示详细错误 信息.

mvn validate 验证工程是否正确,所有需要的资源是否可用。
mvn test-compile 编译项目测试代码。 。
mvn integration-test 在集成测试可以运行的环境中处理和发布包。
mvn verify 运行任何检查,验证包是否有效且达到质量标准。
mvn generate-sources 产生应用需要的任何额外的源代码,如xdoclet。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lifxue/archive/2009/10/14/4662902.aspx

常用命令:
mvn -v 显示版本
mvn help:describe -Dplugin=help 使用 help 插件的 describe 目标来输出 Maven Help 插件的信息。
mvn help:describe -Dplugin=help -Dfull 使用Help 插件输出完整的带有参数的目标列
mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull 获取单个目标的信息,设置 mojo 参数和 plugin 参数。此命令列出了Compiler 插件的compile 目标的所有信息
mvn help:describe -Dplugin=exec -Dfull 列出所有 Maven Exec 插件可用的目标
mvn help:effective-pom 看这个“有效的 (effective)”POM,它暴露了 Maven的默认设置

mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook 创建Maven的普通java项目,在命令行使用Maven Archetype 插件
mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main Exec 插件让我们能够在不往 classpath 载入适当的依赖的情况下,运行这个程序
mvn dependency:resolve 打印出已解决依赖的列表
mvn dependency:tree 打印整个依赖树

mvn install -X 想要查看完整的依赖踪迹,包含那些因为冲突或者其它原因而被拒绝引入的构件,打开 Maven 的调试标记运行
mvn install -Dmaven.test.skip=true 给任何目标添加maven.test.skip 属性就能跳过测试
mvn install assembly:assembly 构建装配Maven Assembly 插件是一个用来创建你应用程序特有分发包的插件

mvn jetty:run 调用 Jetty 插件的 Run 目标在 Jetty Servlet 容器中启动 web 应用
mvn compile 编译你的项目
mvn clean install 删除再编译

mvn hibernate3:hbm2ddl 使用 Hibernate3 插件构造数据库
展开阅读全文

关于maven搭建的项目

08-31

下面就是控制台报的错误:rn[INFO] Scanning for projects...rn[WARNING] rn[WARNING] Some problems were encountered while building the effective model for commbankmgmt:commbankmgmt:war:0.0.1-SNAPSHOTrn[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: javax.servlet:servlet-api:jar -> version 2.4 vs 2.5 @ commbankmgmt:parent:0.0.1-SNAPSHOT, D:\workspace\jsbankmgmt\parent\pom.xml, line 596, column 15rn[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: javax.servlet.jsp:jsp-api:jar -> version 2.0 vs 2.1 @ commbankmgmt:parent:0.0.1-SNAPSHOT, D:\workspace\jsbankmgmt\parent\pom.xml, line 607, column 21rn[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 20, column 12rn[WARNING] rn[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.rn[WARNING] rn[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.rn[WARNING] rn[INFO] rn[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1rn[INFO] rn[INFO] ------------------------------------------------------------------------rn[INFO] Building commbankmgmt 0.0.1-SNAPSHOTrn[INFO] ------------------------------------------------------------------------rn[INFO] Downloading: http://repo.maven.apache.org/maven2/net/sf/ehcache/ehcache-terracotta-root/2.3.0/ehcache-terracotta-root-2.3.0.pomrn[INFO] Downloading: http://repository.jboss.com/maven2/net/sf/ehcache/ehcache-terracotta-root/2.3.0/ehcache-terracotta-root-2.3.0.pomrn[WARNING] The POM for captcha:captcha:jar:1.2.1 is missing, no dependency information availablern[WARNING] The POM for qrcode:qrcode:jar:1.0 is missing, no dependency information availablern[WARNING] The POM for qrDEcode:qrDEcode:jar:1.0 is missing, no dependency information availablern[WARNING] The POM for fastjson:fastjson:jar:1.1.9 is missing, no dependency information availablern[WARNING] The POM for com.ckfinder:CKFinder:jar:2.4.2 is missing, no dependency information availablern[INFO] ------------------------------------------------------------------------rn[INFO] BUILD FAILURErn[INFO] ------------------------------------------------------------------------rn[INFO] Total time: 6.030 srn[INFO] Finished at: 2015-08-31T14:25:47+08:00rn[INFO] Final Memory: 15M/174Mrn[INFO] ------------------------------------------------------------------------rn[ERROR] Failed to execute goal on project commbankmgmt: Could not resolve dependencies for project commbankmgmt:commbankmgmt:war:0.0.1-SNAPSHOT: Failed to collect dependencies at net.sf.ehcache:ehcache-jgroupsreplication:jar:1.3 -> net.sf.ehcache:ehcache:jar:2.3.0 -> net.sf.ehcache:ehcache-terracotta:jar:2.3.0: Failed to read artifact descriptor for net.sf.ehcache:ehcache-terracotta:jar:2.3.0: Could not find artifact net.sf.ehcache:ehcache-terracotta-root:pom:2.3.0 in central (http://repo.maven.apache.org/maven2) -> [Help 1]rn[ERROR] rn[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.rn[ERROR] Re-run Maven using the -X switch to enable full debug logging.rn[ERROR] rn[ERROR] For more information about the errors and possible solutions, please read the following articles:rn[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException 论坛

关于maven的小问题

10-18

我在运行maven时出错了..哪位大侠帮我看看:rn异常为:::rnrnorg.apache.maven.MavenException: Error parsing driver.jellyrn at org.apache.maven.plugin.PluginManager.createJellyScriptHousing(PluginrnManager.java:399)rn at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:rn573)rn at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263)rn at org.apache.maven.cli.App.doMain(App.java:488)rn at org.apache.maven.cli.App.main(App.java:1239)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.rnjava:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesrnsorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at com.werken.forehead.Forehead.run(Forehead.java:551)rn at com.werken.forehead.Forehead.main(Forehead.java:581)rn--- Nested Exception ---rnjava.net.MalformedURLExceptionrn at java.net.URL.(URL.java:601)rn at java.net.URL.(URL.java:464)rn at java.net.URL.(URL.java:413)rn at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Sornurce)rn at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknownrn Source)rn at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)rn at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)rn at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)rn at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)rn at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:299)rn at org.apache.maven.jelly.JellyUtils.compileScript(JellyUtils.java:222)rn at org.apache.maven.jelly.JellyUtils.compileScript(JellyUtils.java:162)rn at org.apache.maven.plugin.PluginManager.createJellyScriptHousing(PluginrnManager.java:391)rn at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:rn573)rn at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263)rn at org.apache.maven.cli.App.doMain(App.java:488)rn at org.apache.maven.cli.App.main(App.java:1239)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.rnjava:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesrnsorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at com.werken.forehead.Forehead.run(Forehead.java:551)rn at com.werken.forehead.Forehead.main(Forehead.java:581)rnrnYou have encountered an unknown error running Maven. Please help us to correctrnthis problem by following these simple steps:rn- read the Maven FAQ at http://maven.apache.org/faq.htmlrn- run the same command again with the '-e' parameter, eg maven -e jarrn- search the maven-user archives for the error atrnhttp://nagoya.apache.org/eyebrowse/SummarizeList?listName=users@maven.apache.orgrnrn- post the output of maven -e to JIRA atrnhttp://jira.codehaus.org/BrowseProject.jspa?id=10030 (you must sign up first)rn- run 'maven --info' and post the output as the environment to the bug above 论坛

紧急求救,关于maven

07-14

[INFO] Scanning for projects...rn[WARNING] rn[WARNING] Some problems were encountered while building the effective model for com.aicaipiao:webclient:war:1.0.2-SNAPSHOTrn[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-clean-plugin is missing. @ line 285, column 12rn[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing. @ line 272, column 12rn[WARNING] rn[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.rn[WARNING] rn[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.rn[WARNING] rn[INFO] ------------------------------------------------------------------------rn[INFO] BUILD FAILURErn[INFO] ------------------------------------------------------------------------rn[INFO] Total time: 0.216srn[INFO] Finished at: Thu Jul 14 21:37:08 CST 2011rn[INFO] Final Memory: 2M/60Mrn[INFO] ------------------------------------------------------------------------rn[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]rn[ERROR] rn[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.rn[ERROR] Re-run Maven using the -X switch to enable full debug logging.rn[ERROR] rn[ERROR] For more information about the errors and possible solutions, please read the following articles:rn[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedExceptionrn这段代码是控台输出的错误信息,请问有谁遇到过这个错误,非常紧急,希望高手能指点 论坛

关于maven 项目打包问题

08-10

我的maven 项目在执行 install 的时候报错 打不包rnrn项目结构如下:rn[img=https://img-bbs.csdn.net/upload/201508/10/1439172872_60013.png][/img]rnrn一个api 另外一个是api的实现 第一个是他们的父类rnrn报错信息rn[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project yihg-travel-customer-api: Compilation failurern[ERROR] Unable to locate the Javac Compiler in:rn[ERROR] C:\Program Files\Java\jre6\..\lib\tools.jarrn[ERROR] Please ensure you are using JDK 1.4 or above andrn[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).rn[ERROR] In most cases you can change the location of your Javarn[ERROR] installation by setting the JAVA_HOME environment variable.rn[ERROR] -> [Help 1]rnorg.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project yihg-travel-customer-api: Compilation failurernUnable to locate the Javac Compiler in:rn C:\Program Files\Java\jre6\..\lib\tools.jarrnPlease ensure you are using JDK 1.4 or above andrnnot a JRE (the com.sun.tools.javac.Main class is required).rnIn most cases you can change the location of your Javarninstallation by setting the JAVA_HOME environment variable.rnrn at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)rn at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)rn at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)rn at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)rn at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)rn at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)rn at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)rn at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)rn at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)rn at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)rn at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)rn at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)rn at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)rn at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)rn at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)rnCaused by: org.apache.maven.plugin.CompilationFailureException: Compilation failurernUnable to locate the Javac Compiler in:rn C:\Program Files\Java\jre6\..\lib\tools.jarrnPlease ensure you are using JDK 1.4 or above andrnnot a JRE (the com.sun.tools.javac.Main class is required).rnIn most cases you can change the location of your Javarninstallation by setting the JAVA_HOME environment variable.rnrn at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656)rn at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)rn at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)rn at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)rn ... 19 morern[ERROR] rn[ERROR] rn[ERROR] For more information about the errors and possible solutions, please read the following articles:rn[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 论坛

没有更多推荐了,返回首页