IVY/JAR ERROR - java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row

IVY/JAR ERROR - java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row

嗨,我知道这个问题已经被问过多次,但我已经尝试了所有建议的问题!

我的代码在 Eclipse 中运行得非常好,但是我想在 Unix 中通过命令行构建 jar 和 运行。

在我的依赖项中 ivy.xml 我列出了我的依赖项:

    <dependencies>
              <dependency org="org.apache.xmlbeans" name="xmlbeans" rev="2.6.0"/>
              <dependency org="org.apache.poi" name="poi" rev="3.11" conf="default" /> 
              <dependency org="org.apache.poi" name="poi-ooxml" rev="3.11" conf="default" />
              <dependency org="org.apache.poi" name="poi-ooxml-schemas" rev="3.11" conf="default" />
    </dependencies>

但是当我执行我的 jar 时,出现以下错误:

线程异常 "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row

我知道你需要为 ss 使用 poi-ooxml,但是,我已经在我的 ivy 依赖项中引用了它。

为什么我仍然收到此错误?

如有任何帮助,我们将不胜感激。

我猜你的 jar 清单中缺少类路径。请尝试以下操作:

<target name="build" depends="test" description="Create executable jar archive">
    <ivy:retrieve pattern="${dist.dir}/lib/[artifact]-[revision](-[classifier]).[ext]"/>

    <manifestclasspath property="jar.classpath" jarfile="${jar.file}">
        <classpath>
            <fileset dir="${dist.dir}/lib" includes="*.jar"/>
        </classpath>
    </manifestclasspath>

    <jar destfile="${jar.file}" basedir="${build.dir}/classes">
        <manifest>
            <attribute name="Main-Class" value="${jar.main.class}" />
            <attribute name="Class-Path" value="${jar.classpath}" />
        </manifest>
    </jar>
</target>

备注:

  • ivy retrieve 任务用于将依赖项放入正在构建的 jar 旁边的分发目录中
  • manifestclasspath 任务是一个有用的技巧,可以为可能很长的依赖项列表创建正确的相对路径