清单中的ClassPath不起作用 [英] ClassPath in manifest does not work

查看:370
本文介绍了清单中的ClassPath不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jar文件的结构是:

Structure of files in my jar is:

com/my/Main.class
META-INF/MANIFEST.MF
RXTXcomm.jar

Manifest.mf包含:

Manifest.mf consist:

Manifest-Version: 1.0
Main-Class: com.my.Main
Class-Path: RXTXcomm.jar

(存在空行)

当我以以下方式运行jar时:java -jar my.jar

When I run my jar as: java -jar my.jar

我得到:Exception in thread "main" java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener

怎么了?

推荐答案

怎么了?

您已将jar依赖关系打包在主jar中. Class-Path的目的是在类路径中添加一个外部jar,其路径相对于主jar的位置.

You have packaged the jar dependency inside your main jar. The intention of Class-Path is to add an external jar to the classpath, with the path relative to the location of the main jar.

标准Java类加载器不支持将jar打包在jar中.但是,如果需要,您可以将内部jar爆炸到主jar中. Maven可以为您做到这一点.

Packaging a jar within a jar is not supported by standard Java classloaders. If you want, you can explode the inner jar into the main jar, though. Maven can do this for you.

这篇关于清单中的ClassPath不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆