djangofan
2009-07-01 18:44:00 UTC
I am having trouble running a Java programe with Windows Powershell.
Any help on this would be greatly appreciated. I want the string
"Hello World!" to print to the main Powershell console window.
Instead, its getting printed to a separate process window that opens
then suddenly closes.
My test class is:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
My PowerShell 2.0 code is this:
set-item -path Env:CLASSPATH -value C:\Test
"CLASSPATH = $Env:CLASSPATH"
[Diagnostics.Process]::Start('java.exe','-classpath $Env:CLASSPATH C:
\Test\HelloWorldApp')
Alternatively, I tried to run it like so, like I would with a regular
DOS shell so that the output shows in the same console :
java.exe -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
It causes an error. I get this error:
PS >C:\Test\Test.ps1
CLASSPATH = C:\Test
java.exe : java.lang.NoClassDefFoundError: C:\Test\HelloWorldApp
At C:\Test\Site.ps1:3 char:5
+ java <<<< -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
+ CategoryInfo : NotSpecified: (java.lang.NoCla...e\HelloWorldApp:
String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Exception in thread "main"
As far as I can tell, my args are correct because here is what the
PCEX ( http://pscx.codeplex.com ) echoargs cmdlet tells me:
PS >echoargs java.exe -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
Arg 0 is <java.exe>
Arg 1 is <-classpath>
Arg 2 is <C:\Test>
Arg 3 is <C:\Test\HelloWorldApp>
Any help on this would be greatly appreciated. I want the string
"Hello World!" to print to the main Powershell console window.
Instead, its getting printed to a separate process window that opens
then suddenly closes.
My test class is:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
My PowerShell 2.0 code is this:
set-item -path Env:CLASSPATH -value C:\Test
"CLASSPATH = $Env:CLASSPATH"
[Diagnostics.Process]::Start('java.exe','-classpath $Env:CLASSPATH C:
\Test\HelloWorldApp')
Alternatively, I tried to run it like so, like I would with a regular
DOS shell so that the output shows in the same console :
java.exe -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
It causes an error. I get this error:
PS >C:\Test\Test.ps1
CLASSPATH = C:\Test
java.exe : java.lang.NoClassDefFoundError: C:\Test\HelloWorldApp
At C:\Test\Site.ps1:3 char:5
+ java <<<< -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
+ CategoryInfo : NotSpecified: (java.lang.NoCla...e\HelloWorldApp:
String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Exception in thread "main"
As far as I can tell, my args are correct because here is what the
PCEX ( http://pscx.codeplex.com ) echoargs cmdlet tells me:
PS >echoargs java.exe -classpath $Env:CLASSPATH C:\Test\HelloWorldApp
Arg 0 is <java.exe>
Arg 1 is <-classpath>
Arg 2 is <C:\Test>
Arg 3 is <C:\Test\HelloWorldApp>