java - maven构建成功,但eclipse构建失败

标签 java eclipse maven apache-httpclient-4.x

我有一个 Eclipse/Maven 项目:使用 Maven 构建成功,但 Eclipse 确实存在编译时错误,无法构建。 我的 Eclipse 是 Neon (4.6.3),我使用内置 Maven 和 JDK 1.8

你能帮我解决这个问题吗?

我的pom.xml:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>seller</groupId>
  <artifactId>home.digest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>home.digest Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.8</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.11</version>
    </dependency>
    <dependency>
        <!-- jsoup HTML parser library @ https://jsoup.org/ -->
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.11.3</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>home.digest</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Eclipse 无法识别类中的以下导入:

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.protocol.HttpContext;

Eclipse 项目具有以下属性:

enter image description here

最佳答案

问题是 jar 文件已损坏:

[错误]读取 C:\Users\User.m2\repository\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar 时出错;无效的 LOC header (错误签名)

我通过替换依赖项解决了问题

<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.11</version>
    </dependency>

通过对早期版本的依赖:

4.4.10

关于java - maven构建成功,但eclipse构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56070509/

相关文章:

java - 在部署时覆盖 Jboss EAP 6.4 中 web.xml 中的上下文参数

java - 已部署 Wildfly 服务但未找到资源

java - 如何使 Eclipse WindowBuilder 解析继承的 JFrame?

python - 使用 vtk 时导入的 undefined variable

java - 构建树中的 spring-security-core 版本冲突问题

java - Jetty服务器无法返回json

java - 使用 Objectify 查询 Geopt

带有 JDK 9 模块的 Java 应用程序 : ServiceLoader not finding service (because of Maven build? )

java - 更改 ActionBar 文本颜色

Eclipse(spring 工具套件)在服务器启动时自动关闭(包括 Eclipse 日志文件)