如何在没有IDE的情况下编译java类(在包内)

时间:2020-11-29 17:41:15

I'm working in windows 7, Java 7 and have following folder:

我正在使用Windows 7,Java 7并具有以下文件夹:

C:\..\myApplicationV

Inside this folder there are two folders with one java class each:

在这个文件夹里面有两个文件夹,每个文件夹有一个java类:

C:\..\myApplicationV\graphics\Circle.java
C:\..\myApplicationV\mains\UseCircle.java

Circle.java contains following code:

Circle.java包含以下代码:

package graphics;

public class Circle {


    public void describeCircle (){

    System.out.println("A circle is round");

    }
}

I've been able to compile Circle.java so therefore I have also following file:

我已经能够编译Circle.java所以我也有以下文件:

C:\..\myApplicationV\graphics\Circle.class

UseCircle.java contains following code:

UseCircle.java包含以下代码:

package mains;

import graphics.Circle;

class UseCircle{

    public static void main (String[] args){

    Circle circle = new Circle();
    circle.describeCircle();

    }
}

I try to compile this last one class, I place in:

我尝试编译最后一个类,我放入:

C:\..\myApplicationV\mains\

and type:

javac UseCircle.java

but I'm getting following message:

但是我收到了以下信息:

UseCircle.java:3: error: package graphics does not exist
import graphics.Circle;
               ^

Doing some research I have found some information at:

做一些研究我发现了一些信息:

http://docs.oracle.com/javase/tutorial/java/package/index.html

So I have solve this isuue by placing all java classes in one package and works fine. Also I have move UseCircle.java class to base folder:

所以我通过将所有java类放在一个包中并且工作正常来解决这个问题。此外,我已将UseCircle.java类移动到基本文件夹:

C:\..\myApplicationV

And also works. The problem is when trying to use the two package. Do you know what could be wrong ?

并且也有效。问题是尝试使用这两个包时。你知道什么可能是错的吗?

2 个解决方案

#1


2  

Please specify the full package path while compiling

编译时请指定完整的包路径

cd C:\..\myApplicationV\
javac mains/UseCircle.java
java mains/UseCircle

#2


1  

Open the command prompt in myApplicationV folder & do the following:

在myApplicationV文件夹中打开命令提示符并执行以下操作:

javac graphics\Circle.java
javac mains\UseCircle.java
java mains.UseCircle

#1


2  

Please specify the full package path while compiling

编译时请指定完整的包路径

cd C:\..\myApplicationV\
javac mains/UseCircle.java
java mains/UseCircle

#2


1  

Open the command prompt in myApplicationV folder & do the following:

在myApplicationV文件夹中打开命令提示符并执行以下操作:

javac graphics\Circle.java
javac mains\UseCircle.java
java mains.UseCircle