如何在类路径中运行带有jar的java类? [英] How to run a java class with a jar in the classpath?

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

问题描述

所以,我可以做得很好:

So, I can do this very well:

java mypackage.MyClass

如果 ./ mypackage / MyClass.class 存在。我也很乐意这样做:

if ./mypackage/MyClass.class exists. I can also happily do this:

java -cp myjar.jar mypackage.MyClass

如果类文件存在于jar的适当部分。简单的东西。但我不能为我的生活设法做这样的事情:

if the class file exists in the appropriate part of the jar. Easy stuff. But I can't for the life of me manage to do something like this:

java -cp utilities.jar mypackage.MyClass

其中 ./ mypackage / MyClass.class 存在,并且 ./ utilities.jar 存在(当然不包含MyClass)。

where ./mypackage/MyClass.class exists, and where ./utilities.jar exists (not containing MyClass, of course).

我是关于感到愚蠢?

推荐答案

可能:))

# On Unix
java -cp utilities.jar:. mypackage.MyClass

# On Windows
java -cp utilities.jar;. mypackage.MyClass

基本上只包括类路径上的(当前目录)以及jar文件。

Basically that's just including . (the current directory) on the classpath as well as the jar file.

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

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