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

    <tfoot id='xqe9b'></tfoot>
    1. <legend id='xqe9b'><style id='xqe9b'><dir id='xqe9b'><q id='xqe9b'></q></dir></style></legend>
    2. <small id='xqe9b'></small><noframes id='xqe9b'>

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

        如何使用 javac 编译 java 包结构

        时间:2023-09-27

            <bdo id='dhPxe'></bdo><ul id='dhPxe'></ul>
              <tbody id='dhPxe'></tbody>
              1. <legend id='dhPxe'><style id='dhPxe'><dir id='dhPxe'><q id='dhPxe'></q></dir></style></legend><tfoot id='dhPxe'></tfoot>
                <i id='dhPxe'><tr id='dhPxe'><dt id='dhPxe'><q id='dhPxe'><span id='dhPxe'><b id='dhPxe'><form id='dhPxe'><ins id='dhPxe'></ins><ul id='dhPxe'></ul><sub id='dhPxe'></sub></form><legend id='dhPxe'></legend><bdo id='dhPxe'><pre id='dhPxe'><center id='dhPxe'></center></pre></bdo></b><th id='dhPxe'></th></span></q></dt></tr></i><div id='dhPxe'><tfoot id='dhPxe'></tfoot><dl id='dhPxe'><fieldset id='dhPxe'></fieldset></dl></div>
                • <small id='dhPxe'></small><noframes id='dhPxe'>

                  本文介绍了如何使用 javac 编译 java 包结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试编译(从命令行)一个导入我自己的另一个包的 java 包.我正在关注 tutorial online 但似乎在我尝试编译最终的 java 文件(CallPackage.java).

                  I am trying to compile (from the command line) a java package that imports another package of my own. I was following a tutorial online but it seems that I get an error when I try to compile the final java file (CallPackage.java).

                  这是文件结构:

                  + test_directory (contains CallPackage.java)
                     -> importpackage
                         -> subpackage (contains HelloWorld.java)
                  

                  这里是 CallPackage.java:

                  Here is CallPackage.java:

                  /// CallPackage.java
                  import importpackage.subpackage.*;
                  class CallPackage{
                    public static void main(String[] args){
                    HelloWorld h2=new HelloWorld();
                    h2.show();
                    }
                  }
                  

                  这里是 HelloWorld.java:

                  and here is HelloWorld.java:

                  ///HelloWorld.java
                  
                  package importpackage.subpackage;
                  
                  public class HelloWorld {
                    public void show(){
                    System.out.println("This is the function of the class HelloWorld!!");
                    }
                  }
                  

                  尝试的步骤

                  1. 进入子包,用$javac HelloWorld.java编译HelloWorld.java.
                  2. 转到 test_directory 并使用 $javac CallPackage.java 编译 CallPackage.java.
                  1. Go to the subpackage and compile HelloWorld.java with $javac HelloWorld.java.
                  2. Go to test_directory and compile CallPackage.java with $javac CallPackage.java.

                  这给了我最后一个命令的错误:

                  This gives me an error on the last command:

                  CallPackage.java:1: package importpackage.subpackage does not exist
                  import importpackage.subpackage.*;
                  ^
                  CallPackage.java:4: cannot find symbol
                  symbol  : class HelloWorld
                  location: class CallPackage
                    HelloWorld h2=new HelloWorld();
                    ^
                  CallPackage.java:4: cannot find symbol
                  symbol  : class HelloWorld
                  location: class CallPackage
                    HelloWorld h2=new HelloWorld();
                                      ^
                  3 errors
                  

                  如何编译这两个包?非常感谢您的帮助!

                  How can I compile both packages? Thanks so much for any help!

                  推荐答案

                  你确定 importpackage/subpackage 在你的类路径中吗?

                  Are you sure importpackage/subpackage is in your classpath?

                  -cp 路径或-classpath 路径

                  -cp path or -classpath path

                  指定在哪里可以找到用户类文件,以及(可选)注释处理器和源文件.此类路径覆盖 CLASSPATH 环境变量中的用户类路径.如果既未指定 CLASSPATH、-cp 也未指定 -classpath,则用户类路径由当前目录组成.有关详细信息,请参阅设置类路径.

                  Specify where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. See Setting the Class Path for more details.

                  如果没有指定-sourcepath选项,也会在用户类路径中搜索源文件.

                  If the -sourcepath option is not specified, the user class path is also searched for source files.

                  如果未指定 -processorpath 选项,还会在类路径中搜索注解处理器.

                  If the -processorpath option is not specified, the class path is also searched for annotation processors.

                  http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

                  这篇关于如何使用 javac 编译 java 包结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:您在 Java 项目中使用什么策略来命名包,为什么 下一篇:编译时如何通配符包含 JAR 文件?

                  相关文章

                  最新文章

                  <legend id='nscWn'><style id='nscWn'><dir id='nscWn'><q id='nscWn'></q></dir></style></legend>
                • <tfoot id='nscWn'></tfoot>

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

                  <small id='nscWn'></small><noframes id='nscWn'>

                  • <bdo id='nscWn'></bdo><ul id='nscWn'></ul>