0

我是 Java Packaging 的新手,我正在尝试编译 Java 代码并想要以下两件事

  • java编译代码并将.java文件放在src文件夹中
  • java编译代码并将.class文件放在.com文件夹中

所以我尝试了下面的命令

javac -s .\src -d .\com Planet.java

命令运行成功,没有任何错误;类文件放在 com 文件夹中,但源文件仍未移动到 src 文件夹中。我在当前文件夹中手动创建了文件夹 com 和 src。Planet.java 也在当前文件夹中。

├───com  
│   └───test  
└───src  

我在这里错过任何技巧吗?请纠正我。

4

2 回答 2

0

In order to use javac in cmd, JDK (Java Development Kit) must be installed on your system.

javac.exe is inside JDK's bin folder (e.g.: C:\Program Files\Java\jdk1.7.0_45\bin), and NOT in JRE's bin folder (C:\Program Files\Java\jre7\bin), because JRE is just a runtime environment (but you need the development kit to be able to compile source code).

You should append JDK's bin directory (C:\Program Files\Java\jdk1.7.0_45\bin) to the PATH system environment variable.

If you don't have JDK, please download it from the following link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Reference thread for JDK vs. JRE:
What is the difference between JDK and JRE?

Procedure:

  1. Install JDK
  2. open command prompt
  3. type "cd C:\Program Files\Java\jdk1.7.0_45\bin", press Enter (path may change based on JDK version and 32-bit/64-bit OS version)
  4. type "javac", press Enter

Done.

于 2013-12-31T15:23:33.603 回答
0

javac 命令实际上不会移动您的源文件。javac 中的-s选项是告诉 javac 将生成的源文件放在哪里,而不是移动你的。

请参阅:http ://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html

于 2013-02-18T09:31:35.453 回答