How do I start a Liberty server in debug mode in the background with the liberty-maven-plugin? - maven

Use Case
The liberty-maven-plugin has a debug goal which allows you to start the server in debug mode, but in the foreground.
Often when wanting to attach the debugger, this is all you'd need. You can execute tests separately somehow or via other goals launched from another shell.
But the debug goal, like the run goal, runs in the foreground and blocks until the server process completes.
If I want to continue to the next phase of my build, e.g. on to run integration tests, it could help to configure a start goal to start the server in debug mode, in the background, and continue on.

Use: src/test/resources/jvm.options
In src/test/resources/jvm.options, for example:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=7777
This is the default value for the <jvmOptionsFile> configuration parameter (described here), so of course you could configure a different location if desired.
Note:
Though an alternative might appear to be to use the <jvmOptions> configuration, it does not work well with the commas (',') embedded in this value.
Warning:
You may be expecting a message from the starting JVM:
Listening for transport dt_socket at address: 7777
However you will not see this from your Maven execution log, it actually appears in the console.log file of the configured server. So the Maven execution will just pause at the point of logging message:
[INFO] Starting server defaultServer.
If you fail to connect in time you'll see:
[INFO] Server defaultServer start failed. Check server logs for details.

Related

Thorntail not exiting gracefully

I'm running a Thorntail 2.2.1.Final microservice with Maven using either of these commands
mvn thorntail:start
mvn thorntail:run
It runs fine, but when I hit Ctrl-C it doesn't exit the application i.e. the console returns, but the app runs in the background. I've tried to stop it
mvn thorntail:stop
But that doesn't work. I have to go and kill the process. I'm using Windows 10.
The thorntail:start and thorntail:stop goals are meant to be used together as part of a Maven lifecycle, typically for integration testing. That is, thorntail:start intentionally leaves the process running in the background, and thorntail:stop should stop it.
For interactive use, mvn thorntail:run should be used. That keeps waiting in the foreground, and Ctrl+C should stop the application behind it.
If none of that works, it's a bug. I'd recommend filing a bug in https://issues.jboss.org/browse/THORN and preferrably also include a jstack output for the process.

Jmeter Tests work at the console, but not with the JMeter Jenkins(Performance) plugin

I'm working with Maven(3.3.9), JMeter (3.0) and the Jenkis Performance plugin.
When I run my JMeter test with Mvn on my Computer, everything works fine, but when I try to make a build #Jenkins, the JMeter tests always fail(100%).
Has anybody an idea what could be the cause for my problem?
My JMeter tests use an assertion, which checks for "viewExpired", because I'm using JSF, and a second assertion, which skips all the other tests as soon as the first test fails.
Here is my log (i changed it a bit, server-adress,etc.)
https://gist.github.com/anonymous/801ef819233468246eb9e42893366b56
Tom -
From your logs, it looks to me that your TLS connections are failing from the Jenkins machine to the target test server (test.at.com). If your Jenkins machine has an Xterm interface, can you install JMeter there and launch it in the GUI mode to validate? Your test plan should run without issues. The logs also indicate that it is using an empty key store. Do you have the test.at.com certificate added to the default java key store on your Jenkins machine? By default, JMeter uses the java key store present under /lib/security. You can override it with your own trust store by using the property
You can edit the JMeter system.properties to use a custom Keystore by editing the below lines
\# Keystore properties (client certificates)
\# Location
\#javax.net.ssl.keyStore=H:\\cert\\client_keystore.jks
\#
\#The password to your keystore
\#javax.net.ssl.keyStorePassword=changeit
\#
\#javax.net.ssl.keyStoreProvider
\#javax.net.ssl.keyStoreType [default = KeyStore.getDefaultType()]
I would also suggest enabling the SSL debug options if you want to know the actual root cause. You can turn it on in the system.properties
\#javax.net.debug=ssl
Having said all the above, please can you check if the connectivity is there between your Jenkins machine and the actual target host
**telnet test.at.com 443**
2017/01/23 15:50:17 DEBUG - org.apache.jmeter.protocol.http.sampler.JMeterClientConnectionOperator$JMeterDefaultClientConnection: Connection 0.0.0.0:33542<->62.116.177.251:443 closed
2017/01/23 15:50:17 DEBUG - org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$7: Closing the connection.
2017/01/23 15:50:17 DEBUG - org.apache.jmeter.protocol.http.sampler.JMeterClientConnectionOperator$JMeterDefaultClientConnection: Connection 0.0.0.0:33542<->62.116.177.251:443 closed
2017/01/23 15:50:17 DEBUG - org.apache.jmeter.protocol.http.sampler.JMeterClientConnectionOperator$JMeterDefaultClientConnection: Connection 0.0.0.0:33542<->62.116.177.251:443 shut down
2017/01/23 15:50:17 DEBUG - org.apache.jmeter.protocol.http.sampler.JMeterClientConnectionOperator$JMeterDefaultClientConnection: Connection 0.0.0.0:33542<->62.116.177.251:443 closed

Debug gradle jettyRun in IntelliJ

I run Jetty from the command line with:
export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
gradle jettyRun
and see:
Listening for transport dt_socket at address: 9999
... then in IntelliJ Idea (Ultimate 12.1.3) I create a new remote debug configuration with all defaults, changing only the port to 9999.
When I start (debug) using the remote configuration, I see:
Connected to the target VM, address: 'localhost:9999', transport: 'socket'
... which makes me think everything is working as expected.
Then I make requests that should result in hitting breakpoints. But the breakpoints are never triggered.
What am I doing wrong?
Thanks.
You could have the "org.gradle.jvmargs" variable set in your gradle.properties file. This causes the JVM to be forked which means you are no longer debugging the right process.
In this case, you could either not set the "org.gradle.jvmargs" or pass it the debug parameters eg.
org.gradle.jvmargs=-XX:MaxPermSize=128m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1233
Setting the debug parameters in org.gradle.jvmargs would configure the forked process for debugging.
In IntelliJ (at least on 12.1.5) you can just go to JetGradle, right click on jettyRun and then click on Debug.

Running remote JBoss in debug mode, Bootup Time Issue

I am trying to run remote jboss in debug mode to debug my application and i have set
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%
in run.bat file, and am trying to start the jboss server using ant jboss.start but it is taking some time and then timing out, am not sure why this is happening, is there a way out?
Also as jboss is timing out, I would like to increase bootup time for the server, how can i do it from the command line?
Side note, server.log file does not show any messages which jboss is trying to bootup in debug mode (not sure if this would help but thought so sharing this info.)
Any clue or suggestions?
You should set:
suspend=n
in debugger startup settings.
suspend - True if the target VM is to be suspended immediately before the main class is loaded; false otherwise.
Your JBoss waits infinitely for debugger connection, this is useful when you want to troubleshoot startup issues, otherwise do not suspend your VM and let the debugger be connected any time you want.
I was frustated to get jboss started in debug mode through command line
Finally following seemed to work
1.Below should be the last line in /bin/run.conf.bat
rem # Sample JPDA settings for remote socket debugging
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n %JAVA_OPTS%
If there is anything below this, delete it.
2.Also when you are running jboss from command prompt please check whether -Xdebug is at the start of JAVA_OPTS.
Then it should display following message
Listening for transport dt_socket at address: 8787
3.In eclipse use 127.0.0.1 instaed of localhost.
I don't know the reason behind it...but when I changed localhost to 127.0.0.1 it worked
(Make sure you replace localhost with 127.0.0.1 at 2 locations 1.Eclipse remote debug and 2.URL while running your application in browser)
Also check project name.
Sometimes we need to change the port number.
I never had such issues with tomcat.

Tomcat failed to shutdown

When I add the following Java options to enable debugging:
JAVA_OPTS="$JAVA_OPTS -noverify -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
I get the following error whenever I try to shutdown the tomcat:
ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initializedFATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)
Thank you for a nice short explanation, PHeath! Following your advice, I found the best way to solve the problem is simply to use CATALINA_OPTS instead of JAVA_OPTS.
Looking into catalina.sh, one can see CATALINA_OPTS is only used by the "start" and "start-security" commands, whereas JAVA_OPTS is also used by the "stop" command (at least with Tomcat 6.0.33 on openSUSE 12.1).
At least if you have Tomcat installed on Linux using a package manager then modifying the CATALINA_OPTS variable in /etc/tomcat6/tomcat6.conf (or whatever path in your distribution) is cleaner than changing the catalina.sh script directly, for the package manager assumes that the user changes only configuration files and breaking this assumption may cause problems when upgrading the Tomcat packages (e. g. lost settings because the catalina.sh file is overwritten).
I think one should prefer CATALINA_OPTS over JAVA_OPTS not only for JDWP but for many other options as well: e. g. if one uses the heap size option -Xmx... then it would be reasonable to put it into CATALINA_OPTS, as the "stop" command does not need much heap.
You are trying to debug tomcat on startup, so it binds to port 5005 when the jvm starts.
When you run catalina.sh stop, it starts up another jvm which also tries to bind to port 5005.
You need to move the debug args to the run and start arguments (in catalina.sh) of tomcat, putting them straight into the JAVA_OPTS is the cause of the issue you're having.
The problem is your tomcat is still running on the debug port(5005) or some other service running on the same port(5005).
If tomcat still running, you can kill it
if it in linux environment ps -ef|grep java, and identify the process id of it. and kill the process using sudo kill -9 .
If it in windows environment got to task manager and kill the tomcat and java process.
Now you should be able to start the server in debug mood without any prob.
This can happen on debugging unit test through the tool(eclipse) which has been executed through the maven. To sole this you can flow the same process.
First close the Eclipse and kill the java process as well and start it again.
This is due to both applications are listening the same port number i.e 8000 while running in debug mode.
One quick solution is change the debug port to 8001 in startup.bat
SET DEBUGPORT=8001
It seems that the port 5005 is already in use. Check open ports with netstat command.
This may be because you already opened tomcat. Check your processes.
It appears you are starting Tomcat with the Debugger enabled, This causes the JVM to attach to the Process for Debugging, However in the catalina.sh there is a case statement for start, stop, restart, so on and so forth. Issuing the stop command still adds this in as it is part of your Global JAVA_OPTS and tries to start the debugger listening on the same port for the shutdown command. If you remove the address=50005 from your JAVA_OPTS or use the start jdpa commands to start the VM with the debugger this will fix your problem.
Look at the default catalina.sh in the latest Tomcat distribution if you need a clean copy. It sounds like someone has made changes inside yours that are invalid and causing JDPA to run on start, stop, any command issued.
set JPDA_ADDRESS=8001 in catalina.bat i.e debug port
and change all 3 ports in server.xml
In my case (Tomcat installed form tarball) I had those debug options unintentionally set in my env. This fixed the error:
$ unset JAVA_OPTS

Resources