Java Dynamic Web Project with Eclipse - eclipse

Currently to access my dynamic web project (running in a tomcat servlet container) I access the following url:
http://localhost:8080/[Eclipse_Project_Name]
I have a couple questions about this:
Where is the configuration that
is forcing the url to require the
Eclipse project name? I don't see
this in the web.xml.
Say I'd like
to change the url used to access my
project. Maybe I want it to by at
the root: localhost:8080/, or maybe
a different directory structure
altogether. How do I do this?
Thanks

Where is the configuration that is forcing the URL to require the Eclipse project name? I don't see this in the web.xml.
When you create a New Dynamic Web Project, the first page of the wizard asks you for a Project name and in the third page, you can change the web module settings such as the Context root which defaults to the project name (the context root is the part of the URL you're talking about).
This information is not stored in the web.xml, it is stored in the .settings directory of the project (to be precise, in org.eclipse.wst.common.component) and will be added later to /Servers/Tomcat v6.0 Server at localhost-config/server.xml in a <Context> element when you will Add the project to the Tomcat server.
Say I'd like to change the url used to access my project. Maybe I want it to by at the root: localhost:8080/, or maybe a different directory structure altogether. How do I do this?
Right-click on your project then Properties > Web Project Settings. There you can change the context root. Then go to the Server View, right-click on the Tomcat server and select Clean... and you should get prompted to accept the modification of the server configuration.

to change the context root in eclipse please follow the below procedure
Right click on Project-->Properties-->WebProject

Related

What config do I have to change in my Eclipse Web project, so that Tomcat redirect URLs without any path to the project URL

In Eclipse Oxygen I have set up a Web project (facets Dynamic Web Module, Java & JavaScript) with the name MyProject.
When I start up Eclipse's Tomcat (Version 8.5) I can view the site under the project URL http://localhost:8080/MyProject/. So far so good. But how can I configure the Eclipse project that the server's base URL http://localhost:8080 redirects to the project URL?
Bonus question: Is there a way to change the path in the URL without changeing the project name, so that the project URL is, say, http://localhost:8080/FancyOtherName/ instead of http://localhost:8080/MyProject/?
So there are a few options here. You could deploy the application in the root context of the server to get rid of the MyProject in the URL altogether. There are a few ways to do this, but the easiest is to have the .war file from your build be name ROOT.war. This will deploy the application in the server's root context and will get rid of MyProject from the URL. To change the context of the application in your projects URL, you could do so through some configuration of the application (which I don't have enough details to comment on), or through the Tomcat configuration. By deploying the application with the ROOT.war MyProject
will be removed from the URL, but you could add <Context path="" docBase="FancyOtherName"></Context> to the $CATALINA_HOME\conf file in the <Host> tag as well as adding to autoDeploy="false" and deployOnStartup="false" to the host tag so it looks something like this <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false">. This will stop the application from deploying twice, once in the root context and once at http://localhost:8080/FancyOtherName/, and will only deploy the application at http://localhost:8080/FancyOtherName/. Good Luck!

Rename JEE project

I'm working on a JavaEE project, I already have the skeleton of an old project. All i have done is rename the project, packages and change the name in the project file (.project). But now when i'm trying to run, it returns error in the browser "The requested resource is not available". I've checked the web.xml and added a new jsp in vain it doesn't work. In the browser's address, it gives me the old name of the project(http://localhost:8061/smsgate/). I've tried a lot to fix the problem. what can i do? Is there any other file that i have to update and write in the new name? Please give me your ideas (knowing that i have to use that old project)
Do Project -> Clean in your workspace by selecting your current project. Also if using maven then right click your project and do maven -> clean.
Manually go to your target directory of your ear module and shift-delete everything inside your target and then rebuild your project to form new ear.
if you have configured the web.xml properly then strike your app url. Also ctrl+shift+delete your browser history and then check.
Why not create a new project using a maven archetype, just type in the console:
mvn archetype:generate
It will show you a list of available archetypes from the web, just choose one of them, for JEE6/JEE7 you could choose among:
1019: remote -> org.codehaus.mojo.archetypes:webapp-javaee6 (Archetype for a web application using Java EE 6.)
1020: remote -> org.codehaus.mojo.archetypes:webapp-javaee7 (Archetype for a web application using Java EE 7.)
If you agree with me, just type:
1019 or 1020 according to your needs and answer the questions like:
projectId:your-project-name
groupdId:com.yourdomain.reverse
version:1.0

Apache Tomcat 7.0 not working properly with eclipse EE juno version

When I run apache tomcat 7.0 alone, it works without any flaw in my browser I can execute the examples also, but when I apache tomcat 7.0 in eclipse I'm getting a 404 error message saying that "requested resource is not available".
I just type the session example program and run it again, it shows this 404 error message only.
How do I resolve it?
I don't know whether it's the problem with tomcat or with eclipse..
Please help!!
I think your eclipse is configured to load a webapp folder that is not the one installed with tomcat, please follow the steps below:
Open the Run Configuration of the Tomcat 7 in the eclipse
Go to the Arguments tab
In the VM arguments, it should have a property listed: -Dwtp.deploy=...
The folder on this property define the webapp folder for the tomcat started from the eclipse
If you want it to load the tomcat examples, change the folder of that property to the one that have the examples
try doing the following steps:
Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.
Go to C:\apache-tomcat-7.0.34\webapps,
R-click on the ROOT folder and copy it.
Then go to your Eclipse workspace,
go to the .metadata folder, and
search for "wtpwebapps".
You should find something like
your-eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse).
Go to the wtpwebapps folder, R-click, and paste ROOT (say "yes" if asked if you want to merge/replace folders/files).
Then reload tomcat test pagea to see the Tomcat welcome page.
I feel your pain. I am also using Tomcat 7.0, and I've gotten servlets to work in Tomcat doing everything by hand. Then a couple of days ago I downloaded eclipse, and after a struggle I successfully got some servlets to work in eclipse.
I downloaded the Java EE version of eclipse here:
http://www.eclipse.org/downloads/
And then I followed this tutorial:
http://www.vogella.com/articles/EclipseWTP/article.html
The tutorial is a little out of date, but I managed to get eclipse setup correctly using that tutorial. In a couple of places, the tutorial says to click on Window->Preferences->..., which for me was equivalent to Eclipse->Preferences->.... The biggest problem I had was when the tutorial said:
Create a new package called ....
There were no instructions on how to create a new package. The way you create a new package is by looking in your project folder for:
--JavaResources
--src
Then right click on the src folder and select:
New-->Package
Send me a comment if you have any questions about any of the steps in the tutorial.
I got that 404 Error constantly until I figured out what was the correct path with which to call the servlet. If you are calling the servlet, say with a <form>'s action attribute, the url should look like this:
<form action="/<project name>/WelcomeServlet" method="get">
And that would correspond to a web.xml something like this:
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>com.exmaple.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/WelcomeServlet</url-pattern>
</servlet-mapping>
Are you using servlets 3.0 or 2.5? With 3.0 you use the syntax:
#WebServlet("/WelcomeServlet")
public class WelcomeServlet extends HttpServlet {
for the url mapping instead of a web.xml file.
I had a similar issue with my project.
Maybe Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.
Go to webapps directory inside apache directory (for example C:\apache-tomcat-7.0.34\webapps), right click on the ROOT folder and copy it.
Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps".
Start the Tomcat server by eclipse.
You should find something like your-eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse).
Pay attention that the folder tmp0 is present only if the server is started.
Go to the wtpwebapps folder, right click, and paste ROOT (say "yes" if asked to override folders/files).
Then try to see the Tomcat welcome page.
Bye
Monica
Doubleclick the Tomcat server entry in the Servers tab, you'll get the server configuration.
At the left column, under Server Locations,
select Use Tomcat installation radio button ,browse Server Path of the Tomcat Root directory(Ex: D:\RaviTeja\installed\apache-tomcat-7.0.57) and browse Deploy path aslo webapps folderof tomcat
(Ex: D:\RaviTeja\installed\apache-tomcat-7.0.57\webapps).
This way Eclipse will take full control over Tomcat, this way you'll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse.
3. Please find below Tomcat configuration screen shot.

URL issue with tomcat include project name

I am using Eclipse for J2EE project...
one device send request to my side and url like
http://myIP:myPort/corporationweb/Controller
/corporationweb/Controller is fixed we can't change it because it made on device
my project name in eclipse is "VirtualTest" but here tomcat include project name if i mapping any servlet, /corporationweb/Controller URL like
http://localhost:8080/VirtualTest/corporationweb/Controller
I need page open without change project name
any i can mapping servlet directly so URL like http://localhost:8080/corporationweb/Controller
any URL rewriting technique..
make as default application for my project
Rightclick project in Eclipse, choose Properties, go to Web Project Settings and set Context root to /.
This will let Eclipse deploy the project on context root instead of project name (which is the default).
Unrelated to the concrete problem, you really need to ensure that your application is written the way so that it does not care on which context path the application is been deployed. This is namely a server specific setting which is not controllable from inside your project. Make use of HttpServletRequest#getContextPath() the smart way.
If you want to make "VirtualTest" as default application for your project, and not showing this name in URL, you can simply change project name to "root", which is a special name for the default application.
Your URL will be like:
http://localhost:8080/corporationweb/Controller
If you are using Eclipse. Go to server and remove the unwanted project which are Synchronized, then restart your server. Worked for me

Dynamic Web Project libraries

Good morning in my timezone.
I have imported one Dynamic web project to my eclipse. I have downloaded the Tomcat server.
If I work without any IDE, I know that every libraries that we use in the project must be inside the lib folder in tomcat.
Folder structure : Tomcat\webapps\WEB-INF\lib
My question is, if I need a library (*.jar) should I put it directly in the lib folder or should I configure in the build path, adding it in the libraries tab?
Second question, my project steels have the red cross above the project name, but I do not see where the error is, in the src folder no class have any error and inside the Web Content folder there is not any cross, so how can I know where the problem is?
Thanks in advance.
Best regards developer community.
There shouldn't be any need for configuration, just copy them in the lib folder.
Make sure you have set the right jdk and the server libraries. right click on project -> build path -> configure -> libraries. if there is no tomcat runtime lib, you should add it.(I assume tomcat is embedded in eclipse. If not, right click on servers(next to console) and add the tomcat server.)