Remote deployment and debugging to Tomcat from IntelliJ including Remote JRebel updates.

Sometimes it’s nicer or required to develop code by deploying to a remote server. After a lot of trial and error, and frustration with lack of documentation on how this is to be done.  Here’s what I got to work. 

These instructions are mainly for windows, but can be adapted for other operating systems.

REMOTE TOMCAT BOX:

 Software needed:

 Delete the existing ROOT webapp folder in tomcat if you will be deploying to ‘/’

 Open up these ports in your firewall:

  • 1099
  • 8080
  • 5005 (Or whatever port you configure IntelliJ with for debugging)

 Add these lines to config/tomcat-users.xml:

<role rolename=”manager-gui” />

<role rolename=”manager-script” />

<role rolename=”manager-jmx” />

<role rolename=”manager-status” />

<user username=”admin” password=”password” roles=”manager-gui, manager-script, manager-jmx, manager-status” />

 Add setenv.bat (Windows) or setenv.sh to apache-tomcat/bin:

set CATALINA_OPTS=-Drebel.remoting_plugin=true -javaagent:C:\jrebel\jrebel.jar -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,suspend=n,server=y -Xms64m -Xmx2048m -XX:MaxPermSize=768m -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

 Update the javaagent param with the path to your installed jrebel.jar and the Xrunjdwp port with your IntelliJ debug port.

 Use startup.bat and shutdown.bat to control your tomcat instance.

LOCAL DEV BOX:

 Software needed:

  • IntelliJ 13
  • JRebel plugin
  • Maven 3

 Update your .m2/settings.xml file with:

<servers>

   <server>

      <id>RemoteTomcatServer</id>

      <username>admin</username>

      <password>password</password>

   </server>

</servers>

 Update the project’s main module’s pom.xml file with:

<plugin>

   <groupId>org.apache.tomcat.maven</groupId>

   <artifactId>tomcat7-maven-plugin</artifactId>

   <version>2.2</version>

   <configuration>

       <url>http://remotehost:8080/manager/text</url>

       <server>RemoteTomcatServer</server>

       <path>/</path>

   </configuration>

</plugin>

 With this maven plugin, you can run ‘mvn tomcat7:deploy’, ‘mvn tomcat7:redeploy’, etc to build and send war files to the remote tomcat instance.  You can do this from the command line or the Maven Projects tab in IntelliJ.

 Create an IntelliJ ‘Remote’ run configuration with your debugging port information and add a maven command to the ‘Before launch’ box with tomcat7:redploy as the command in the project’s main module directory.  You can have these actions in separate run configurations if you want the debugging and deployment to be executed as needed.

 IntelliJ JRebel settings:

File->Settings->Compiler->  check ‘Make project automatically

File->Project Settings->Modules->  enable ‘Remote Host’ in the modules’ JRebel configuration with your remote host url (http://remotehost:8080/)

To send changed resources, jsps, and class files over to the remote server: Run->JRebel Remoting: Synchronize project

 References:

http://wiki.aiwsolutions.net/2014/02/20/deploy-web-application-to-remote-tomcat- 7-server/

http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/usage.html

http://zeroturnaround.com/software/jrebel/learn/remoting/setting-up-jrebel-remot ing-with-intellij-idea-and-tomcat/

http://player.vimeo.com/video/54855437

http://rockycode.com/blog/debugging-remote-tomcat-intellij/