Maven依赖项在默认包中

Maven依赖项在默认包中

本文介绍了Maven依赖项在默认包中找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Maven有一些不了解的地方,也没有找到任何答案.所以我在这里问,希望得到答案.
我添加了一个jar作为项目的Maven依赖项,作为系统范围.
当我在依赖插件上运行analyze-only目标时,它确实找到了它.但是每当我要使用此jar的默认包中的类时,它都不会编译.
我对来自具有相同类的相同提供程序的jar进行了相同的操作,但是这次位于默认以外的一个包中并且可以编译.是否有明显的我想念的东西或有人已经遇到了相同的问题?

There is something I don't understand with maven and I didn't find any answer out there. So I ask it here, hoping to get an answer.
I added a jar as a maven dependency for a project as system scope.
When I run analyze-only goal on dependency plugin, it does find it. But whenever I want to use classes located in default package in this jar, it won't compile.
I did the same with a jar from same provider with same classes but this time located in one package other than default and it compiles.
Is there something obvious I missed or has someone already encountered the same problem ?

不值得发布代码,因为我只是尝试导入系统依赖性类之一.
我的POM(系统依赖性)

It is not worth posting the code as I just try to import one of the class of system dependency.
My POM (system dependency)

 <?xml version="1.0" encoding="UTF-8"?>
 <project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>edu.algo</groupId>
  <artifactId>algorithms</artifactId>
  <version>1.0</version>
  <properties>
    <lib.path>C:/lib</lib.path>
  </properties>

  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>edu.princeton.cs</groupId>
        <artifactId>stdlib</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${lib.path}/stdlib/stdlib.jar</systemPath>
    </dependency>
  </dependencies>
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

推荐答案

很抱歉打扰你们,谢谢您的帮助.
我找到了问题的答案,并且与Maven无关.对于1.4版以上的Java版本,您只能从命名包中导入默认包中的类,我使用的是1.7版.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4989710

Sorry to bother you guys and thanks for your help.
I found the answer to my question and it has nothing to do with maven. You just cannot import classes in default package from named package for java versions above 1.4, I was using 1.7 version for compilation.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4989710

这篇关于Maven依赖项在默认包中找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:38