在Maven网络应用项目中,CSS和JavaScript文件在哪里? [英] Where do CSS and JavaScript files go in a Maven web app project?

查看:1880
本文介绍了在Maven网络应用项目中,CSS和JavaScript文件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在切换到使用Maven for Spring Web应用程序项目,我遇到了一个简单的问题。我不知道将CSS和JS文件放在新项目结构中的位置。



传统Web应用程序结构



在传统的Java Web应用程序结构中(在Eclipse中,创建为动态Web项目),我将CSS,Javascript和Images文件放在以下结构中:

  WebContent 
| __css / myStyles.css
| __js / myjs.js
| __images / myImage.gif
| __WEB-INF

然后在我的jsp如果我想引用一个CSS文件,我做如下: / p>

 < link rel =stylesheethref =<%= request.getContextPath()%> / css / myStyles .css> 

这很好。



Maven Web App结构



在Maven项目中,我将css

与WEB-INF相同,就像在传统的动态Web项目中一样。但是当我执行以下操作时

  mvn clean tomcat:run 

我从Spring框架得到以下错误:

  springframework.web.servlet.PageNotFound  - 在DispatcherServlet中找不到与URI [/appname/css/myStyles.css]的HTTP请求的映射



第二次尝试



将我的css文件夹放在 src / main / resources 下,但是当我执行以下操作时: p>

  mvn clean tomcat:run 


b $ b

我从Spring框架得到以下错误:

  org.springframework.web.servlet.PageNotFound  - 在DispatcherServlet中找不到与URI [/appname/css/myStyles.css]的HTTP请求



第三尝试



放置我的css文件夹 src / main / resources



结果:如上



我相信这是一个简单的东西,但我被困,也许我可以俯瞰的东西。提前感谢



UPDATE :添加pom.xml以查看是否可以帮助解决问题:

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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.dariopardo< / groupId>
< artifactId> jfreechartdemo< / artifactId>
< name> abc< / name>
< packaging> war< / packaging>
< version> 1.0.0-BUILD-SNAPSHOT< / version>
< properties>
< java-version> 1.6< / java-version>
< org.springframework-version> 3.0.6.RELEASE< /org.springframework-version>
< org.aspectj-version> 1.6.9< /org.aspectj-version>
< org.slf4j-version> 1.5.10< /org.slf4j-version>
< / properties>
< repositories>
< repository>
< id> spring-maven-release< / id>
< name> Spring Maven Release Repository< / name>
< url> http://maven.springframework.org/release< / url>
< / repository>
< repository>
< id> spring-maven-milestone< / id>
< name> Spring Maven里程碑存储库< / name>
< url> http://maven.springframework.org/milestone< / url>
< / repository>
< repository>
< id> spring-roo-repository< / id>
< name> Spring Roo存储库< / name>
< url> http://spring-roo-repository.springsource.org/release< / url>
< / repository>
< repository>
< id> JBoss Repo< / id>
< url> https://repository.jboss.org/nexus/content/repositories/releases< / url>
< name> JBoss Repo< / name>
< / repository>
< / repositories>
< pluginRepositories>
< pluginRepository>
< id> spring-maven-release< / id>
< name> Spring Maven Release Repository< / name>
< url> http://maven.springframework.org/release< / url>
< / pluginRepository>
< pluginRepository>
< id> spring-maven-milestone< / id>
< name> Spring Maven里程碑存储库< / name>
< url> http://maven.springframework.org/milestone< / url>
< / pluginRepository>
< pluginRepository>
< id> spring-roo-repository< / id>
< name> Spring Roo存储库< / name>
< url> http://spring-roo-repository.springsource.org/release< / url>
< / pluginRepository>
< / pluginRepositories>
< dependencies>
<! - Spring - >
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> $ {org.springframework-version}< / version>
< exclusions>
<! - 排除Commons登录SLF4j - >
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclusion>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> $ {org.springframework-version}< / version>
< exclusions>
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-test< / artifactId>
< version> $ {org.springframework-version}< / version>
< scope> test< / scope>
< exclusions>
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-aop< / artifactId>
< version> $ {org.springframework-version}< / version>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-aspects< / artifactId>
< version> $ {org.springframework-version}< / version>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-tx< / artifactId>
< version> $ {org.springframework-version}< / version>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-jdbc< / artifactId>
< version> $ {org.springframework-version}< / version>
< classifier />
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-orm< / artifactId>
< version> $ {org.springframework-version}< / version>
< classifier />
< / dependency>
< dependency>
< groupId> commons-pool< / groupId>
< artifactId> commons-pool< / artifactId>
< version> 1.5.4< / version>
< classifier />
< exclusions>
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> commons-dbcp< / groupId>
< artifactId> commons-dbcp< / artifactId>
< version> 1.3< / version>
< classifier />
< exclusions>
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclude>
< exclusion>
< groupId> commons-pool< / groupId>
< artifactId> commons-pool< / artifactId>
< / exclude>
< exclusion>
< groupId> xerces< / groupId>
< artifactId> xerces< / artifactId>
< / exclude>
< exclusion>
< groupId> xerces< / groupId>
< artifactId> xercesImpl< / artifactId>
< / exclude>
< exclusion>
< groupId> xml-apis< / groupId>
< artifactId> xml-apis< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-web< / artifactId>
< version> $ {org.springframework-version}< / version>
< classifier />
< exclusions>
< exclusion>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< version> $ {org.springframework-version}< / version>
< / dependency>

<! - AspectJ - >
< dependency>
< groupId> org.aspectj< / groupId>
< artifactId> aspectjrt< / artifactId>
< version> $ {org.aspectj-version}< / version>
< / dependency>

<! - Hibernate - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 3.6.4.Final< / version>
< classifier />
< / dependency>
< dependency>
< groupId> org.hibernate< / groupid>
< artifactId> hibernate-entitymanager< / artifactId>
< version> 3.6.4.Final< / version>
< classifier />
< exclusions>
< exclusion>
< groupId> cglib< / groupId>
< artifactId> cglib< / artifactId>
< / exclude>
< exclusion>
< groupId> dom4j< / groupId>
< artifactId> dom4j< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< version> 1.0.0.Final< / version>
< classifier />
< / dependency>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< version> 4.1.0.Final< / version>
< classifier />
< exclusions>
< exclusion>
< groupId> javax.xml.bind< / groupId>
< artifactId> jaxb-api< / artifactId>
< / exclude>
< exclusion>
< groupId> com.sun.xml.bind< / groupId>
< artifactId> jaxb-impl< / artifactId>
< / exclude>
< / exclusions>
< / dependency>
< dependency>
< groupId> javax.validation< / groupId>
< artifactId> validation-api< / artifactId>
< version> 1.0.0.GA< / version>
< classifier />
< / dependency>
< dependency>
< groupId> cglib< / groupId>
< artifactId> cglib-nodep< / artifactId>
< version> 2.2< / version>
< classifier />
< / dependency>
< dependency>
< groupId> javax.transaction< / groupId>
< artifactId> jta< / artifactId>
< version> 1.1< / version>
< classifier />
< / dependency>

<! - 记录 - >
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< version> $ {org.slf4j-version}< / version>
< / dependency>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> jcl-over-slf4j< / artifactId>
< version> $ {org.slf4j-version}< / version>
< scope> runtime< / scope>
< / dependency>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-log4j12< / artifactId>
< version> $ {org.slf4j-version}< / version>
< scope> runtime< / scope>
< / dependency>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.15< / version>
< exclusions>
< exclusion>
< groupId> javax.mail< / groupId>
< artifactId> mail< / artifactId>
< / exclude>
< exclusion>
< groupId> javax.jms< / groupId>
< artifactId> jms< / artifactId>
< / exclude>
< exclusion>
< groupId> com.sun.jdmk< / groupId>
< artifactId> jmxtools< / artifactId>
< / exclude>
< exclusion>
< groupId> com.sun.jmx< / groupId>
< artifactId> jmxri< / artifactId>
< / exclude>
< / exclusions>
< scope> runtime< / scope>
< / dependency>

<! - @Inject - >
< dependency>
< groupId> javax.inject< / groupId>
< artifactId> javax.inject< / artifactId>
< version> 1< / version>
< / dependency>

<! - Servlet - >
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> servlet-api< / artifactId>
< version> 2.5< / version>
< scope>提供< / scope>
< / dependency>
< dependency>
< groupId> javax.servlet.jsp< / groupId>
< artifactId> jsp-api< / artifactId>
< version> 2.1< / version>
< scope>提供< / scope>
< / dependency>
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> jstl< / artifactId>
< version> 1.2< / version>
< / dependency>

<! - Test - >
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.7< / version>
< scope> test< / scope>
< / dependency>

<! - 为了使jfree图表,iText& Apache POI - >
< dependency>
< groupId> net.sf.jasperreports< / groupId>
< artifactId> jasperreports< / artifactId>
< version> 4.1.2< / version>
< / dependency>

< dependency>
< groupId> org.codehaus.groovy< / groupId>
   artifactId> groovy-all< / artifactId>
< version> 1.5.5< / version>
< / dependency>

<! - Oracle jdbc drivers - >
< dependency>
< groupId> com.oracle< / groupId>
< artifactId> oracle< / artifactId>
< version> 10.2.0.1.0< / version>
< / dependency>

< / dependencies>
< build>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< configuration>
< source> $ {java-version}< / source>
< target> $ {java-version}< / target>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-war-plugin< / artifactId>
< configuration>
< warName> abc< / warName>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-dependency-plugin< / artifactId>
< executions>
< execution>
< id> install< / id>
< phase> install< / phase>
< goal>
< goal> sources< / goal>
< / goal>
< / execution>
< / executions>
< / plugin>
< / plugins>
< / build>



Web.xml

 <?xml version =1.0encoding =UTF-8?& 
< web-app version =2.5xmlns =http://java.sun.com/xml/ns/javaee
xmlns:xsi =http://www.w3。 org / 2001 / XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd>

<! - 所有Servlet和过滤器共享的根弹簧容器的定义 - >
< context-param>
< param-name> contextConfigLocation< / param-name>
< param-value> /WEB-INF/spring/root-context.xml
classpath *:META-INF / spring / applicationContext * .xml
< / param-value>
< / context-param>

<! - 创建所有Servlet和过滤器共享的Spring容器 - >
< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener< / listener-class>
< / listener>

<! - 处理应用程序请求 - >
< servlet>
< servlet-name> appServlet< / servlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet< / servlet-class>
< init-param>
< param-name> contextConfigLocation< / param-name>
< param-value> /WEB-INF/spring/appServlet/servlet-context.xml< / param-value>
< / init-param>
< load-on-startup> 1< / load-on-startup>
< / servlet>

< servlet-mapping>
< servlet-name> appServlet< / servlet-name>
< url-pattern> /< / url-pattern>
< / servlet-mapping>

解决方案>

因此,如果您的DispatcherServlet配置为类似REST的网址格式(例如 / ),则css文件将位于 src / main / webapp / resources



只是为了澄清这是我必须做的:


  1. servlet-context.xml 中,您具有以下内容:

     < resources mapping = / resources / **location =/ resources //> 


  2. 如果在网络应用程序下不存在名为 resources


  3. 参考我的css档案如下:

     < link rel =stylesheethref =<%= request .getContextPath()%> /resources/css/960.css/> 



I am switching to use Maven for my Spring web app projects and I am running into a simple issue. I am not sure where to put the CSS and JS files in the new project structure.

Traditional Web App Structure

In a traditional Java web app structure (In Eclipse, created as a Dynamic Web Project) I put the CSS, Javascript and Images files under the following structure

WebContent
|__css/myStyles.css
|__js/myjs.js
|__images/myImage.gif
|__WEB-INF

Then in my jsp if I want to reference a CSS file I do as follows:

<link rel="stylesheet" href="<%=request.getContextPath()%>/css/myStyles.css">

This works fine.

Maven Web App Structure

In a Maven project I have put the css files in these locations:

First Attempt

Under the webapp folder at the same level as WEB-INF just like in a traditional dynamic web project. But when I do the following

mvn clean tomcat:run

I get the following error from the Spring Framework:

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/appname/css/myStyles.css] in DispatcherServlet

Second Attempt

Placed my css folder under src/main/resources But when I do the following:

mvn clean tomcat:run

I get the following error from the Spring Framework:

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/appname/css/myStyles.css] in DispatcherServlet

Third Attempt

Placed my css folder src/main/resources

Results: Same as above

I am sure it's something simple but I am stuck, maybe I am overlooking something. Thanks in advance

UPDATE: Adding pom.xml to see if it can help troubleshoot the issue:

<?xml version="1.0" encoding="UTF-8"?>
<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.dariopardo</groupId>
<artifactId>jfreechartdemo</artifactId>
<name>abc</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.0.6.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.9</org.aspectj-version>
    <org.slf4j-version>1.5.10</org.slf4j-version>
</properties>
<repositories>
    <repository>
        <id>spring-maven-release</id>
        <name>Spring Maven Release Repository</name>
        <url>http://maven.springframework.org/release</url>
    </repository>
    <repository>
        <id>spring-maven-milestone</id>
        <name>Spring Maven Milestone Repository</name>
        <url>http://maven.springframework.org/milestone</url>
    </repository>
    <repository>
        <id>spring-roo-repository</id>
        <name>Spring Roo Repository</name>
        <url>http://spring-roo-repository.springsource.org/release</url>
    </repository>
    <repository>
        <id>JBoss Repo</id>
        <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
        <name>JBoss Repo</name>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-maven-release</id>
        <name>Spring Maven Release Repository</name>
        <url>http://maven.springframework.org/release</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-maven-milestone</id>
        <name>Spring Maven Milestone Repository</name>
        <url>http://maven.springframework.org/milestone</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-roo-repository</id>
        <name>Spring Roo Repository</name>
        <url>http://spring-roo-repository.springsource.org/release</url>
    </pluginRepository>
</pluginRepositories>
<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework-version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework-version}</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework-version}</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>1.5.4</version>
        <classifier />
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.3</version>
        <classifier />
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-pool</groupId>
                <artifactId>commons-pool</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xerces</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
        <classifier />
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <!-- AspectJ -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>   

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.4.Final</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.4.Final</version>
        <classifier />
        <exclusions>
            <exclusion>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
            </exclusion>
            <exclusion>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.1.0.Final</version>
        <classifier />
        <exclusions>
            <exclusion>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
        <version>2.2</version>
        <classifier />
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
        <classifier />
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
        <scope>runtime</scope>
    </dependency>

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>       

    <!-- To bring jfree chart in, iText & Apache POI -->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>4.1.2</version>
    </dependency> 

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.5.5</version>
    </dependency>

    <!-- Oracle jdbc drivers -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>oracle</artifactId>
        <version>10.2.0.1.0</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <warName>abc</warName>
            </configuration>                            
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>           
    </plugins>
</build>

UPDATE: Adding Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml
                 classpath*:META-INF/spring/applicationContext*.xml                  
    </param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

解决方案

So if you have your DispatcherServlet configured in a REST like URL pattern such as / then css files would go under src/main/webapp/resources

Just to clarify this is what I had to do:

  1. Make sure that in your servlet-context.xml you have as follows:

    <resources mapping="/resources/**" location="/resources/" /> 
    

  2. Create a folder if does not already exist under webapps called resources

  3. Place your css folder along with css files there

  4. Reference my css file as follows:

    <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/960.css"/>
    

这篇关于在Maven网络应用项目中,CSS和JavaScript文件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆