使用PowerShell编译和运行java应用程序 [英] Compiling and running java application using powershell

查看:1619
本文介绍了使用PowerShell编译和运行java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译和示例Helloworld.java文件。
我在C:\Program Files \ _jdk1.7 \ bin中安装了我的jdk。

I am trying to compile and a sample Helloworld.java file. I have my jdk installed in C:\Program Files\jdk1.7\bin.

我在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'的错误是即使在env变量中添加它也没有定义。

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 Files \ jdk1.7

添加到 PATH 变量字符串%JAVA_HOME% \ bin

打开新的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆