从命令行使用外部jar文件运行Java应用程序 [英] Run java application from command line with external jar files

查看:137
本文介绍了从命令行使用外部jar文件运行Java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部jar文件(具有包结构),其中包含主类,并且可以从命令行运行应用程序,如下所示:

I have an external jar file(have package structure), which contains the main class, and I can run the app from command line like this:

java -jar example.jar

但是我在这个jar文件之外还有另一个test.class文件,这个jar文件中的某些类将调用test.class中的方法.如何在命令行中指定jar文件要使用的test.class文件?尝试了多种方式,始终显示:

But I still have another test.class file outside this jar file, and some classes inside this jar file will invoke the methods in test.class. How can I specify the test.class file to be used by jar file in command line? Tried many ways, always show:

NoClassDefFoundError for test.class

注意:test.class文件也使用example.jar文件中的类文件,具有自己的包结构.

NB: the test.class file also use class files in example.jar file, has its own package structure.

我知道我可以将它们放到一个jar文件中,不幸的是,我需要将test.class文件分开.

I know I can put them together in one jar file, unfortunately I need separate the test.class file.

推荐答案

如果该类在bin目录中:

If the class is in bin directory :

java -cp xxx.jar;bin pck1.pck2.MainClass

如果该类在当前目录中:

If the class is in the current directory :

java -cp xxx.jar;. pck1.pck2.MainClass

以此类推...

手册中的更多信息,请至少阅读一次...;-)

More info in the manual, please read it at least one time... ;-)

这篇关于从命令行使用外部jar文件运行Java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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