Java Web development: WebJars, Java Web development webjars

Source: Internet
Author: User

Java Web development: WebJars, Java Web development webjars
After changing to a new job, I got a lot of work, basically had no time to access the Internet, and my Blog writing became less. I was still in the technology-driven environment that I used to drive, and everyone was actively learning new technologies, share new technologies. Now there are fewer technical environments and less passion for learning. Don't talk about it. Write your own learning WebJars.
Java Web Front-end usually uses JS or CSS technologies, such as jQuery, Backbone. js, and Twitter Bootstrap. Previously, I copied these Web resources to the corresponding Webapp directory of the Java Web project. This manual copy may produce version errors, copy version errors, and missing copies, the front-end page cannot be correctly displayed. Of course, to some extent, I feel very good that many folders and files have become a jar.
WebJars packages Web Front-end Javascript and CSS resources into Java Jar packages. In this way, we can use Maven to manage these dependent libraries in Java Web development to ensure the uniqueness of these Web resource versions. The basic principles are as follows:With any Servlet 3 compatible container, the WebJars that are in the WEB-INF/lib directory are automatically made available as static resources. This works because anything in a META-INF/resources directory in a JAR in WEB-INF/lib is automatically exposed as a static resource.The following describes how to use WebJars, which is very simple. 1. Define the jar package for js or css in the maven configuration file.

                <dependency>                        <groupId>org.webjars</groupId>                        <artifactId>bootstrap</artifactId>                </dependency>                <dependency>                        <groupId>org.webjars</groupId>                        <artifactId>jquery-cookie</artifactId>                </dependency>                <dependency>                        <groupId>org.webjars</groupId>                        <artifactId>dojo</artifactId>                </dependency>

2. In the jsp file, obtain the file (webjars/js or css jar name/version/detail file name) in the following path)
<script type="text/javascript" src="<%=request.getContextPath() %>/webjars/jquery/1.9.0/jquery.min.js"></script><script type="text/javascript" src="<%=request.getContextPath() %>/webjars/bootstrap/3.0.2/js/bootstrap.min.js"></script> <script type="text/javascript" src="<%=request.getContextPath() %>/webjars/jquery-cookie/1.3.1/jquery.cookie.js"></script>
PS: Processing static resources for large websites is certainly not a Java Server. Basically, apache or nginx is used to process static processing, with better performance. For small websites, you can directly use WebJars.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.