java—没有可用于org.apache.poi.xssf.usermodel.xssfworkbook类型的源代码;你忘了继承一个必需的模块吗?

cgyqldqp  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(188)

我正在用maven创建一个gwt项目(使用eclipse的gwt插件),并且已经导入了所有必需的依赖项。我想使用excel工作表运行junit测试(fordtest),从excel工作表中读取数据,然后执行一些操作。但是,当我尝试以“gwt junit test”的形式运行文件fordtest时,出现以下错误:

Starting Jetty on port 0
   [WARN] ServletContainerInitializers: detected. Class hierarchy: empty
Compiling module com.figo.FordJUnit.JUnit
   Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Compiling 1 permutation
      Compiling permutation 0...
   Compile of permutations succeeded
   Compilation succeeded -- 4.057s
Linking into C:\Users\Harshit\eclipse-workspace-1\ford\www-test\com.figo.FordJUnit.JUnit
   Link succeeded
   Linking succeeded -- 0.393s
Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Tracing compile failure path for type 'com.figo.client.FordTest'
   [ERROR] Errors in 'file:/C:/Users/Harshit/eclipse-workspace-1/ford/src/test/java/com/figo/client/FordTest.java'
      [ERROR] Line 36: No source code is available for type org.apache.poi.xssf.usermodel.XSSFWorkbook; did you forget to inherit a required module?
      [ERROR] Line 41: No source code is available for type org.apache.poi.ss.usermodel.Row; did you forget to inherit a required module?
      [ERROR] Line 39: No source code is available for type org.apache.poi.xssf.usermodel.XSSFSheet; did you forget to inherit a required module?
      [ERROR] Line 46: No source code is available for type org.apache.poi.ss.usermodel.Cell; did you forget to inherit a required module?
      [ERROR] Line 33: No source code is available for type java.io.FileInputStream; did you forget to inherit a required module?
      [ERROR] Line 33: No source code is available for type java.io.File; did you forget to inherit a required module?
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

我在这里面做错什么了?
以下是我的fordtest文件源代码:

package com.figo.client;

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.google.gwt.junit.client.GWTTestCase;

/**
 * GWT JUnit tests must extend GWTTestCase.
 */
public class FordTest extends GWTTestCase {

    /**
     * Must refer to a valid module that sources this class.
     */
    public String getModuleName() {
        return "com.figo.FordJUnit";
    }

    /**
     * Tests the FieldVerifier.
     */
    public void testSheet() {

        try
        {
            FileInputStream file = new FileInputStream(new File("./ExcelSheets/Test1.xlsx"));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) 
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();

                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly

                    double num1=cell.getNumericCellValue();
                    cellIterator.next();

                    String operator=cell.getStringCellValue();
                    cellIterator.next();

                    double num2=cell.getNumericCellValue();
                    cellIterator.next();

                    double expectedResult=cell.getNumericCellValue();

                    Ford testObj=new Ford();

                    double actualResult=testObj.addTwoNumbers(num1, operator, num2);

                    assertEquals(expectedResult,actualResult);
            }
            file.close();

        }
        catch(Exception e)
        {
            System.out.println("File Error");
        }
    }
}

这是我的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 http://maven.apache.org/maven-v4_0_0.xsd">

  <!-- POM file generated with GWT webAppCreator -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.figo</groupId>
  <artifactId>Ford</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>com.figo.Ford</name>

  <properties>

    <!-- Setting maven.compiler.source to something different to 1.8
         needs that you configure the sourceLevel in gwt-maven-plugin since
         GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <!-- Don't let your Mac use a crazy non-standard encoding -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- ensure all GWT deps use the same version (unless overridden) -->
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.8.1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.3.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
  </dependencies>

  <build>
    <!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

    <plugins>

      <!-- GWT Maven Plugin-->
      <plugin>
        <groupId>net.ltgt.gwt.maven</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.0-rc-6</version>
        <executions>
          <execution>
            <goals>
              <goal>import-sources</goal>
              <goal>compile</goal>
              <goal>import-test-sources</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <moduleName>com.figo.Ford</moduleName>
          <moduleShortName>Ford</moduleShortName>
          <failOnError>true</failOnError>
          <!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
               a different source language for java compilation -->
          <sourceLevel>1.8</sourceLevel>
          <!-- Compiler configuration -->
          <compilerArgs>
            <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
            <arg>-compileReport</arg>
            <arg>-XcompilerMetrics</arg>
          </compilerArgs>
          <!-- DevMode configuration -->
          <warDir>${project.build.directory}/${project.build.finalName}</warDir>
          <classpathScope>compile+runtime</classpathScope>
          <!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
          <startupUrls>
            <startupUrl>Ford.html</startupUrl>
          </startupUrls>
        </configuration>
      </plugin>

      <!-- Skip normal test execution, we use gwt:test instead -->
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

    </plugins>
  </build>
</project>

这里是gwt.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!--
  When updating your version of GWT, you should also update this DTD reference,
  so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.1//EN"
  "http://www.gwtproject.org/doctype/2.8.1/gwt-module.dtd">
<module rename-to='ford'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

  <!-- Other module inherits                                      -->

  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.figo.client.Ford'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>

  <!-- allow Super Dev Mode -->
  <add-linker name="xsiframe"/>
</module>

下面是fordjunit.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  When updating your version of GWT, you should also update this DTD reference,
  so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.1//EN"
  "http://www.gwtproject.org/doctype/2.8.1/gwt-module.dtd">
<module rename-to='ford'>
  <!-- Inherit our applications main module.                      -->
  <inherits name='com.figo.Ford'/>

  <!-- Specify the path to any remote services.                   -->
  <servlet path="/ford/greet" class="com.figo.server.GreetingServiceImpl" />

</module>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题