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

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

问题描述

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

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

我认为它会进入目录,并说java -cp myJar.jar.myClass但是isnt工作。任何帮助将不胜感激

i thought it would be go into the directory and say java -cp myJar.jar.myClass but that isnt working. Any help would be appreciated

推荐答案

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

Use 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上:

java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass


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

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