我目前正在尝试构建一个具有多个依赖项的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>
答案 0 :(得分:1)
可能是因为您向我们展示的文件位于源包中(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>