IntelliJ无法使用Maven解析符号第三方jar

时间:2015-10-20 09:19:29

标签: java maven intellij-idea

我有第三方JAR,我通过pom.xml命令创建了一个工件。工件被添加到项目中,模块的<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> <name>Sandbox</name> <parent> <groupId>com.x.y</groupId> <artifactId>third-party-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.x.y.z</groupId> <artifactId>thirdparty-z</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.x.y.thirdparty</groupId> <artifactId>thirdparty-sources</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.x.y.thirdparty</groupId> <artifactId>thirdparty-compiled</artifactId> <version>1.0</version> </dependency> </dependencies> </project> 和导入就好了。

使用第三方JAR中的符号创建Java类仍然无法解决。红灯灯泡显示,并且没有像我期望的那样选择“导入类”。

我试图使缓存失效|重启但无济于事。

有什么想法吗?

编辑如果我改为安装已编译的JAR,则解析符号。为什么会这样?

编辑2 添加显示内部共享工件的pom.xml。

.sf-menu li:first-child a, .sf-menu li:first-child a:hover {
    padding: 0;
}   
 li.menu-item a {
        padding-top: 20px;
    }

1 个答案:

答案 0 :(得分:0)

此Maven项目文件pom.xml包含修复程序,以及有关更改内容及其更改原因的一些提示/提示。

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--  Parent POM best at the top  -->
    <!--  WANRING: Here you import the parent of 3th party. This is (almost) never correct!!!  -->
    <!--  For a simple project, which only exists of 1 set of classes and unit tests, you do   -->
    <!--  not need a parent POM. Only for multi module Maven project, you will have a parent   -->
    <!--  POM. Or for organisation wide configuration, of repositories, Maven plugin           -->
    <!--  configuration, and so. When starting with a small project, leave out the parent POM  -->
    <!--  reference.                                                                           -->
    <parent>
        <groupId>com.x.y</groupId>
        <artifactId>third-party-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!--  Better keep all project stuff together  -->
    <groupId>com.x.y.z</groupId>
    <artifactId>your-project-name</artifactId>
    <packaging>pom</packaging>
    <name>My Little Sandbox</name>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <!--  Here only a reference to the compiled jar is required!!!                   -->
        <!--  If a source jar is available, it will get pulled in automatically!!!       -->
        <!--  As this is done by (naming) convention of all jars, in a Maven repository  -->
        <dependency>
            <groupId>com.x.y.thirdparty</groupId>
            <artifactId>thirdparty</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

</project>

备注:新项目扩展第三方家长POM的罕见情况是新项目是第三方项目的某种扩展/插件。然后,它可以使用相同的Maven插件版本,dependecies等,如第3方使用。新的扩展/插件与第三方软件的其他部分配合良好,这是最蠢的。

尝试

的具体示例
<?xml version="1.0" encoding="UTF-8"?>
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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.organisation.play-ground</groupId>
    <artifactId>my-little-sandbox</artifactId>
    <packaging>pom</packaging>
    <name>My Little Sandbox</name>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <!--  A dependency reuired for each phase  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>

        <!--  A dependency only needed during runtime phase  -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
            <scope>runtime</scope>
        </dependency>

        <!--  A dependency only needed during compile and test phase  -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.8</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>