Debug web app in IntelliJ, webapp built by maven, run by jetty - debugging

I'm using s/o code, it's a java webapp built by maven. The webapp is run by maven script, like below, and the app is run on localhost:8080, :
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<contextPath>/</contextPath>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<!--<port>8085</port>-->
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<stopKey>stop</stopKey>
<stopPort>8089</stopPort>
</configuration>
</plugin>
</plugins>
</build>
I want to attach the debugger of IntelliJ so that I can step through the code. I tried to set up a debugger configuration like: Jetty Server, then 'Remote' but it said Application Server not specified. I also tried with 'Local', it said 'main config file not included'.
So what must I do to attach the debugger?
Thanks in advance.

The easiest way is to:
Expand your project in the Maven Projects tab.
Expand Plugins > jetty items.
Right-click jetty:run.
Choose Debug from the context menu.

I know it's too late to reply this question, but It's worth sharing the latest update on this issue as a modern solution: You can also run jetty using “mvnDebug jetty:run” which has the same effect. Which display the following logs in the terminal
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
[INFO] Scanning for projects...
Just remember to choose the correct socket address(e.g. 8000), then:
Open Intellij
Run -> Edit Configuration
In Run/Debug Configuration window, you need to click on (+) button to add a new configuration
Select Remote
Keep the default configuration as is, just change the listening port to corresponding one (8000).
Enjoy.

When I was getting "main config file not included" it was because the path to Jetty in my Application Server configuration (on Run/Debug Configurations dialog) was deleted during my OS X upgrade (I had put it in /usr/share/java).
I reinstalled jetty-hightide-8.1.5.v20120716 under /usr/local, updated the configuration and all is well.

Related

Remote debug or local debug with tomcat embedded in Spring boot

I am working on a new project which embedded a tomcat with the dependency spring-boot-starter-tomcat:2.5.3 (into vaadin-spring-boot-starter).
I am building my project into a .jar, and launching it with "mvn spring-boot:run".
But because of the embedded tomcat, I am unable to use the debug mode with Eclipse.
I have already try to launch a remote debug session, with :
MAVEN_OPTS= -Xmx1024M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
Eclipse connects itself well, but breakpoints are not working and it shows me only one thread, without any more informations.
So, do you have any idea how can I make it works ?
Thanks you for your time !
When running application using mvn spring-boot:run you can attach debugger like this:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8000"
By providing spring-boot.run.jvmArguments system property.
Alternatively, you can build application first and then run it using the following command:
java -jar app.jar -Dagentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
When you provide debugger configuration using MAVEN_OPTS, the debugger is attached to the Maven process, however, the application is running in a separate Java process without a debugger attached.
The easiest way to debug a Spring Boot application from an IDE is to not use Maven at all but instead directly launch the main method from the #SpringBootApplication class.
As a third solution, I have installed Spring Tools 4 on the Eclipse Marketplace.
It makes me able to launch a #SpringBootApplication in debug mode, like Leif Astrand said, but with an IHM (Boot Dashboard).
Another solution is described here:
https://vaadin.com/forum/thread/17519592/debug-with-intellij
This solution also helped me get around the problem of connecting the remote debugger, but breakpoints not being reached (see my comment above).
You can add a JVM arg to the config params of the plugin, like this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- my edits start -->
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
</jvmArguments>
</configuration>
<!-- my edits end -->
</plugin>

How to debug a Maven OpenJFX application in IntelliJ

Since JavaFX has become OpenJFX and needs to be added as a dependency to your Maven project, debugging a OpenJFX application has become complicated. In this question it is already answered how to solve it for NetBeans. But IntelliJ works slightly different. The Ppom.xml has been setup according to this example.
How can you run an OpenJFX (JavaFX) application which is configured as a Maven project in debug mode in IntelliJ?
If you would copy the addition of VM options in the pom.xml for javafx-maven-plugin as given by José Pereda here, you can run the application with 'mvn javafx:run#debug' and then manually attach it to the IntelliJ Debugger by go to the menu 'Run - Attach to process...' and the select your application.
However, if you want debugger and application to be started with a single click, IntelliJ is a but troublesome. You can create a Remote Debug configuration which first launches your application and the debugger serially. Or have Compound Configurations which does both in parallel. The problem is to get them synchronized.
I found the following solution. Make your application run as debug client and the IntelliJ debugger as server. The VM options for the javafx-maven-plugin in the pom.xml file should have 'server=n':
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<!-- Default configuration for running -->
<id>default-cli</id>
<configuration>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
<execution>
<!-- Configuration for debugging -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8000,suspend=y</option>
</options>
<mainClass>org.waninge.test.JFXTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Create a Maven Run Configuration in IntelliJ with 'javafx:run#debug' in the 'Command line'.
Create a Remote Run Configuration with the following settings:
Debugger mode: 'Listen to remote JVM';
Transport: 'Socket';
Host: as in the pom
Port: as in the pom
Now the Remote Run Configuration will start a debug server waiting for clients. The Maven Run Configuration will connect to the debug server, or fail if the debug server isn't online.
Now, to get everything started with a single click, you can create a Compound Run Configuration and add the Maven and the Remote Run Configuration to it. Starting this configuration will launch the two in parallel, and you can debug your application.

GWT + Maven + Tomcat + JNDI + Eclipse configuration

I've got a project using GWT 2.6.1 + Maven 3.2 + Tomcat 5.5 (yes, I know it's an old one ...) + Eclipse Luna which is using JNDI allowing for external parameters to be configured.
As you might know, the context XML file is located at /conf/Catalina/localhost/myWebApp.xml where myWebApp is the Java web application name.
I am using gwt-maven-plugin for this project (the one from mojo haus) which has the version 2.6.1.
Here is my current configuration :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<module>xxx.yyy.myModuleName</module>
<runTarget>myWebPage.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<encoding>UTF-8</encoding>
<failOnError>true</failOnError>
<style>OBF</style>
<i18nMessagesBundle>xxx.yyy.zzz.client.ui.i18n.OlbClientMessages</i18nMessagesBundle>
<extraParam>true</extraParam>
<extraJvmArgs>-Dgwt.compiler.optimizationLevel=9</extraJvmArgs>
<extraJvmArgs>-Xms128M</extraJvmArgs>
<extraJvmArgs>-Xmx1200M</extraJvmArgs>
<extraJvmArgs>-XX:MaxPermSize=768M</extraJvmArgs>
<noServer>true</noServer>
<logLevel>INFO</logLevel>
</configuration>
</plugin>
As you can see, i am using the noServer (configured to "true") option because I must use an external Tomcat container for the server side.
My question is :
How can I enable client side AND server side debugging within my actual configuration through a step-by-step help.
I've made a lot of attempts but i can't make things working.
I've tested running the "mvn gwt-debug" which tries to connect to default port 8000 and then connecting a remote java application which connects to my webapp to localhost:8000 and it works well, but it's only for the server side.
I also need to debug the client side in the DEVMODE.
Thanks for your help.
There are two ways to run a remote server. First is using using DevMode with -noserver and pointing the war directory to the output war directory of the external server. The second way is to use the CodeServer entrypoint and run a WTP server runtime and set the launcher directory to tomcat output war directory.
I prefer the second routine, and built automation into the GPE fork.
http://gwt-plugins.github.io/documentation/gwt-eclipse-plugin/servers/Tomcat.html - see it in action here. There are videos and such.

How to see changes without building maven project?

I have simple java web application. web application has some js, css, html files. when I change js files, i am not able to view new changes in browser. For new changes i have to perform "mvn clean install" command then only i am able to see new changes. So Is there any way to see changes without performing this command ?
thanks.
it's not recommended to perform "mvn clean install" unless you want to use your code into another project.
That's what I do when I want to publish code change into a webserver for debug purposes
1/ I configure tomcat7-maven-plugin into the parent pom project:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
2/ then
mvn tomcat7:run
will launch an embded tomcat7 server with your resources deployed.
to publish your code to a remote tomcat, you can use
tomcat7:deploy
after having configured tomcat7 plugin correctly
alternatively, import your maven project as an eclipse project (plugin name: m2e) then right click on the projet, debug on server will launch the eclipse configured tomcat.
whenever you save a resource, it will be automagically deployed on the eclipse-managed tomcat.

maven tomcat7 plugin authentication fail, 403 Forbidden

I'm posting this after weeks of effort. I try and try because I felt guilty of posting this because there are thread similar to this. But still I'm getting slightly different error. So what I have is a very simple spring(no need to be spring of course bcz problem is with maven) application with maven.
This is plugins section from my pom.
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<username>tomcat</username>
<password>s3cret</password>
<path>/Test</path>
<port>8080</port>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Earlier I have problems with maven tomcat plugin not working with tomcat 7 etc etc but now with "tomcat7-maven-plugin" there are solved. I'm using 'http://localhost:8080/manager' as the URL. For almost all threads about this maven tomcat compiler plugin are about build failure. But my build succeed(I run as tomcat7:deploy). Problem is tomcat is replying
tomcatManager status code:403, ReasonPhrase:Forbidden
along with the html that we see when we got a authentication failure on browser. The same code works fine under my Linux box. I try different scenarios of using server element in settings.xml which is inside .m2 and inside maven_home/conf etc. Still not working.
As I figure out maven cannot authenticate tomcat. username and password is find and I can log in using GUI. So expecting a help here.
p.s - my tomcat-users.xml fiel
<role rolename="manager-gui" />
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Url is not correct try with :
<url>http://localhost:8080/manager/text</url>
what is the content of tomcat-users.xml file. Did you correctly set permissions ?
See http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html
I could get tomcat deploy work but environment is different. So anyway I'm going to tell how I could do it since may be It'll help someone.
In this case I have tomcat6 as my web container and I'm using eclipse Helios as the IDE.
First of all I have haven environmental variables set as described in the maven web site(Maven download installation help). Which means environmental variables M2_HOME and M2 are set and M2 is in my path variable.
Then in eclipse I have maven installation folder, local repository(In case if it is not default) and settings.xml file correctly. (These setting are in Window -> Preferences -> Maven -> Installations and User settings)
In tomcat_home\conf\tomcat-users.xml I have created user with the role manager-script.(Note that here I use tomcat6)
< role rolename="manager-script"/>
< user password="s3cret" roles="manager-script" username="tomcat"/>
In POM.xml I have maven tomcat plugin defined as follows.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>TomcatServer</server>
</configuration>
</plugin>
Then on eclipse Run Configurations I create a configuration to run goal "tomcat6:deploy" ( This site from apache says tomcat:deploy is the goal but it didn't work).
Which runs perfectly and deploy my app to the container. Once it is deployed app need to be undeplyed using "tomcat6:undeploy" before deploying again.
I'm not a expert about this and still I have doubts on some facts. But since I saw this question in lots of places I thought this will help someone it the same problem.
Thank you
Today I tried same application with Tomcat 7. I need to change plugin artifactId to "tomcat7-maven-plugin". And I have to change the url as "http://localhost:8080/manager". After doing these changes deploy works fine. Also I figure out that maven read settings.xml inside .m2 folder. There is also a settings.xml file inside mvaen_home/conf but it is not the one it read. Another thing I found is there is no undeploy for tomcat7 for tomcat6 there was a undeploy.
Sometimes when all from the above criteria are matched and You still get the error there is a chance that You are using mvn tomat7:deploy command. And at the same time the server is maintained by Eclipse wchich dosen't go heand in heand. You could stop the server in Eclipse IDE and than try again with the mvn command.
After trying several things the following configuration worked for me.
Please give it a try
tomcat-users.xml
<role rolename="manager-gui"/>
<user password="tomcat" roles="manager-gui" username="tomcat"/>
pom.xml
<!-- Maven Tomcat Plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/html</url>
<username>tomcat</username>
<password>tomcat</password>
<update>true</update>
<path>/Test</path>
</configuration>
</plugin>

Resources