idea maven 多module工程怎么关联源码而不是关联本地仓库的jar?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

idea maven 多module工程怎么关联源码而不是关联本地仓库的jar?报错

2020-06-09 10:15:38 511 1

如图所示,新建了一个简单的工程,结构为:

wrap

-main 依赖mod工程

-mod

配置没问题,但在main工程里配置了jetty插件运行就会 报错,找不到mod这个依赖的jar

[ERROR] Failed to execute goal on project main: Could not resolve dependencies for project com.kongwu:main:war:1.0: Failure to find com.kongwu:mod🏺1.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]


,怎么 让他依赖于module里的文件呢,而不是依赖本地jar?
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-09 10:15:55

    其实没父目录的maven工程是有问题的。这边公司是这样的。

    正确的做法是

    root

    |-web

    |-service

    |-dao

    这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

    你可以新建project,选maven,然后一路下去。

    建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

    最后一个编译就OK了

    [INFO]Scanningforprojects...
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorBuildOrder:
    [INFO] 
    [INFO]TestMaven
    [INFO]dao
    [INFO]service
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]BuildingTestMaven1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@TestMaven---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@TestMaven---
    [INFO]InstallingD:\workspace\testMaven\pom.xmltoD:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingdao1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@dao---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO]Buildingjar:D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@dao---
    [INFO]InstallingD:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\dao\pom.xmltoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingservice1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@service---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO]Buildingjar:D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@service---
    [INFO]InstallingD:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\service\pom.xmltoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorSummary:
    [INFO] 
    [INFO]TestMaven..........................................SUCCESS[ 0.709s]
    [INFO]dao................................................SUCCESS[ 0.949s]
    [INFO]service............................................SUCCESS[ 0.088s]
    [INFO]------------------------------------------------------------------------
    [INFO]BUILDSUCCESS
    [INFO]------------------------------------------------------------------------
    [INFO]Totaltime:1.848s
    [INFO]Finishedat:2016-09-27T17:35:34+08:00
    [INFO]FinalMemory:11M/150M
    [INFO]------------------------------------------------------------------------


    Processfinishedwithexitcode0


    是我哪里弄错了么,还是idea就这么设计的嗯。我也是这么做的,但是jetty:run之后他就报错找不到依赖module的jar。。应该会找依赖项目的文件才对吧?pom.xml里面配置啊···依赖这个子模块我已经配置好了,但运行的时候他还是去本地仓库找mod这个jar,而不找模块的源码


    添加项目依赖。(这个只是保证编译时不报错)

    另外还要在子POMMOD中,加入一句这个

      
       <
       
        parent
        
         >
         
          <
          
           groupId
           
            >父GROUPID
            
             </
             
              groupId
              
               >
               
                <
                
                 artifactId
                 
                  >父ARTIFACTID
                  
                   </
                   
                    artifactId
                    
                     >
                     
                      <
                      
                       version
                       
                        >父版本
                        
                         </
                         
                          version
                          
                           >
                           
                            <
                            
                             relativePath
                             
                              >../mod/pom.xml
                              
                               </
                               
                                relativePath
                                
                                 >
                                 
                                  </
                                  
                                   parent
                                   
                                    >
                                   
                                  
                                 
                                
                               
                              
                             
                            
                           
                          
                         
                        
                       
                      
                     
                    
                   
                  
                 
                
               
              
             
            
           
          
         
        
       
      
    把mod移动和wap同级,然后修改mod中的pom代码如上。

    工程如下这样:


    怎么做到没有父目录,把这个移动到上层目录的。。。还有这一步有什么用呢

    引用来自“szwx855”的评论

    其实没父目录的maven工程是有问题的。这边公司是这样的。

    正确的做法是

    root

    |-web

    |-service

    |-dao

    这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

    你可以新建project,选maven,然后一路下去。

    建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

    最后一个编译就OK了

    [INFO]Scanningforprojects...
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorBuildOrder:
    [INFO] 
    [INFO]TestMaven
    [INFO]dao
    [INFO]service
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]BuildingTestMaven1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@TestMaven---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@TestMaven---
    [INFO]InstallingD:\workspace\testMaven\pom.xmltoD:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingdao1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@dao---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO]Buildingjar:D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@dao---
    [INFO]InstallingD:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\dao\pom.xmltoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingservice1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@service---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO]Buildingjar:D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@service---
    [INFO]InstallingD:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\service\pom.xmltoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorSummary:
    [INFO] 
    [INFO]TestMaven..........................................SUCCESS[ 0.709s]
    [INFO]dao................................................SUCCESS[ 0.949s]
    [INFO]service............................................SUCCESS[ 0.088s]
    [INFO]------------------------------------------------------------------------
    [INFO]BUILDSUCCESS
    [INFO]------------------------------------------------------------------------
    [INFO]Totaltime:1.848s
    [INFO]Finishedat:2016-09-27T17:35:34+08:00
    [INFO]FinalMemory:11M/150M
    [INFO]------------------------------------------------------------------------


    Processfinishedwithexitcode0


    回复 @空无:jetty是必须打包的。这个木有办法。所以我都用resin或者tomcat.这个jetty,在本地开必debug很蛋疼。回复 @szwx855:我换了几个环境换了电脑都是同样的结果,经测试,直接配置个本地tomcat是可以正常依赖module的,junit/main方法运行也是可以依赖的,但mavenjetty/tomcat插件跑的话就必须先把module打包到本地仓库,还是很感谢你!回复 @空无:一般是加载本地仓库的jar,在idea中看代码跟踪到jar的时候,因为它会自动反编译,所以这个时候,你点下这个class右上上角的downloadsource,然后在选择chooseSource,就定位到源码了。都有的,你的可以正常加载代码而不是本地仓库的jar吗?你看本地仓库有没有对应的jar,你删掉在看看
    0 0
相关问答

40

回答

[@徐雷frank][¥20]什么是JAVA的平台无关性

大河人家 2018-10-29 23:55:20 144748浏览量 回答数 40

162

回答

惊喜翻倍:免费ECS+免费环境配置~!(ECS免费体验6个月活动3月31日结束)

豆妹 2014-10-29 17:52:21 226192浏览量 回答数 162

8

回答

OceanBase 使用动画(持续更新)

mq4096 2019-02-20 17:16:36 337051浏览量 回答数 8

13

回答

[@饭娱咖啡][¥20]我想知道 Java 关于引用那一块的知识

心意乱 2018-10-31 18:44:12 142472浏览量 回答数 13

110

回答

OSS存储服务-客户端工具

newegg11 2012-05-17 15:37:18 295593浏览量 回答数 110

22

回答

爬虫数据管理【问答合集】

我是管理员 2018-08-10 16:37:41 147255浏览量 回答数 22

18

回答

阿里云开放端口权限

xcxx 2016-07-20 15:03:33 646829浏览量 回答数 18

31

回答

[@倚贤][¥20]刚学完html/css/js的新手学习servlet、jsp需要注意哪些问题?

弗洛伊德6 2018-10-27 21:52:43 146055浏览量 回答数 31

42

回答

【精品问答集锦】Python热门问题

小六码奴 2019-05-30 15:27:34 137072浏览量 回答数 42

10

回答

[@墨玖tao][¥20]为什么流式处理框架都是 java 写成的,JVM 是不是在流和批存在着特殊优势。还有分布式资源调度,感觉Mesos 的成长速度跟不上 Yarn。这是为什么?

管理贝贝 2018-10-23 13:18:03 136479浏览量 回答数 10
+关注
爱吃鱼的程序员
https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
2
文章
21569
问答
问答排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载