这是我第一次发布 - 我发现类似的问题,但没有关于这个问题的任何直接。这听起来很简单,但我不太确定为什么会发生。我的程序在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
更多推荐
无法使用软件包从命令行运行多类程序
发布评论