<bdo id='2qGv7'></bdo><ul id='2qGv7'></ul>
        <legend id='2qGv7'><style id='2qGv7'><dir id='2qGv7'><q id='2qGv7'></q></dir></style></legend>
        <tfoot id='2qGv7'></tfoot>

        <i id='2qGv7'><tr id='2qGv7'><dt id='2qGv7'><q id='2qGv7'><span id='2qGv7'><b id='2qGv7'><form id='2qGv7'><ins id='2qGv7'></ins><ul id='2qGv7'></ul><sub id='2qGv7'></sub></form><legend id='2qGv7'></legend><bdo id='2qGv7'><pre id='2qGv7'><center id='2qGv7'></center></pre></bdo></b><th id='2qGv7'></th></span></q></dt></tr></i><div id='2qGv7'><tfoot id='2qGv7'></tfoot><dl id='2qGv7'><fieldset id='2qGv7'></fieldset></dl></div>

      1. <small id='2qGv7'></small><noframes id='2qGv7'>

        如何从 cmd 运行作为包一部分的 .class 文件?

        时间:2023-09-27
      2. <tfoot id='W66fz'></tfoot>
      3. <i id='W66fz'><tr id='W66fz'><dt id='W66fz'><q id='W66fz'><span id='W66fz'><b id='W66fz'><form id='W66fz'><ins id='W66fz'></ins><ul id='W66fz'></ul><sub id='W66fz'></sub></form><legend id='W66fz'></legend><bdo id='W66fz'><pre id='W66fz'><center id='W66fz'></center></pre></bdo></b><th id='W66fz'></th></span></q></dt></tr></i><div id='W66fz'><tfoot id='W66fz'></tfoot><dl id='W66fz'><fieldset id='W66fz'></fieldset></dl></div>

          • <legend id='W66fz'><style id='W66fz'><dir id='W66fz'><q id='W66fz'></q></dir></style></legend>

          • <small id='W66fz'></small><noframes id='W66fz'>

                <bdo id='W66fz'></bdo><ul id='W66fz'></ul>

                  <tbody id='W66fz'></tbody>
                1. 本文介绍了如何从 cmd 运行作为包一部分的 .class 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我将 .class 作为 package 的一部分并尝试从 cmd 运行它时,我不断收到错误.

                  I keep getting errors when I make my .class part of a package and try to run it from cmd.

                  这是使用 javac 然后使用 java:

                  Here's the code that works after using javac and then java:

                  class HelloWorld {
                      public static void main(String[] args) {
                          System.out.println("Hello World!");
                      }
                  }
                  

                  然后是不起作用的代码:

                  and then the code that does not work:

                  package com;
                  
                  class HelloWorld {
                      public static void main(String[] args) {
                          System.out.println("Hello World!");
                      }
                  }
                  

                  尝试通过以下命令运行程序后出现此错误:java HelloWorld:

                  giving me this error after trying to run the program via the command: java HelloWorld:

                  Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong nam
                  e: com/HelloWorld)
                      at java.lang.ClassLoader.defineClass1(Native Method)
                      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$100(Unknown Source)
                      at java.net.URLClassLoader$1.run(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)
                      at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
                  

                  这是我迄今为止尝试过的:

                  Here's what I've tried doing so far:

                  java -cp . HelloWorld
                  java -cp . com.HelloWorld
                  java -cp . com/HelloWorld
                  java HelloWorld
                  java com.HelloWorld
                  java com/HelloWorld
                  

                  请记住,javac 返回时没有错误,只需删除 package com; 即可解决问题.有时在其他情况下,我会收到一条错误消息,提示找不到主类文件或类似的内容.

                  Keep in mind that javac returns with no errors and that simply removing package com; solves the problem. Sometimes in other scenarios I get an error that says the main class file cannot be found or something along those lines.

                  我做错了什么?

                  推荐答案

                  假设你做了 cd C:/projects 并且 HelloWorld.classC:/projects/com,然后输入:

                  Suppose you did cd C:/projects and HelloWorld.class is in C:/projects/com, then just type:

                  java com.HelloWorld
                  

                  这篇关于如何从 cmd 运行作为包一部分的 .class 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:编译时如何通配符包含 JAR 文件? 下一篇:为什么另一个包中的子类不能访问受保护的方法

                  相关文章

                  最新文章

                2. <small id='e2Cjh'></small><noframes id='e2Cjh'>

                  1. <legend id='e2Cjh'><style id='e2Cjh'><dir id='e2Cjh'><q id='e2Cjh'></q></dir></style></legend>

                    <i id='e2Cjh'><tr id='e2Cjh'><dt id='e2Cjh'><q id='e2Cjh'><span id='e2Cjh'><b id='e2Cjh'><form id='e2Cjh'><ins id='e2Cjh'></ins><ul id='e2Cjh'></ul><sub id='e2Cjh'></sub></form><legend id='e2Cjh'></legend><bdo id='e2Cjh'><pre id='e2Cjh'><center id='e2Cjh'></center></pre></bdo></b><th id='e2Cjh'></th></span></q></dt></tr></i><div id='e2Cjh'><tfoot id='e2Cjh'></tfoot><dl id='e2Cjh'><fieldset id='e2Cjh'></fieldset></dl></div>
                  2. <tfoot id='e2Cjh'></tfoot>
                      <bdo id='e2Cjh'></bdo><ul id='e2Cjh'></ul>