使用powershell编译和运行java应用程序 [英] Compiling and running java application using powershell
问题描述
我正在尝试编译一个示例 Helloworld.java 文件.我的 jdk 安装在 C:Program Filesjdk1.7in 中.
I am trying to compile and a sample Helloworld.java file. I have my jdk installed in C:Program Filesjdk1.7in.
我在 C:Helloworld.java 中有我的 Helloworld.java
And I have my Helloworld.java in C:Helloworld.java
我实际上是 powershell 和 java 的新手.我从网上得到了一些关于此的示例,但其中许多建议像这样运行它:
I am actually a novice in both powershell and java. I got some examples from web regarding this but many of them advice to run it like this:
java.exe -classpath $Env:CLASSPATH C:Helloworld.java
java.exe -classpath $Env:CLASSPATH C:Helloworld.java
但是当我在 powershell 中给出这个时,我得到一个名为CLASSPATH"的错误,即使在将它添加到环境变量中之后也没有定义.
But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables.
当我尝试使用以下语法编译代码时:
And when I try to compile the code with the following syntax:
$javac C:Helloworld.java I get an error "javac is not recognised as a token".
所以,我真的迷失在这个话题中.对于像我这样的傻瓜,任何使用 powershell 运行 java 程序的分步过程都将不胜感激.
So, I am literally lost in this topic . Any step by step procedure to run java programs using powershell for dummies like me will be greatly appreciated.
推荐答案
在您的系统中设置环境变量.
Setup environment variables in your system.
设置JAVA_HOME
为C:Program Filesjdk1.7
将字符串 %JAVA_HOME%in
打开新的 cmd
会话.
导航您的 java 源文件夹.
navigate your java source folder.
使用 javac
来编译你的 java 文件.
use javac
to compile your java files.
更新:
此外,如果您在通过 PowerShell 启动可执行文件时遇到困难,请检查此 Microsoft TechNet 文章
also if you are experiencing difficulities upon launching an executable via PowerShell check this Microsoft TechNet article
这篇关于使用powershell编译和运行java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!