zoukankan      html  css  js  c++  java
  • maven package多模块项目时出现: 程序包XXX.XXX不存在

    前提

    多模块项目的时候,如B依赖A:B->A,在A项目中依赖了一个本地jar包:

    A模块的POM文件部分:

            <dependency>
                <groupId>org.csource</groupId>
                <artifactId>fastdfs-client-java</artifactId>
                <version>1.29</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/lib/XXX.jar</systemPath>
            </dependency>

    注:如果要打包本地jar到项目环境

            <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>xxxxlib</outputDirectory>
                                <excludeTransitive>false</excludeTransitive>
                                <stripVersion>false</stripVersion>
                                <includeScope>system</includeScope>
                            </configuration>
                        </execution>
                        <!--打包 scope 为 compile 的 jar 包-->
                        <execution>
                            <id>copy-dependencies2</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>xxxxlib</outputDirectory>
                                <includeScope>runtime</includeScope>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

    如果需要现在编译B,并且在B中使用了XXX.jar里面的类,在打包的的时候会提示

    java: 程序包XXX.XXX.XXX不存在

    在日志中发现了一个警告:

    [WARNING] The POM for xxx:jar:1.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

    说是一个jar包的pom无效,传递依赖项(如果有的话)将不可用。也就是说,Maven的模块(Module)B依赖了A,而A又依赖了一个jar,A的pom无效,所以B编译时就报错了,各种找不到类、找不到包。

    解决方法

    方法一

    A层Module的引用中,去掉第三方的jar,寻找一个Maven中央仓库可以引用到的jar代替;在项目根目录,mvn clean deploy,把B层引用到的jar包传到私服上面;这次再运行mvn clean install -Dmaven.test.skip=true,发现通过,问题解决。

    方法二

    设置模块B的编译参数

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <compilerArguments>
                            <extdirs>${project.basedir}/../XXX/lib</extdirs>
                        </compilerArguments>
                    </configuration>
                </plugin>

    这样就是在编译的时候获取对应的路径查找,就可以编译通过了

  • 相关阅读:
    sql server 2008收缩数据库日志
    小题大做之MySQL 5.0存储过程编程入门(收藏)
    精进不休 .NET 4.0 (5) C# 4.0 新特性之并行运算(Parallel) (收藏)
    GridView 格式化<收藏>
    MySql捕获sql语句异常的方法
    Windows7发生VS2005无法调试Web项目
    mysql 5.0存储过程学习总结《转载》
    HashMap和Hashtable及HashSet的区别
    iphone 界面实现下拉列表
    Java中堆和栈的区别
  • 原文地址:https://www.cnblogs.com/grasp/p/13650385.html
Copyright © 2011-2022 走看看