带有Maven的Netbeans-添加依赖库



我目前正在尝试构建一个具有多个依赖项的Java项目。我已经将其创建为Maven Web应用程序,并添加了所有必要的依赖项。然而,进口问题并没有得到解决。

在下面的链接中,我附上了我的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>

可能是因为您向我们展示的文件在源代码包(solr-common*sources*jar)中(请注意,您指向的是扩展名为.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>

最新更新