【问题标题】:Java eclipse does not recognize the import org.apache.poi package that is already imported with mavenjava eclipse无法识别已经用maven导入的import org.apache.poi包
【发布时间】:2020-07-11 02:00:18
【问题描述】:

我正在尝试使用 apache poi 在 java 中创建一个 excel,我正在使用 spring boot 和 thymeleaf,我已经在 pom.xml 文件中导入了依赖项并在我的 eclipse 中更新它,依赖项在我的项目中,当我运行命令 mvn clean install 一切似乎都很好,但是当将它导入我的 java 类时,它找不到它,我已经尝试更改 apache-poi 库的版本,但它没有工作.我在这里留下一些参考数据:

this is the class that I want to inport

eclipse does not recognize the jara apache-poi class


这是我的 pom.xml 的代码:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>mx.com.telcel</groupId>
    <artifactId>detalladoVentas</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>detalladoVentas</name>
    <description>Generación de reportes sisap</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!-- dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> 
            </dependency -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!-- <scope>provided</scope> -->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!-- dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> 
            <scope>test</scope> </dependency -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>

        <!-- START Bibliotecas necesarias para el desarrollo de reportes en Excel -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
            <scope>runtime</scope>
        </dependency>
    
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.2</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.20</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>3.1.0</version>
            <scope>runtime</scope>
        </dependency>
        <!-- END Bibliotecas necesarias para el desarrollo de reportes en Excel -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

你认为是什么问题?我真的很感谢你的帮助。

【问题讨论】:

  • 您的 POM 中有多个依赖项 &lt;scope&gt;runtime&lt;/scope&gt;。你能用你自己的话解释一下那个指令是做什么的吗?
  • 我不知道这是什么意思,现在我看到这个范围表明依赖不是编译所必需的,而是执行所必需的。非常感谢
  • 太好了,您自己想通了并添加了正确的答案。不要忘记接受您自己的答案(在 2 天的等待期结束后),这样这个问题就不会在搜索中出现未回答的情况。此外,始终将文本内容包含为 formatted 文本 - 仅在有意义时使用图像 - 然后更愿意将图像直接嵌入到您的问题中(而不是作为链接)。

标签: java eclipse spring-boot maven apache-poi


【解决方案1】:

我会回答我自己的问题,以防将来有人发现它有用:
我不知道是什么

< scope > runtime < /scope >

意思是,现在我看到这个范围表明依赖不是编译所必需的,而是执行所必需的。它在运行时和测试类路径中,而不是编译类路径。
所以解决办法就是去掉这个标签。

【讨论】:

    【解决方案2】:

    您不需要添加 Apache POI 的依赖范围。 从这里检查它

    https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml/4.1.2

    我在 gradle 中使用它们,它们的范围默认是编译时

    https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml/4.1.2

    【讨论】:

    • 我试过这个解决方案,但错误是一样的,我的 java 类无法识别包 org.apache.poi.* ,我不知道我是否缺少一些 eclipse 配置。跨度>
    猜你喜欢
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    相关资源
    最近更新 更多