'SpringMVC with Eclipse, should the source folder be src or src/main/app?

https://tokkan.net/spring/mvc.html

I'm following this tutorial to create my first SpringMVC project.

It's in Japanese. You don't need to read it.

I will describe the procedures

Step 1. create a "Dynamic Web Project"

Step 2. convert it to a Maven project

When create the project, I noticed that the source folder in the tutorial is simply "src" but however it's "src\main\app" on my Eclipse

I tried to "Edit" it as "src" and found out it was not allowed ("Cannot nest source folder "src/main/java" inside source folder "src"")

I wouldn't mind this if it didn't come back and bite me

When creating the "Controller" class, I created a package (spring.test) first as per the tutorial. But when I started writing the class, all the imported packages (org.springframework) and annotations are underlined in red, implying that the dependencies are missing

But I have already successfully added all the dependencies in pom.xml. Something tells me it has something to do the src folder. So I copied the file to src folder (from "src\main\app\spring\test" to "src") and the red underlines disappeared

I also tried "src\spring\test" and it also works fine

So exactly which folder should be the correct src folder (into which the controller.class file is stored? ) and is this setting configurable in one of the xml files?

The .classpth files is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="test" value="true"/>
    </attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

The pom.xml is as follows (same as in the tutorial except for the project name, etc):

<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>PeterMVC4</groupId>
  <artifactId>PeterMVC4</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>11</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
  </properties>

<dependencies>
    <!--追加-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.9.RELEASE</version>
    </dependency>
</dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <compilerArgs>
            <arg>-Xlint:all</arg>
          </compilerArgs>
          <release>${java.version}</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
 </build>

</project>


Solution 1:[1]

You probably needed to update the pom.xml contents shown in the tutorial from <sourceDirectory>src</sourceDirectory> to <sourceDirectory>src/main/java</sourceDirectory>.

The default folder path has changed (that tutorial was written for Apache Tomcat 8.0), but you can make it anything you want on the second page of the Dynamic Web Project wizard. I'd be surprised if it had any problem with the new default, as that's what the Maven archetype would create.

The second page of the wizard, which configures the Java Source Folders.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1