简体   繁体   中英

Intellij : Problem with compilation of apache poi

I've got a problem with the compilation of my java code when I include the poi-4.0.0 library. I know this has been asked but no real answer has been given. The error I am given is the following :

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Litock: Compilation failure: Compilation failure:

/C:/Users/MyName/Desktop/testBuilds/Litock/src/main/java/Controller/Controller.java:[17,37] package org.apache.poi.xssf.usermodel does not exist

My pom dependecies :

<dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>ooxml-schemas</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.12</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>3.0.1</version>
        </dependency>
</dependencies>

My pom building :

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>10</source>
                <target>10</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>Main.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

My iml file :

<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="mysql-connector-java-8.0.12" level="project" />
<orderEntry type="library" exported="" name="xmlbeans" level="project" />
<orderEntry type="library" exported="" name="commons-collections4-4.2" level="project" />
<orderEntry type="library" exported="" name="commons-compress-1.18" level="project" />
<orderEntry type="library" exported="" name="poi-4.0.0" level="project" />
<orderEntry type="library" exported="" name="ooxml-schemas" level="project" />

My Controller class :

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

I'm able to call the class functions in the code but when I compile at the end, I'm a given the error I stated at the beginning.

Promoting a comment to an answer

As detailed on the Apache POI page for the different Components , to make use of the OOXML classes such as XSSF , you need to depend on the poi-ooxml Maven artifact.

Your dependency should therefore (as of December 2018) be

  <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.0.1</version>
  </dependency>

That will pull in the other artifacts needed, such as poi and ooxml-schemas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM