开发者社区> 问答> 正文

maven依赖传递有效性?报错

比如我在项目中用到了shiro,然后我添加了shiro的dependency,可以看到在shiro-core中又依赖了commons-beanutils。这时我用了commons-beanutils中的类时,运行时报错class not found,必须重新添加commons-beanutils的依赖才能使用,不知道怎么看这种传递的依赖是不是有效,下面是shiro-core.pom文件,麻烦给我分析下

project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-root</artifactId>
        <version>1.2.3</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>shiro-core</artifactId>
    <name>Apache Shiro :: Core</name>
    <packaging>bundle</packaging>

    <build>
        <plugins>
            <!-- collect the test classes so they can be referenced by other modules -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>org.apache.shiro.core</Bundle-SymbolicName>
                        <Export-Package>org.apache.shiro*;version=${project.version}</Export-Package>
                        <Import-Package>
                            org.apache.shiro*;version="${shiro.osgi.importRange}",
                            org.apache.commons.beanutils*;resolution:=optional,
                            *
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
        </dependency>
        <!-- For Java 1.4 and below only: - ->
        <dependency>
            <groupId>backport-util-concurrent</groupId>
            <artifactId>backport-util-concurrent</artifactId>
        </dependency>
        -->

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- JDBC Realm tests: -->
        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>



展开
收起
爱吃鱼的程序员 2020-06-14 18:45:21 509 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    不应该这样啊,确定你用的时候已经将相关包加在library下了吗谢谢,刚才找到问题了,原来shiro依赖的beanutils的版本是1.8.3,我自己添加的beanutils的版本是1.9.2,里面又依赖了commons-cellections,1.8.3里面没有commons-collections,还是看错误信息不仔细。。。

    clear 

    然后重新install检查包是否冲突

    没下载下来吧maven有个命令可以检查所有依赖的,不过我忘记是啥了

    2020-06-14 18:45:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载