无法使用软件包从命令行运行多类程序

编程入门 行业动态 更新时间:2024-10-26 20:31:45
本文介绍了无法使用软件包从命令行运行多类程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我第一次发布 - 我发现类似的问题,但没有关于这个问题的任何直接。这听起来很简单,但我不太确定为什么会发生。我的程序在Eclipse中漂亮地运行,但不是从命令行运行。我在一个 simpletree 包中有几个类。

This is my first time posting -- I found similar issues but not anything concerning this issue directly. This sounds very simple but I'm not quite sure why this is occurring. My program runs beautifully in Eclipse but not from the command line. I have a few classes within a simpletree package.

这里是 BinaryTree.java :

package simpletree; import java.io.*; public class BinaryTree implements Serializable { // Automatically generated UID private static final long serialVersionUID = -3124224583476129954L; BinaryTree leftNode; // left node BinaryTree rightNode; // right node // some code } class Tree implements Serializable { private static final long serialVersionUID = 6591795896216994405L; private BinaryTree root; // some code }

而 Program1Test.java :

package simpletree; public class Program1Test { public static void main(String[] args) { Tree tree = new Tree(); // some code } }

/ strong>:从内部执行此操作 simpletree 编译精细:

javac BinaryTree.java Program1Test.java

当我这样做:

java Program1Test

我得到这个:

Exception in thread "main" java.lang.NoClassDefFoundError: Program1Test (wrong n ame: simpletree/Program1Test) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.URLClassLoader.defineClass(Unknown Source) at java.URLClassLoader.access$000(Unknown Source) at java.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: Program1Test. Program will exit.

任何想法?我有我的类路径设置正确,我试过运行一个包(simpletree.program1Test)和没有。

Any ideas? I have my classpath set correctly and I've tried running with a package (simpletree.Program1Test) and without.

推荐答案

java simpletree.Program1Test

从dir上面 simpletree

还可以使用 -cp

更多推荐

无法使用软件包从命令行运行多类程序

本文发布于:2023-11-16 20:02:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:软件包   命令行   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!