Eclipse Tomcat file Synchronization - eclipse

I am using Eclipse and Tomcat to develop some J2EE application, Dynamic web project
I am wondering how to synchronize the local files/file structure with the service side.
In practice, we develop our j2ee at a local workspace, but we need to upload these *.class to the service side, so done folder structure and other accessory files, such as web.xml.
Can somebody let me know how to configure Eclipse so that every action I made can also work on the service side?
such as generating *.class files to their destinated folder on service and mapping the folder structure onto the service side.
Many thanks

Related

How-to deploy to application server web project with non-webproject structure (within Eclipse)

Basically what I want is to deploy from Eclipse web project to application server (WebLogic). The problem is that project source files are structured differently than what application server expects (i.e. there is no WEB-INF containing deployment descriptor). As a results when I try to deploy my project to app server it is not recognized as deployable app. Is there a smart and elegant way how-to solve this problem?
OK, i will answer my question myself. Basically this situation can be solved by creating a new dynamic web project with the required structure and then using Linked folder functionality of eclipse.

Technical details of serve modules without publishing in Eclipse WTP and Tomcat?

Eclipse's Web Tools Platform (WTP) allows you to configure Tomcat to "Server modules without publishing":
Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader.
In a 5 step process (just joking, you pick the # of steps), what happens technically and where are the files that Eclipse generates? I did notice that Eclipse generated a org.eclipse.jst.server.tomcat.runtime.70.loader.jar file in the Tomcat lib directory.
The idea is to serve a web application directly from the scattered directory structure of the development workspace, without packaging modules into JARs which then end up in WEB-INF/lib in a WAR.
The main benefits are:
You don't need to build archives.
When you change a resource in your workspace, the change is reflected in the running webapp without redeploying the webapp or restarting the server.
With Servlet 3.0, web resources may also be bundled in library JARs in META-INF/resources, so classes and resources may come from multiple workspace directories.
Tomcat 7.0 supports a VirtualWebappLoader and a VirtualDirContext to configure a web application based on a collection of scattered resource and class directories.
To serve your web app directly from your Eclipse workspace, WTP generates a suitable Tomcat configuration matching your project structure
in $WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/conf/server.xml
For some reason, WTP does not directly use the Tomcat loader and context implementations but has its own WtpDirContext and WtpWebappLoader which are slightly different but similar. (I believe this approach is older than the current solution in Tomcat. There is some special logic for TLD scanning - I'm not sure if this is still required with the latest Tomcat versions.) These helper classes are contained in the org.eclipse.jst.server.tomcat.runtime.70.loader.jar you noticed.
Without Serve modules without publishing, when you change a web resource in META-INF/resources in a library module, this change will not be directly visible in the running application after reloading the current page in the browser.

debug GWT on tomcat using eclipse

I'm using GWT 2.4 and have a ton of code already written. I understand the Jetty server that comes with the GWT plugin has very tight control over the jars that can be used in a project to mimic app engine as closely as possible. I need to deploy to tomcat 7. I modified my project in eclipse and "blessed" it as a dynamic web project so I can export...WAR and upload it to my QA and production tomcat.
I need help with getting the app to run (and debug) on an embedded tomcat (like an honest dynamic web project would). I already have tomcat setup in eclipse and I have my CAS server web app deployed to it.
I've ready tons of either old or confusing posts here and elsewhere. Basically, I'm looking for the same debugging environment I would get with the packaged Jetty server, but on my own tomcat configured with WTP in eclipse...so I can mimic my production environment (just like Jetty mimics app engine)
any help is appreciated.
It should probably a little bit easier, but it's possible. Here's how I do it:
1. Setting up the web server
Using the JavaEE edition of Eclipse, I set up the Tomcat 7.0 server adapter, and define an environment in Preferences > Server > Runtime Environments
File > New > Project... > Web/Dynamic Web Project
Select the target runtime I set up in the first step
Important: In Context Root, enter /
I create an HTML file and a Servlet, and then try running the setup using Debug As > Debug On Server
2. Adding the GWT code server
Project > Properties > Google > Web Toolkit > Use Google Web Toolkit
Important: I always need to change the order in the Java Build Path (Project > Properties > Java Build Path > Order and Export), see http://code.google.com/p/google-web-toolkit/issues/detail?id=4479 - gwt-dev.jar must be pretty much on top of the path.
Project > Properties > Google > Web Application: War directory = "WebContent", also check "Launch and deploy from this directory"
I create some sample GWT content (I create a sample GWT project, and copy most of it over)
I try to GWT compile the project. This shows me, if I got the build path order right - otherwise, the compiler fails early with "java.lang.NoSuchFieldError: warningThreshold".
Debug As > Web Application - just to create a debug configuration. Stop the debug. Edit the debug configuration (Run > Debug Configurations...), deselect "Run built-in server". Start the debug again.
Now, finally, I can debug both the server and the client part (I still need to click two Debug icons to start both!) I can manage the client side from the "Development Mode" view, and the server side from the "Servers" view. At the end of the day, it works great, and using the "Automatically publish when resources change" feature (Servers view > myServerName > Open > Publishing), sometimes even better than with the integrated Jetty.
At first thought, I don't really see why you would be facing a problem. Perhaps, the way Eclipse is laid out is too confusing and daunting.
On my Eclipse, I had been using the default jetty as the server during GWT debug. However, there were some problems which would not be caught by jetty when deployed on Tomcat or JBoss.
And when I added Tomcat or JBoss instances to Eclipse and added my app to those server instances, the debugging worked straight away. Are you missing one piece of vital, but simple info?
Let me presume that the following would fill in your missing link ...
Locating/adding your server instance:
On Package Explorer (or Project Explorer, either one) in Eclipse, you would see, besides your personal projects, a "servers" project. Under it is are configuration nodes listing all your Tomcat instances.
If you cannot see the "servers" node in Package Explorer, it probably is due to your working set filter. (And if you don't know what working sets are ... I guess you would need to beef up on your dexterity in Eclipse).
If you don't already have a Tomcat instance, you simply right click on the "servers" project to add a new server (Package Explorer -> New -> Server ...). You would be asked the location of your Tomcat home. And your desired port number of the server instance. Of course, you would have to ensure that the port number will not clash with the port used by any other inet operation on your box.
Configuring the port number a 2nd time
On the server instance node in Package Explorer, you would find the file you should edit to set the port number to match the one you specified when creating the new Tomcat instance. If you don't know which file to edit, you would need to read up on the Tomcat version you created to find out which file contains the port number config.
You need to config the port a 2nd time because the 1st time tells Eclipse where and at what port to expect the server instance to be running. The 2nd time is to configure the server instance itself.
Adding your app to the server
However, the nodes in "servers" project only allow you to configure your Tomcat instances. There is yet another view called the "server view" to further configure your tomcat instance. You need to enable Server view from Window->Show View->Server->Servers.
Right click on the server instance in the "Server View" to add your app.
Running debug off the Maven generated target.
There are times you wish to debug the war structure to figure out which jars are missing in the war. And incrementally remove jars from your war to figure out the jars that are already supplied by the server. Since JBoss supplies many of the jars already, you would have to figure out if your development jars are of the versions as those expected by JBoss.
You would create another Eclipse project in your workspace and make an Eclipse folder softlink in your 2nd project to point to the Maven generated target of your first project. And you specify target/{maven generated webapp directory} as the webapp directory of your 2nd project. What I mean by "maven generated webapp directory" is the unzipped intermediate directory generated by Maven (used by Maven to generate the zipped war file).
This is the cleanest way to debug production war if you could faithfully replicate the production tomcat/jboss server on your Eclipse development box.
If you prefer JBoss.
Somehow, JBoss config node is not listed in the "Servers" node in Package/Project Explorers. You would need to go to your JBoss installation directory to edit them.
Remote debugging.
If you wanted to debug the app on your production box, or on a server sitting on another box, you would have to start that tomcat instance under debug. You should read up on that. You have to specify the debug port.
Then in Eclipse, at Run->Debug Configuration->Remote Java Application, you specify the app and the debug port.
The first time you debug, Eclipse "may not know" where the source files are, especially if your app has multiple project dependencies. (Why can't Eclipse search the source files from my list of projects?) Anyway, you have to specify where to find your source files. And then when your debugging traverses into another project dependency, you would have to over-write the location of the source files.
So, voila! That is how I got my debugging working. I advise you to avoid remote debugging as much as possible unless you need to diagnose production problems. Unless you are doing remote debugging, do not attempt to deploy the war to local server, but simply depend on associating the project to the server instance.
Eclipse is too confusing
I know Eclipse is too confusing and you have to wade thro its features. You just have to bear with it. Eclipse menus & views are apparently optimized for plugin-programmer-centric not user-centric.
For example, why would I go to "help" to install new software? I used to expect that "Help->Install new software" to be an instructional manual to installing new software.
It beats (and annoys me) that the Eclipse team did not combine the operations together so that I could add apps to a server instance at Package Explorer. Why not? As a user I would expect to see only a single entry point to configuring my servers.
To alleviate the confusion, I like encouraging people to download and install Springsource's version of Eclipse (STS). It's the same Eclipse, except that STS has the essential parts installed and has a dashboard pointing to compatibly installable plugins. Tomcat is preinstalled as VMware tc Server. And the views are correctly config'd to show the server instances. And the correct workable Eclipse-Maven bridging plugin is pre-installed.

How to deploy Java web application project from Eclipse to live Tomcat server?

I have developed an web application using HTML, Java Servlet and all. While developing I was using Tomcat to deploy it in order to test it.
Now my development is done and I want to make it live. For that we have live server but as I am new to all this I dont know how to deploy my java web application on live server?
So please help me if you know to answer?
My Project Structure
ProjectName
->src
->beanClass
->class1
->Class2
->easyServlet
->Servlet1
->Servlet2
->Servlet3
->easyTrans
->Class1
->Class2
->Class3
->Class4
->build
->WebContent
->META-INF
->MENIFEST.mf
->WEB-INF
->lib(contain javascript files)
->web.xml
->html1
->html2
->html3
->html4
->html5
I am also using MySql so what I have to about it..
You will have to build a WAR of the project.
You can do this
in eclipse: right click on the project, Click "Export", and choose war file in the dialog (and mention, the destination, name and all)
via ant using the war task
The ant option is better because when you have multiple developers on the project and the code is in version control, it is easier to get the project automatically (using ant) and build a war. (you have version control, don't you?)
But this is more of an operational difference (albeit an important one) but the war created in either way are same
Deploy the war to the server
You can manually copy the war file to the $TOMCAT_HOME/webapps directory (See the "Creating and Deploying a WAR File" section on this article)
You can use the Tomcat 6 "Manager" application.
Update
You said that you are using MySql also. MySql should be installed on a server (it can be on the same server) and the configuration should be changed (username, password, server details) so that the application connects to the same database (I am sure you are not hard coding database details and credentials in your application and reading them from some configuration, this is the configuration that has to be changed)
For that we have live server but as I am new to all this I dont know how to deploy my java web application on live server?
I assume by this you meant , you have a public IP assigned to a server. Now you can install tomcat into this server and open the tomcat port for public and you will be able to access.
Now build a war file of your webapplication and put it into web-apps dir of the tomcat and start the server
Making a few assumptions here. You need
A tomcat instance running on your production server
Permissions to make changes to the tomcat instance
A war file that bundles your application
If you have both, then you need to navigate to the Tomcat manager page and follow the instructions to upload your war file.
Deploy the war to the server
You can manually copy the war file to the $TOMCAT_HOME/webapps directory.
You can use the Tomcat 6 "Manager" application.

Custom Re deployments from My Eclipse IDE

Experts
When we redeploy any application from an IDE such as MYEclipse , it just redeploys the .class files. I want to customize the eclipse developer, so the deployer can also deploy the custom files (other than class files).
Should i write any custom ANT script for Myeclipse or any custom settings the My Eclipse provides us ?
IDEs along the classes and libraries usually deploy everything they find in the web / www-root folder (in the folder that contains the WEB-INF and META-INF).
So you can configure your deployed applications structure using the IDE by structuring the content of that folder.
If it still doesn't fit your needs, then ANT would be the best option.
In my opinion ANT is always the best option, but using the development environment's functionality is proven faster then writing an ant build file.
Say, if you're developing a web service, a web application consuming that service, and a library that both the service and the webapp uses, then with a single (and not even long or difficult) ant file you can build them, create the aar, war and jar files and deploy them all in their correct places, eg. under axis, inside the global lib folder, and in the webapps folder.
All these in one step.