Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Windows 7 x64 and the newest java version (didn't work any better with u21 though)

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

When trying to start a java application to debug it remotely I get the following error:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n <application>
ERROR: JDWP option syntax error: -agentlib:jdwp=server=y transport=dt_socket address=4000 suspend=n

but only when using PowerShell, running the exact same command with cmd.exe works just as expected.

share|improve this question
    
Is your application in a jar format by any chance? –  Andrew Martin Aug 21 '13 at 16:54
    
@Andrew Nope just trying with a trivial Hello World java program right now. Works fine when just executing it with java Test as expected so that's not it. –  Voo Aug 21 '13 at 16:58
    
@Andrew Ok now that's strange.. running the whole thing not in powershell but "good" old cmd.exe works as expected. So now I'm assuming powershell is doing something? editing question accordingly. –  Voo Aug 21 '13 at 17:00

2 Answers 2

up vote 2 down vote accepted
+50

Can you try :

PS> $a = "java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n <application>"
PS> Invoke-Expression $a

I suppose PowerShell try to interpret something in your command line. This way PowerShell just have to execute. Be carefulk, if you have double quotes in your application name use ` before.

You can also try this in order to paramter your call.

$scriptBlock = {java -Xdebug                                                         <# This is comment param 1 #>`
                     -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n   <# This is comment param 1 #>`
                     `"$($args[0])`"}                                                <# Application Path #>

$ApplicationName = "c:\un chemin applicatif\toto"
Invoke-Command -ScriptBlock $scriptBlock  -ArgumentList $ApplicationName

I found it, just try :

PS> $a = "java -Xdebug '-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n' <application>"

I just inclose -Xrunjdwp param inside ''.

share|improve this answer
    
Hmm no that still leads to exactly the same error, but if I print $a it looks like nothing is expanded by PS see log. –  Voo Aug 26 '13 at 11:16
    
@Voo I submit another trick. –  JPBlanc Aug 26 '13 at 11:39
    
Hmm sadly same error in 32bit version too with all variants. Really strange this. –  Voo Aug 26 '13 at 11:42
    
@Voo, I found it, just inclose -Xrunjdwp params inside '' –  JPBlanc Aug 26 '13 at 12:19
    
That works, very nice. Do you know what exactly PS is doing here? I assume it may be using "," as a separator for the argument. Good to keep in mind for future similar problems –  Voo Aug 26 '13 at 13:43

Instead of:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n <application>

Try using:

java -agentlib:jdwp=server=y,transport=dt_socket,address=4000,suspend=n <application>

The latter is used when the target VM is 5.0 or latter, whilst the forner is for machines with a target VM earlier than 5.0

Source: Oracle Docs

share|improve this answer
    
I'm afraid that's the extend of my knowledge. Sorry. –  Andrew Martin Aug 21 '13 at 17:04
    
Yes very strange that. Let's see if there are some windows experts somewhere who can explain what the hell is going on. Using cmd for now works but god is it awful.. –  Voo Aug 21 '13 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.