通过命令窗口执行Java程序

时间:2012-08-26 04:41:01

标签: java

我有一个查询,因为我使用eclipse主要是为了执行java类但是我想知道我是不是在使用eclipse并且我想执行java程序然后我还要手动设置路径和类路径,我在J:驱动器中的java文件夹中有我的jdk,我的程序在名为AA的文件夹中命名为Temp.java,请告知如何设置路径和类路径,以便从命令窗口本身执行java程序..!< / p>

2 个答案:

答案 0 :(得分:2)

您可以设置安装jdk bin路径的环境路径,然后就可以从任何位置编译和运行java程序。

My compute->right click->system properties->advanced tab->select system variable path-> select edit->then add your jdk bin path. save the setting.

在Windows上设置路径

Windows 7
Select Computer from the Start menu
Choose System Properties from the context menu
Click Advanced system settings > Advanced tab
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Reopen Command prompt window, and run your java code.

Refrence

答案 1 :(得分:1)

您可以使用以下方法设置当前工作目录的路径:

path=%path%;c:\Java\jdk[followedbyversion]\bin

这会暂时设置路径,并且在系统重新启动时,您必须再次设置路径。

如果在Windows上工作,则可以使用环境变量永久设置路径。右键单击“我的电脑” - &gt;属性 - &gt;高级系统设置 - &gt;环境变量 - &gt;然后添加一个用户环境变量,将其命名为path并将路径设置为jdk的bin。