- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
大家好,提前感谢您的帮助。我是一名学生,正在学习java。这个学期我们有一个小组项目,我们需要完成一个已经实现了一些功能的代码。我的主要任务是在目录分配的类分配中实现一个算法,主要使用目录数据模型中类的函数。尽管位于不同目录中的每个类都位于同一个包中。当从分配中的数据模型类调用静态字段时,我没有遇到任何问题。但是,当在这里调用方法时,我收到错误 ClassDefNotFound。我要补充一点,我使用 .jar 文件运行该程序。我尝试了很多方法来解决这个问题,但不幸的是我还没有解决它,而且我的时间已经不多了,所以我在这里寻求你的帮助。
我尝试通过添加配置来更改分配目录中的 pom.xml 文件,但它仍然不起作用。此外,我对应该准确写下哪条路径感到困惑。我知道它是绝对路径,但我无法写入我的用户目录,因为该项目应该在任何计算机上运行。
再次感谢您今后的帮助。我一直在为这件事绞尽脑汁,所以任何解决这个问题的帮助都将是我的救星!
最佳答案
认为您在生成 jar 时缺少依赖项。这就是为什么它说该类未定义,请在您的 pom.xml 中尝试此操作
来源: Including dependencies in a jar with Maven
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
个人pom.xml示例(注意一开始使用上述插件,并且我还定义了一个 list ,尝试两种方法:
<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>NuevaUtilidadExcel</groupId>
<artifactId>NuevaUtilidadExcel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.nuevaUtilidad.vista.InterfazPrincipal</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
<repository>
<id>netbeans</id>
<name>Netbeans rep</name>
<url>http://bits.netbeans.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<dependency>
<groupId>com.toedter</groupId>
<artifactId>jcalendar</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<name>NuevaUtilidadExcelSVG</name>
</project>
关于java - 使用 maven 时出现 java.lang.NoClassDefFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59146437/
这个问题已经有答案了: NoClassDefFound when trying to run java with external libraries (4 个回答) 已关闭 8 年前。 如何从命令行
我在我的 Java 项目中使用 .dll(Eclipse IDE,如果有帮助的话),假设这个 .dll 包含类“myclass”并且我导入了它。构建时没有错误。 我在使用以下代码时遇到问题(NoCla
我正在尝试使用 netbeans 将我的 java 程序编译为单个 .jar 文件,并包含多个库。尝试使用以下命令通过 cmd 运行时,出现 NoClassDefFound 和 ClassNotFou
我遇到了编译器给我的这个错误: 线程“main”java.lang.NoClassDefFoundError中出现异常:javax/media/opengl/GLProfile 我的类路径中确实有 j
编辑:这个项目演示了行为: https://github.com/NathanielWaggoner/AndroidExamples/tree/master/packing 有一个读我解释了您第一次构
我不明白NoClassDefFoundError在 running an OpenEJB client 的背景下: thufir@doge:~$ thufir@doge:~$ java -classp
我已经被某个点困扰了几个小时,我正在初始化我从应用程序类调用的 Controller.java 类中的一些代码,它早些时候在所有设备上工作,但从昨天开始,我在 lolipop 以下的设备上收到 NoC
我有点被 xstream 的问题困住了。我有两个基于 OSGI 的 RCP 应用程序。他们使用 xstream 在 XML 文件中写入和读取某些类。当我运行程序并触发有问题的代码时,我得到: com.
我正在尝试将具有多个 jar 的小程序添加到 HTML 页面,但尝试在浏览器中运行该程序时出现 NoClassDefFounderror: db.DAO 。 DAO 是 TheaterApplet 所
我已经输入了在里面应用程序标签。 当我尝试进行此 Activity 时,我崩溃了。 这是我的java文件: ** import com.google.android.maps.MapActivity;
我试图在 html 文档上使用我的 java 小程序,但它只是一遍又一遍地给出相同的错误。我正在使用 eclipse 。当我调试/运行小程序时,一切正常,但是当我将其导出到 jar 文件并尝试将其与
我有一个 Android 库,我在两个不同的项目中使用它。在其中之一中,我可以正确使用该库。但是,在第二个项目中,我遇到了 NoClassDefFound 异常。 08-31 07: 49:23.15
嗨,当我添加 activation.jar、编译以及运行时出现错误时,我收到 NoClassDefFoundError。 DataHandler 类存在于 activation.jar 注意:我在 a
我有一个扩展 OrmliteSqliteOpenHelper 的类,以便为 Android 应用程序提供持久性模块。问题是,每当我从 Eclipse 中的测试项目访问此类时,它都会抛出 NoClass
我安装了 apache-jmeter-5.1.1 和 java 1.8.0_221 (8),并且正在浏览 getting started guide在 GUI 中构建 Web 测试计划。但是当我单击“
我正在尝试在我的项目中使用 Jira Rest Java 客户端。但无法连接到我安装的 jira。使用以下代码片段时: JiraRestClientFactory factory = new Asyn
我查看了此问题的其他答案,并尝试遵循它们。基本上是这样的场景:我有一个通过 jsp 页面调用的类。该类有一个在 jar 文件中找到的类。当我转到该页面时,对于 jar 中的类,我得到一个未找到类的异常
我最近将 ADT 从 22 版本更新到了 23.0 版本。现在我的项目在更新之前运行良好,但出现以下错误:- 01-01 10:19:27.016: E/AndroidRuntime(2405):
这个问题已经有答案了: TestNG java.lang.NoClassDefFoundError: com/google/common/primitives/Ints (3 个回答) 已关闭 6 年
概念是在特定时间获得通知。显然,我做到了,直到我包含了对低于 HoneyComb 和高于它的版本的支持。 我已经设置了最小 SDK 版本 8 和目标 SDK 17。由于类编码要大得多,我只显示存在问题
我是一名优秀的程序员,十分优秀!