2012-03-12 222 views
0

我目前正在尝试构建一个具有多个依赖关系的Java项目。我已经将它创建为Maven Web应用程序,并添加了所有必需的依赖关系。但是,进口并没有得到解决。使用Maven的Netbeans - 添加依赖库

在下面的链接中,我附上了我的Netbeans屏幕截图,其中右侧面板中显示导入错误。在左侧面板中,我突出显示了我添加的库。谁能告诉我为什么会发生这种情况?任何帮助将非常感激。谢谢:)

http://img20.imageshack.us/img20/5558/screenshotat20120312121.png

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"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.mycompany</groupId> 
<artifactId>nutchTest2</artifactId> 
<packaging>war</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>nutchTest2 Java EE 6 Webapp</name> 
<url>http://maven.apache.org</url> 
<repositories> 
    <repository> 
     <id>java.net2</id> 
     <name>Repository hosting the jee6 artifacts</name> 
     <url>http://download.java.net/maven/2</url> 
    </repository> 
</repositories> 
<dependencies> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.6.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jvnet.hudson.hadoop</groupId> 
     <artifactId>hadoop-core</artifactId> 
     <version>0.19.1-hudson-3</version> 
    </dependency> 
    <dependency> 
     <groupId>com.saucelabs.selenium</groupId> 
     <artifactId>selenium-htmlunit-driver</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>solrj</groupId> 
     <artifactId>solr-solrj-1.3.0.jar</artifactId> 
     <version>1.3.0</version> 
    </dependency> 
    <dependency> 
     <groupId>solr</groupId> 
     <artifactId>solr-common-1.3.0-sources</artifactId> 
     <version>1.3.0</version> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.2</version> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.0.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1-beta-1</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
    </plugins> 
    <finalName>nutchTest2</finalName> 
</build> 
<profiles> 
    <profile> 
     <id>endorsed</id> 
     <activation> 
      <property> 
       <name>sun.boot.class.path</name> 
      </property> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.0.2</version> 
        <configuration> 
         <!-- javaee6 contains upgrades of APIs contained within the JDK itself. 
          As such these need to be placed on the bootclasspath, rather than classpath of the 
          compiler. 
          If you don't make use of these new updated API, you can delete the profile. 
          On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.--> 
         <compilerArguments> 
          <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath> 
         </compilerArguments> 
        </configuration> 
        <dependencies> 
         <dependency> 
          <groupId>javax</groupId> 
          <artifactId>javaee-endorsed-api</artifactId> 
          <version>6.0</version> 
         </dependency> 
        </dependencies> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

</project> 

回答

1

也许是因为你告诉我们,这些文件是在源代码包(Solr的常见*来源*罐子)(注意不是你点到扩展名为.java的文件,而不是.class),而不是在编译的库中。将编译的库包含到您的项目中。 需要看到POM文件提供更详细的解答


我看到.pom文件后:你应该改变

<dependency> 
    <groupId>solr</groupId> 
    <artifactId>solr-common-1.3.0-sources</artifactId> 
    <version>1.3.0</version> 
</dependency> 

<dependency> 
    <groupId>solr</groupId> 
    <artifactId>solr-common</artifactId> 
    <version>1.3.0</version> 
</dependency> 
+0

我已经粘贴的内容我的POM文件。我很抱歉,我下载了jar文件并使用mvn:install命令将其添加到maven本地存储库。你能告诉我如何将.java文件转换为.class?谢谢:) – arya 2012-03-12 07:10:17

+0

通过下载正确的jar文件修复它。非常感谢你 :) – arya 2012-03-12 07:15:13