====== The fastest way to make a deployment in eclipse ======
**Update about Tomcat**
When I started this tutorial, I've found that every single change
in a web page under JBoss forces this to restart the application.
Unfortunately it is not the case with Tomcat: Tomcat ignores everything
else except web.xml, and this is a bit cumbersome if you are changing
jsf or jsp pages frequently, because these changes aren't detected
and refected by Tomcat. On the contrary, the pages appear unchanged.
With other J2EE servers I don't have an idea of what will happen....
Although eclipse has a system to deploy applications to the application server of our choice (Tomcat, jboss, Web Sphere, etc.) I think that the system it uses is extremely slow. Other solutions that have appeared ([[http://zeroturnaround.com/software/jrebel/|jrebel]] (commercial), and others are depicted [[http://stackoverflow.com/questions/998737/integrating-tomcat-and-eclipse-as-a-hot-deploy-environment|here]], [[http://techblog.bozho.net/?p=1246|here]], [[http://stackoverflow.com/questions/2296387/jsf2-and-maven-hot-deploy|here]] and [[http://stackoverflow.com/questions/1793533/hot-deploy-of-development-changes-with-eclipse-tomcat-and-jetspeed|here]]) involve in some way keeping a synchronization of files between the deployed application and the developed application.
**I humbly think that there is a better solution,** cheaper and faster: it consists on a proper selection of the configuration of your project in eclipse and using a symbolic link to the deployment directory of the app server: this way, every change in your source code is reflected automatically in the deployment directory (because in fact both are the same directory) and saving a lot of computer time.
Let's go over the details of the process for Linux and Windows.
===== Steps =====
==== Assumptions ====
For the rest of this article, I will assume that we are working in an JSF eclipse project called "MyTest". This solution works for every web project: jsp's, jsf, struts, whatever. The solution is very simple as you will see.
I've started with a project with a default configuration:
{{ :java:20140426_hotdeployment.png?direct&200 |}}
==== In eclipse, change the compilation dir of your compiled classes ====
This directory has to be ''web/WEB-INF/classes'', so that the directory WebContent can be equal as a complete deployed application.
So, right-click on MyTest -> properties -> Java Build Path and configure the directory so that the binaries are left in the WEB-INF directory:
{{ :java:20140426_2.png?direct&600 |}}
==== General instructions ====
In general, you have to create a symbolic link in the web application of your preference. In this way, whenever a change is made in eclipse, that change is reflected instanly in the webserver. Usually webservers can be configured to redeploy applications everytime a change is detected.
This method has many advantages:
* you avoid to start and stop the webserver every time you want to redeploy
* and avoid to pack the web application to be deployed (and afterwards be unpacked by the application server)
An important step is to create a symbolic link, in other words, a directory that points to the same content as other directory. Here are the instructions in different platforms:
=== How to create a symbolic link in Linux ===
Let's say that we have the directory ''WebContent'' and we want to create the symbolic link ''MyTest'' who points to the same content as ''WebContent''. We can achieve this by issuing the command:
/usr/local/srv/tomcat/webapps$ ln -s /home/user/workspace/MyTest/WebContent/ MyTest
For this example, my application resides in the directory ''/home/user/workspace/MyTest'' as you might see.
=== How to create a symbolic link in Windows 7 ===
In this case our application is in the directory ''c:\workspace\MyTest'' and our webserver is in the directory ''c:\tomcat\webapps'':
C:\tomcat\webapps>mklink /d MyTest "c:\workspace\MyTest\WebContent"
vínculo simbólico creado para MyTest <<===>> c:\workspace\MyTest\WebContent
=== How to create a symbolic link in Windows XP ===
Although Windows XP does not have the tools to do it, it can support symbolic links. The only thing you have to do is to download a tool called [[http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx|junction]] to do the job. After it, it's done:
C:\>junction "c:\tomcat\webapps\MyTest" "c:\workspace\MyTest\WebContent"
This example creates a symbolic link called ''MyTest'' who points to the same content as the directory ''c:\workspace\MyTest\WebContent''.
==== Step by step examples ====
=== Jboss 5 and Windows XP ===
Assumed you have the configuration of your project as described before, the only thing you have to do is create the symbolic link.
For this example, I've have my Jboss installation under ''c:\jboss'', and I will refer it as JBOSS_JOME.
To make the symbolic link you need first to install ''junction'' command, where you can get it [[http://technet.microsoft.com/es-es/sysinternals/bb896768.aspx|here]].
After installing, you should issue a command like this:
junction "JBOSS_HOME\server\default\deploy\myTest.war" "c:\workspace\myTest\WebContent"
== Start the business ==
The only thing you have to do to start the application is the following:
* Please, before of everything, remove all the "servers" in eclipse: remember that running the application through eclipse will spoil everything because eclipse will try to overwrite the deployment directory, and because it is the same directory as your webContent directory, everything will be mixed up and spoiled. You have been warned.
* Start the Jboss application server, manually, ''JBOSS_HOME/bin/run.bat''. It is a good measure to have a look to the logs, you can issue a ''tail -f LOGFILE'', but the detailed instructions are for another chapter
* Start your eclipse application: you can easily verify that every change in the application is reflected instantly in the Jboss directory and Jboss redeploy automagically your application reflecting every change
== Debugging ==
**You can also debug your application.** To do so, edit the file ''JBOSS_HOME\bin\run.conf.bat'' and add the following line:
rem # Sample JPDA settings for remote socket debugging
set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
This will make Jboss to hear from the port 8000 for debugging interruptions. Who will interrupt JBoss?? Properly configured, eclipse will do.
In your eclipse click on run -> debug configurations. Under "Remote Java application" click on "new":
{{:java:20140519_1.png|}}
Configure it with the apropiate values (remember, port 8000) and you will have an entry like this:
{{:java:20140519_2.png|}}
Whenever you want to debug your application you only have to start the remote debug option you have created. This will make your application to stop in the step points you have set.
=== Tomcat 6 and Linux ===
**Important:** You have to edit the ''context.xml'' file and set the "reloadable" feature as this:
Also, as cited [[http://www.mulesoft.com/tcat/tomcat-reload|here]], you can add some //watched resources// that, upon change, will force tomcat to reload the application.
Assumed you have the configuration of your project as described before, the only thing you have to do is create the symbolic link.
For this example, Tomcat is installed under $TOMCAT_HOME (in my particular case, ''/usr/local/srv/tomcat''). The only thing you have to do is:
TOMCAT_HOME$ ln -s /home/rluna/workspace/MyTest/WebContent/ $TOMCAT_HOME/webapps/myTest
This way, you will have **exactly the same** contents in two places at the same time: in the proper tomcat directory **and** in your eclipse project.
== Put things to start ==
Every time you want to run your application the only thing you have to do is:
- Start Tomcat ($TOMCAT_HOME/bin/start.sh, **Don't use** the "start server" button on eclipse)
- Start eclipse (Remember!!!! **Don't use** de Run as -> run on server facility of eclipse or you will ruin your project
And that's it, because everytime you make a change in a class, or in a web page, it will be reflected automatically in tomcat.
== Debug: Things you have to do the first time ==
You can debug your application, also. For debugging your application, you have to run Tomcat with the remote debugging facility enabled. To do so, you have to add the following line to the java start parameters:
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
I've opened the file ''$TOMCAT_HOME/bin/catalina.sh'' and I've located the following line:
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi
and added the following:
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi
And start Tomcat.
**For debug in eclipse,** open the "Debug configurations..." option:
{{ :java:20140517_1.png?direct&400 |}}
And select "Remote Java Application" and then "New":
{{ :java:20140517_2.png?direct&400 |}}
And fill it with the following data:
{{ :java:20140517_3.png?direct |}}
~~DISQUS~~