本文介绍了无法使用软件包从命令行运行多类程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次发布 - 我发现类似的问题,但没有关于这个问题的任何直接。这听起来很简单,但我不太确定为什么会发生。我的程序在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.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.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

这篇关于无法使用软件包从命令行运行多类程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:31