运行一个java程序

发布于 2024-09-25 03:48:44 字数 304 浏览 0 评论 0原文

我想使用shell脚本运行java程序。 java程序在p2目录下,名字是maxconnect4,我已经编译好了,类名是maxconnect4。我这样编写 shell 命令:

java p2/maxconnect4 arg1 arg2 arg3

这个 shell 命令不起作用。 它给出一个错误: Exception in thread "main" java.lang.NoClassDefFoundError: p2/maxconnect

但是,我以这种方式编译java程序:

javac p2/*.java,并且它有效。

I want to run a java program using shell script. The java program is in p2 directory and its name is maxconnect4 and I have already compiled it, the class name is maxconnect4. I write the shell commands like this:

java p2/maxconnect4 arg1 arg2 arg3

This shell command does not work.
It give an error: Exception in thread "main" java.lang.NoClassDefFoundError: p2/maxconnect

However, I compile the java program in this way:

javac p2/*.java, and it works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

度的依靠╰つ 2024-10-02 03:48:44

假设该类声明了 package p2; ,那么应该可以工作——尽管更标准的方法是在完全限定的类名中使用点而不是斜杠——java p2.maxconnect< /代码>。

如果该类没有包声明,请尝试 java -cp p2 maxconnect。您需要指定一个类路径,以便在顶层找到类文件。

如果该类有其他包声明,则需要将其放入与其包匹配的文件夹中。

Assuming that the class has package p2; declared, that should work -- although the more standard way is to use dots instead of slashes in the fully-qualified classname -- java p2.maxconnect.

If the class has no package declaration, try java -cp p2 maxconnect. You need to specify a classpath such that the class file is found at the top level.

If the class has some other package declaration, you need to put it into a folder that matches its package.

微凉 2024-10-02 03:48:44

只需使用 java -cp p2 maxconnect4 arg1 arg2 arg3 即可。 -cp 设置 JVM 的类路径。编辑:我假设您没有使用 maxconnect4 的包。

Just use java -cp p2 maxconnect4 arg1 arg2 arg3. -cp sets the classpath of the JVM. Edit: I assume you don't use a package for maxconnect4.

穿越时光隧道 2024-10-02 03:48:44

尝试使用

java p2.maxconnect4 arg1 arg2 arg3

另外,您可以尝试检查类名,并验证文件 p2/maxconnect4.class 是否存在。

Try with

java p2.maxconnect4 arg1 arg2 arg3

Also, you can try to check the class name, and verify if the file p2/maxconnect4.class exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文