[英]Compile java file with a package using Oracle JDK in ubuntu
I have successfully compiled this file and saved. 我已成功编译此文件并保存。
class A
{
public static void main(String[] args)
{
System.out.println("Hey!");
}
}
using 使用
javac a.java
java A
but when I compile this file: 但是当我编译这个文件时:
package B;
class A
{
public static void main(String[] args)
{
System.out.println("Hey!");
}
}
now, again using the same commands it do compile but never run 现在,再次使用相同的命令进行编译,但从不运行
javac a.java
java A
// could not find or load main class
Please guide me the exact command for the terminal to run the file. 请指导我终端运行文件的确切命令。
Note: The file is named "a.java". 注意:该文件名为“ a.java”。
您需要指定标准名称,即packageName.ClassName
:
java B.A
您必须将目录更改为包含路径“ B”(您的程序包名称)的目录,然后调用java BA
As mentioned above, You need to specify the fully-qualified name, ie packageName.ClassName: 如上所述,您需要指定标准名称,即packageName.ClassName:
>> javac a.java
>> java B.A
But you need to create the directory named "packageName" yourself as jdk does not create one for you implicitly. 但是您需要自己创建一个名为“ packageName”的目录,因为jdk不会为您隐式创建一个目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.