maven构建项目若干问题整理

来源:互联网 发布:手机传软件 编辑:程序博客网 时间:2024/05/20 13:40

第一: 依赖问题

maven中maven dependencies中依赖出现了项目,把依赖的项目关掉,项目消失,但是还是无法打包 ,出现的错误如图。说明:依赖的项目为project-dao  打包的项目为project-service  都在project-parent中有依赖。project-dao是可以打包成功的。project-service中依赖dao的jar包也可以过来。

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building project-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.507s
[INFO] Finished at: Thu May 22 09:45:55 CST 2014
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project project-service: Could not resolve dependencies for project com.newhero.project:project-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies for [com.newhero.project:project-dao:jar:0.0.1-SNAPSHOT (compile?)]: Failed to read artifact descriptor for com.newhero.project:project-dao:jar:0.0.1-SNAPSHOT: Could not find artifact com.newhero.project:project-parent:pom:0.0.1-SNAPSHOT -> [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


解决办法是需要把parent工程,也就是package是pom的那个工程先install一下。

第二: web项目启动,报错,缺少jar包问题

例如启动web服务器报错:Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 

解决办法:可能是jar文件没有同步发布到自己项目的lib目录中, 项目点击右键 点击 Properties 选择Deployment Assembly 再点击右边的Add按钮 选择Java Build Path Entries后点击Next按钮 然后选择你的Maven Dependencies 确定即可

第三: 模块化设计

项目中常用的模块化设计,参看maven视频就可以做到,但是视频上讲的都是平级目录,很多时候,项目中的父类项目中包含子类项目,如目录结构为

其创建方法为:

1 创建一个跳过骨架的un-user项目

2 选中un-user项目, 

FILE-NEW-PROJECT-MAVEN-MAVEN MODULE,即可。

未完待续……


未完待续……

0 0
原创粉丝点击