Reputation:
In Eclipse, the folder structure when I create a Dynamic Web Project is
[srikanth@hana Sample]$ ls -R
.:
build src WebContent
./build:
classes
./build/classes:
./src:
./WebContent:
index.html META-INF scripts WEB-INF
./WebContent/META-INF:
MANIFEST.MF
./WebContent/scripts:
jquery-1.7.1.js
./WebContent/WEB-INF:
lib web.xml
./WebContent/WEB-INF/lib:
As you can see, there is this WebContent directory, When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine.
This is the folder structure in Tomcat's webapps directory under application:
[srikanth@hana Sample]$ ls -R
.:
build index.html META-INF scripts src WEB-INF
./build:
classes
./build/classes:
./META-INF:
MANIFEST.MF
./scripts:
jquery-1.7.1.js
./src:
./WEB-INF:
lib web.xml
./WEB-INF/lib:
So, now I can just go to http://localhost:8080/Sample
and can go to index.html properly
What am I doing wrong? Why didn't it work just copying the application from Eclipse to tomcat webapps directory directly? Why do I have to change the directory structure?
Upvotes: 1
Views: 21240
Reputation: 1919
I had the same problem, ./WebContent/index.html not appearing in the Eclipse-exported .war. This occurred on my new Eclipse system after I recreated a working project from my old system with Kepler Eclipse to a new system with Luna Eclipse.
I fixed this by going to Project / Properties / Deployment Assembly. I discovered that the old working system had this rule, while my new non-working systems was missing this rule ...
Source = /WebContent
Deploy Path = /
I corrected this on the new system by Pressing "Add..." and adding the missing rule.
Upvotes: 7
Reputation: 54074
When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine
Not sure what you mean if I moved all the directories and files under WebContent directory a level above, it worked fine
here and what you mean by saying a level above
.
What you should be doing is not copy anything manually but right-click on the project and select Export as WAR
option.
This will create a file named Project.war
that contains the proper file structure i.e. WEB-INF
etc that you are supposed to put under tomcat's webapps
dir
Upvotes: 1
Reputation: 691755
Eclipse allows deploying the webapp directly to a server, without needing to copy anything by yourself. It also allows generating a deployable war file when you're ready to deploy to a test or production server.
Open the "Servers" view, right-click, and choose to create a new server. Once created, right-click on the server and choose to add your web-app into it. And then Eclipse will deploy your web-app to the server.
You're not supposed to manually copy anything from Eclipse. And if you need or want to do this, then you should probably use some ant script which generates the proper deployment structure. This structure is described in the servlet specification. It should have, under the root directory of the webapp, a WEB-INF directory containing:
All the other directories and files that are not under WEB-INF can be served by the web container.
Upvotes: 2