IntelliJ IDEA: Webjars / Maven / Spring MVC - How to correctly import dependencies and have them work?

有些话、适合烂在心里 提交于 2019-12-23 12:38:53

问题


So I'm beginning Java Web development and I'd just like to have some libraries imported to my IntelliJ project correctly through use of Maven. I've stumbled upon making use of Webjars in order to import bootstrap and jquery, but I am having a great deal of trouble getting anything to work correctly. Wondering if someone could help out? Any suggestions are appreciated.

My project currently has Maven and Spring MVC as supported frameworks. My pom.xml:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>JavaEEHelloWorld</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>LATEST</version>
            <exclusions>
                <exclusion>
                    <groupId>org.webjars</groupId>
                    <artifactId>jquery</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>LATEST</version>
        </dependency>
    </dependencies>

</project>

My spring-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

</beans>

My index.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Awesome site.</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.5/css/bootstrap.min.css"/>
    <script src="/webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="/webjars/jquery/3.0.0-alpha1/jquery.min.js"></script>
</head>
<body>
Hello World!
</body>
</html>

If I try adding the following line to my spring-config.xml, I get this error:

More screenshots:

My project explorer which for some reason never created subdirectories for bootstrap or jquery:

The errors I'm seeing at runtime:

来源:https://stackoverflow.com/questions/31663149/intellij-idea-webjars-maven-spring-mvc-how-to-correctly-import-dependenci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!