rob
rob

Reputation: 3012

Debugger does not attach itself to remote target if shell script is run before in IntelliJ

I need to start a Java application with a shell script in order to attach the remove debugger to it later (No generally, but this particular application). The arguments when running the .jar in the shell script are:

"-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y"

But this part is working. If I manually execute the shell script and run the debug configuration from IntelliJ after, everything works as expected. If, however, I tell IntelliJ to execute the shell script automatically before trying to attach the debugger it does not work. The shell script is executed and the debug port is open but the debugger does not attach itself to it.

This is the run configuration for the debugger: Debug Configuration

When I run it, I can see that the shell script is executed in the console:

Listening for transport dt_socket at address: 8000

But the debugger does not attach.

edit:
I figured out the problem. The shell script is blocking, therefore IntelliJ does not continue and attach the debugger. Therefore I tried to run it in the background like this:

nohup ./shell_script -debug > /dev/null &

This works fine in the terminal. It immediately continues if you execute the command. If, however, I execute the same command from IntelliJ, the it does not run in the background and continues to be blocking.

Upvotes: 1

Views: 514

Answers (1)

rob
rob

Reputation: 3012

Apparently Ant is able to spawn a new process when executing a shell script which is blocking. Therefore I was able to start the application with an Ant target which is non-blocking.

<target name="run" depends="clean,install-release">
    <exec executable="pkill" spawn="false">
        <arg line="-f application_name"/>
    </exec>
    <exec executable="bash" spawn="true">
        <arg line="${target}/install/some.sh -debug"/>
    </exec>
</target>

Upvotes: 0

Related Questions