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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4500037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 18:05:02  来源:igfitidea点击:

Build failure due to missing libraries

javamaven

提问by theJava

[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

But i have added all the libraries in my eclipse by right clicking the project and adding the external jars.

但是我通过右键单击项目并添加外部 jars 在我的 eclipse 中添加了所有库。

When i try to run mvn compile i get these errors with a lot of other jars also missing.

当我尝试运行 mvn compile 时,我收到了这些错误,同时还缺少许多其他 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>

Should i do anything with POM.xml

我应该对 POM.xml 做任何事情吗

采纳答案by Jigar Joshi

Add this to your dependency

将此添加到您的依赖项

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

回答by axtavt

The whole point of maven is that you describe all dependencies of your project in pom.xmlrather than add them as jars in your IDE.

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

When you have dependencies configured in pom.xml, you can easily generate Eclipse project with the corresponding dependencies by running mvn eclipse:eclipse, or add them to the existing project with m2eclipseplugin.

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