在 Jar 文件中运行类 [英] Run class in Jar file

查看:29
本文介绍了在 Jar 文件中运行类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在 /myfolder 中有一个名为 myJar.jar 的 jar 文件,并且您想使用其中的 myClass 类,您如何从命令行执行此操作?

If you have a jar file called myJar.jar located in /myfolder and you want to use the class called myClass from it, how do you go about doing it from the command line?

我认为应该进入目录并说 java -cp myJar.jar.myClass 但这不起作用.任何帮助将不胜感激.

I thought it would be to go into the directory and say java -cp myJar.jar.myClass but that isn't working. Any help would be appreciated.

推荐答案

使用 java -cp myjar.jar com.mypackage.myClass.

  1. 如果类不在包中,则只需java -cp myjar.jar myClass.

如果你不在myJar.jar所在的目录中,那么你可以这样做:

If you are not within the directory where myJar.jar is located, then you can do:

  1. 在 Unix 或 Linux 平台上:

  1. On Unix or Linux platforms:

java -cp/location_of_jar/myjar.jar com.mypackage.myClass

在 Windows 上:

On Windows:

java -cp c:location_of_jarmyjar.jar com.mypackage.myClass

这篇关于在 Jar 文件中运行类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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