1
votes

I have recently installed Eclipse and Tomcat for developing Some Web Projects using JSP.

When I see some tutorials then their project structure was different but now it is completely changed. so I am confused that where to write Java Code and where to write JSP Code and HTML Code ?

OLD Project Structure

enter image description here

NEW

enter image description here

2
Are you learning independently or as part of a course with specific requirements? - chrylis -cautiouslyoptimistic-
Looks like you’ve switched to maven. That is important as it has pretty strong opinions - Thorbjørn Ravn Andersen
@ThorbjørnRavnAndersen in latest eclipse creates folder structure like maven with some difference src\main\resources is not created by default so src\main\java must be used for that. also test folders not generated. - Karthikeyan Vaithilingam
@KarthikeyanVaithilingam Maven does not require those folders to be present. Apparently the Eclipse wizard does not create all of them. It still looks very much like a Maven layout. Also, putting resources in src/main/java will not work when compiling from the command line. - Thorbjørn Ravn Andersen
@ThorbjørnRavnAndersen Yes command line wont copy but when you create a war using eclipse it copies non java files as it is to the WEB-INF\classes folder. - Karthikeyan Vaithilingam

2 Answers

1
votes

Most of tutorials are outdated and used older version of Eclipse.

Basically, in a java web application the final output either war or a folder should be as follows.

/ (Web resources like html, jsp, js and css files)
|
+--WEB-INF/
|   |
|   +--web.xml (optional since servlet 3.0)
|   +--classes/ (will have the compiled java classes and class path resources)
|   +--lib/ (third party libraries)
+--META-INF/ (will have manifest file)

Eclipse changed the folder structure to be on par with other build tools like Maven and Gradle.

In the new structure

  1. src/main/java will consists of java sources and other class-path resources like XMLs and other configuration files.
  2. src/main/webapp will have all web resources.

When you build the app eclipse compiles the java classes from src/main/java folder and put the class files in the WEB-INF/classes also copies non java class-path resources as it is to WEB-INF/classes. And the files in src/main/webapp will be copied to the root(/) folder as it is.

Off-Topic: I will advise you to use a build tool like Maven or Gradle so your project will work in any IDE and environment.

0
votes

.java files go under src/main/java, JSPs under src/main/webapp. If you want the old paths, use the text fields given to you when creating the project as you go through the wizard pages.