由于缺少库而导致构建失败

时间:2010-12-21 14:01:24

标签: java maven

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project spring-intergation: Compilation failure: Compilation failure:
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[3,24] package javax.persistence does not exist
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[4,24] package javax.persistence does not exist
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[5,24] package javax.persistence does not exist
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[6,24] package javax.persistence does not exist
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[7,24] package javax.persistence does not exist
[ERROR] \spring-intergation\src\main\java\uk\co\dd\spring\domain\User.java:[9,1] cannot find symbol

但是我通过右键单击项目并添加外部jar来添加我日食中的所有库。

当我尝试运行mvn编译时,我发现这些错误也会丢失很多其他的jar。

<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">
    <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>

        <configuration>
          <mainClass>uk.co.dd.spring.App</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <modelVersion>4.0.0</modelVersion>
  <groupId>uk.co.dd.spring</groupId>
  <artifactId>spring-intergation</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>spring-intergation</name>
  <url>http://maven.apache.org</url>
  <dependencies>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>2.5.5</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>



  </dependencies>
</project>

我应该对POM.xml做什么吗

2 个答案:

答案 0 :(得分:24)

将此添加到您的依赖项

<dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>persistence-api</artifactId>  
  <version>1.0</version>
</dependency>

答案 1 :(得分:2)

maven的全部意义在于,您在pom.xml中描述项目的所有依赖项,而不是在IDE中将它们添加为jar。

如果在pom.xml中配置了依赖项,则可以通过运行mvn eclipse:eclipse轻松生成具有相应依赖项的Eclipse项目,或者使用m2eclipse插件将它们添加到现有项目中。