Change eclipse's built in tomcat context.xml file using WTP? - eclipse

Is it possible somehow to modify the contents of the context.xml that eclipse uses when you are doing "Run as" -> "On server"... and "Debug as" -> "on server"
We have some settings that are in our production environments context.xml file and we need them to be available to eclipse built in tomcat as well.
I know we could use eclipse to run run on an external server, but thats not as convenient.

Have a look at the automatically created project "Servers". There should be a folder for each configured Server. There, open the context.xml and add anything you like to be in the "default" context (Parameter-Tags for example).
Anything that's inside there will be used to populate the context.xml WTP automatically creates on publishing for each project on that Server.
Or use the project specific way: put a context.xml with your contents inside META-INF in your project (have a look here: http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_specify_the_Tomcat_context_configuration_for_my_Web_Application.3F)

Related

Eclipse with Tomcat does not automatically republish my WAR file

I've got Windows 8.1 with a 1.6 JDK manually installed.
I'm using Eclipse (Kepler, Java EE IDE for Web Developers).
I imported a project that builds a WAR file using an Ant build script; that shows up as a Project.
I created a Tomcat6 Server (downloading the available Eclipse package); that shows up as a second Project.
On the Modules tab for the Server, I clicked "Add External Web Module...", browsed to the folder holding my WAR file and clicked OK. I then added the name of my WAR file (directory name "...\SpiffyApp" to file name "...\SpiffyApp\spiffyapp.war"). I confirmed that the name of the path is "/"; I clicked to have "Auto reloading enabled" checked, and clicked OK.
I admit - I peeked inside the Server configuration. I clicked on "Open launch configuration"; in dialog "Edit launch configuration properties", on the Arguments tab, I discovered the following property setting:
-Dcatalina.base= "....metadata.plugins\org.eclipse.wst.server.core\tmp0"
Then in my mischief I observed that the "tmp0" directory had a "webapps" subdirectory. Aha!
I notice that, under some circumstances, the "SpiffyApp" is republished under "webapps" - problem is, I can't figure out when!
Specifically, I'm disappointed that Eclipse doesn't republish my app to "webapps" when I tell the server to "Clean"/"Publish". What I'd really like is for it to republish automatically when I rebuild the WAR.
I can get the WAR redeployed when I do all of this:
stopped my Tomcat Server
delete all folders under "tmp0/webapps"
delete all folders under "tmp0/work" (tip I got from Chris Lercher, here)
rebuilt my WAR file
Started my Server
Surely I'm doing something wrong.
What are the rules here? Am I really left to remove the Web Module, delete the folder in "tmp0" and re-add the Web Module?
What you're doing wrong is expecting it to watch for changes on an archive file, which generally isn't expected to change. Import the WAR as a project and then Eclipse can deploy it properly when something actually changes within the app.
Otherwise you might try forcibly Cleaning the server area from the context menu of the Tomcat server instance in the Servers View.

Eclipse - Make dynamic web application include other projects in workspace

I'd like the exported .war file to include the other (referenced) projects in the workspace.
When I reference them in the Build Path only, it shows no "Problems", but ClassNotFoundException is thrown later, when I try to "Run on Server" or export.
Using eclipse Kepler, tomcat 7.0.42.
I've seen the solution here: Not able to configure run path for web application project in Eclipse workspace; that's how it works now. Is there a more convenient way?
Are you running Tomcat within Eclipse? Try this:
Run -> Run Configurations... (or Debug Configurations...).
Find Tomcat v7.0 Server at localhost (or whatever it's named for you) under Apache Tomcat on the left-hand side.
Go to the Classpath tab on the right.
Select User Entries and click Add Projects....
Select the projects you wish to include.
That should place that project on Tomcat's classpath.

Map external directory outside tomcat installation in eclipse Dynamic Web Project

I want to map an external directory outside tomcat installation which stores images in eclipse Dynamic Web Project's tomcat server. I have done that in tomcat directly by adding context tag in server.xml file. But when I done that in eclipse Dynamic Web Project's tomcat server.xml file. It is not working. I am using Tomcat 6.
My question is:
How to map an external directory outside tomcat installation in eclipse Dynamic Web Project?
Is it the good way to map external directory outside tomcat installation?
Thanks
Brajesh
Try a linked resource. Go to the folder in which you want your external directory to apprear. Now open the File menu -> New -> Folder.
Type in the name.
Click on "Advanced >>". Select "Link to alternate location (Linked Folder)". Browse to the external directory.
Click Finish.
That creates a link from your workspace to the external directory. It's possible that the plugin supports that.

Eclipse publishing to Tomcat

I recently came back to using Eclipse after 2 years of IntelliJ. Things have changed.
Now when I try to run Tomcat, it tries to publish my project to it. What the hell is publish?
What ever happened to pushing a war into the webapps directory and letting Tomcat deploy it?
Right now my deployment is broken because of compilation errors. I have a feeling that Eclipse is taking my project and copying it to webapps dir without first building it properly.
Can someone explain to me what exactly publishing does, and also how to turn it off and use Tomcat like normal people?
A the "Servers" view, you can double click on your Tomcat instance, to open the server settings editor.
There, at the upper right corner, you can find the Publishing options. Check the "Never publish automatically" option, and save.
With this it should be enough.
Oh, and by "Publishing", they kind of mean "Deploying", or "Copying to the deploy directory", depending on what server you are using.
Eclipse (Helios) makes a copy of your entire Tomcat configuration and starts a new instance of the Tomcat server when you are running the web application from Eclipse. That is why you must shut down any existing Tomcat service before running in Eclipse.
The application runs out of your workspace, not out of the "webapps" folder. Eclipse modifies the copied server.xml file to add "CONTEXT" tags that include your workspace project folders in the running application list.
The path in the "CONTEXT" tag should be the name of your project folder.
You can export the project to a WAR file and deploy your web application to the webapps folder if you want.

How can I add my application to Tomcat in Eclipse?

I have a web app built with Maven.
Most of the time, I built the application using Intellij IDEA, but now I want to import the application in Eclipse to see something in this IDE.
After mvn eclipse:eclipse, I add in Eclipse the app, but when I try to add the app to the server (tomcat), I receive:
There are no resources that can be added or removed from the server
Solutions?
You need the project to have a Eclipse Dynamic Web Module facet. You can try doing this via the project properties dialog and looking at project facets, then clicking the appropriate check box. This may not be available however, so you may need to do the next thing.
Create a backup of your project and follow the directions at dzone.com. This'll allow you to modify the project facets via your eclipse .project file.
Keep in mind, once you add those facets, you cannot change them back via Eclipse. Definitely make sure you have a backup before starting.
This step worked for me:
Right-Click on the Project Name, then
Maven-->Update Project..
Click OK
After doing this I was able to see my project in Add/Remove Programs.
As mentioned somewhere else adding Eclipse WTP didn't do any good, however I performed the above step after I had already added Eclipse WTP, so I am guessing that may not be needed.
This was done for Eclipse Juno.
Hope this helps someone.
Edited: You can follow this link as above mentioned I think might have needed WTP and that add a lot of other things into the workspace.
http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556
Check whether Maven Integration for Eclipse WTP is installed. If not, install it from Eclipse Marketplace
After installation restart Eclipse
Right click your project and Maven--> update project configuration
Delete tomcat and re create tomcat (clean tomcat,add your project,publish and enjoy)
I've got Tomcat 6, Java 1.6, and was trying to get it to work in Eclipse Juno Service Release 1's "internal server" (whatever that's called.) Here's what I did that worked for me:
(Found these instructions at http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java-ee-5-web-modules/)
I should point out that I followed ClutchDude's instructions to make my project a Dynamic Web Module facet. It didn't work on its own for me, but maybe it was part of making it work in the end.
Using Eclipse (or other text editor), open the file
.settings/org.eclipse.wst.common.project.facet.core.xml
Find the line that reads
<installed facet="jst.web" version="3.0"/>
3.0 is for Tomcat 7.x (so says mkyong.) Change it to 2.5 (or 2.4).
I restarted Eclipse and it worked for my project.
The reason why this is happening is because eclipse by default looks for the deployment descriptor in the folder {project.home}/Webcontent/WEB-INF/web.xml where as the Maven puts them in src/main/webapp/WEB-INF/web.xml.
So when you are trying to add your project onto the server eclipse cannot find a deployment descriptor and hence you get the annoying message.
This can be solved by adding the following entries in .settings/org.eclipse.wst.common which can be found in
Project home folder in your workspace if it is a new maven project.
The folder where you already imported from if you are using Import -> Maven projects.
Make the following changes in to the org.eclipse.wst.common
wb-resource deploy-path="/" source-path="/src/main/webapp"/. Add this entry.
Edit --> property name="java-output-path"
Please check the following link from more details. http://java.dzone.com/articles/webapps-eclipse-and-maven.
The comments section has an excellent example with a working project.
This issue was fixed for me my installing additional eclipse modules. in particular, the ones related to m2e-wtp. just do a search for m2e in the plugins search listing for your version of eclipse
If you face an error like "There are no resources that can be added or removed from the server",
then
1) Go to the META_INF of your websvcsEAR and go to the application.xml.
2) Goto modules-> clickDetails and add the module that is existing. i.e., some EAR which your project demands.
3) Click ok
4) Now go to your server -> right click -> add and remove -> add your EAR.
Maybe you don't need add your application to the server's configuration. I think that you must use m2e eclipse plugin in order to launch the app.
For example, in your eclipse you will see a contextual menu called "Run as" if you right-click on your pom file. You can clicking on "Maven build" and Maven will download all the information needed to start tomcat.
I hope this helps you.
I used
mvn eclipse:eclipse -Dwtpversion=2.0
in command line in the folder where I had my pom.xml. Then I refreshed the project in eclipse IDE. After that I was able to add my project.
I was able to resolve this by removing my EAR project from my Eclipse workspace, then re-importing it.
Well, with a Spring and maven project, i got it that way:
Eclipse Version: 2019-06 (4.12.0)
Java 1.8
Tomcat 7
Yes, go to Project Properties >> Facets >> select Dynamic Web Module but dont apply yet!!!
Right under, it should appear a link Further Configuration Available. Click on it, otherwise one will have to edit .settings/org.eclipse.wst.common.component manually. Update source directory to src/main/java. (source)
Then in Facets window check Java - mine was pointing to 11 even though i don't have Java 11 installed or configured like a JRE runtime. I could only add/remove when changed to 1.8. (source). Note: That was really the problem, why don't Eclipse get this configuration automatically from the project?
Finally Eclipse creates some directories like WEB-INF and META-INF, just delete them.