源文件夹不在Java构建类路径上

源文件夹不在Java构建类路径上

本文介绍了Spring WebApp Maven-源文件夹不在Java构建类路径上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注文章了解如何使用Spring MVC创建Java Web应用程序.我首先在单独的位置创建了Web应用程序项目 CounterWebApp ( mvn eclipse:eclipse -Dwtpversion = 2.0 ),然后将整个项目导入Eclipse.

I am following this article to understand how to create a Java web application with Spring MVC.I created the web app project CounterWebApp at a separate location first(mvn eclipse:eclipse -Dwtpversion=2.0) and then imported the whole project in Eclipse.

我很难将 BaseController.java 放入本文所述的正确包中.要么是

I am having difficulty to put the BaseController.java in the correct package as stated in the article.It's either

  1. 源文件夹不在Java构建类路径上", OR

BaseController.java没有在该位置创建(/src/main/java/com/mkyong/controller/BaseController.java )

BaseController.java is not getting created at the location(/src/main/java/com/mkyong/controller/BaseController.java)

请帮助我了解如何正确执行此操作?在Eclipse中导入项目之后,下面是我的 .classpath 文件和 pom.xml 的内容.

Please help me understand how to do it correctly ? Following are the contents of my .classpath file and pom.xml just after importing the project in eclipse.

<classpath>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/3.2.0.RELEASE/spring-web-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.2.0.RELEASE/spring-context-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.2.0.RELEASE/spring-aop-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.2.0.RELEASE/spring-beans-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.2.0.RELEASE/spring-expression-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-webmvc/3.2.0.RELEASE/spring-webmvc-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar" sourcepath="M2_REPO/junit/junit/4.11/junit-4.11-sources.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
</classpath>

pom.xml

<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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.sandeep</groupId>
        <artifactId>CounterWebApp</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>CounterWebApp Maven Webapp</name>
        <url>http://maven.apache.org</url>

        <properties>
                <spring.version>3.2.0.RELEASE</spring.version>
                <junit.version>4.11</junit.version>
                <jdk.version>1.7</jdk.version>
        </properties>

        <dependencies>

                <!-- Spring 3 dependencies -->
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-core</artifactId>
                        <version>${spring.version}</version>
                </dependency>

                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-web</artifactId>
                        <version>${spring.version}</version>
                </dependency>

                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                        <version>${spring.version}</version>
                </dependency>

                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>${junit.version}</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
        <build>
                <finalName>CounterWebApp</finalName>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.0</version>
                                <configuration>
                                        <source>${jdk.version}</source>
                                        <target>${jdk.version}</target>
                                </configuration>
                        </plugin>
                </plugins>
        </build>
</project>

推荐答案

问题如何解决:

  1. 在"main"下创建一个文件夹"java"(文件->新建->文件夹).完成此步骤后,我们在src/main下有3个文件夹:java,resources,webapp.

  1. Created a folder "java" under "main"(File -> New -> Folder).After this step,we have 3 folders under src/main: java,resources,webapp.

我下载了本文随附的.zip,将.classpath与我的.path进行了比较,并进行了相应的修改.

I downloaded the .zip provided along with the article,compared the .classpath with mine and modified it accordingly.

这时,我的eclipse.classpath内容如下:

At this point,my eclipse.classpath content looks like:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/3.2.0.RELEASE/spring-web-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.2.0.RELEASE/spring-context-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.2.0.RELEASE/spring-aop-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.2.0.RELEASE/spring-beans-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.2.0.RELEASE/spring-expression-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-webmvc/3.2.0.RELEASE/spring-webmvc-3.2.0.RELEASE.jar"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar" sourcepath="M2_REPO/junit/junit/4.11/junit-4.11-sources.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
</classpath>

最后,创建了Spring MVC控制器类BaseController.java(/src/main/java/com/sandeep/controller/BaseController.java )

Finally.created the Spring MVC controller class BaseController.java(/src/main/java/com/sandeep/controller/BaseController.java)

  • 选择"java",新建->其他->类->下一步.

  • Select "java",New -> Other -> Class -> Next.

包装:com.sandeep.controller

Package: com.sandeep.controller

这篇关于Spring WebApp Maven-源文件夹不在Java构建类路径上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:19