How to encapsulate a custom label into a jar package

Source: Internet
Author: User
Tags tld

When we develop custom tags in a Web application, these custom tags usually have the tag processor Java class, and a description of these tag TLD files, if we want to be able to use these tags in other Web projects later, you can encapsulate these custom tags in a jar package, Just like the JSTL tag library.

We are now ready to encapsulate the custom tags developed in the Web application into jar packages, which are two files of these custom labels as shown in:

To encapsulate a special jar, we need to build another Java project, note that Java Engineering, not web engineering, where the Java project is named "Simpletag", and then in the project's "src" directory, Copy the package and the Java file into the new Java project, and we'll see that the copied Java file will get an error:

  

The reason for the error is that the original tag was created in the Web project, the use of the Java EE API, for example, we use the simple tag processor class to inherit the Simpletagsupport class, and this Simpletagsupport class is the JSP API class, belongs to the category of the Java EE. Our common Java project does not use the library of the EE. But it doesn't matter, because we've already used validation in the original Web project and that's no mistake.

Then we must also copy the TLD file into the Java project. This TLD file requires a new directory in the Java project now, typically "Meta-inf", and then placing the TLD file in:

  

This will enable us to export the project into a jar package, right click on the project, select "Export ...", Pop-up window:

  

Here we select "JAR file" and then choose Next:

  

". Classpath" and ". Project" two hooks are removed, because the two options of the file we do not need, and then select the next to save the path and name of the jar package, so far, directly click "Finish" to complete the custom label packaged into a jar package, In a future Web project, if you need to import the jar package only, and import the taglib directive into the JSP page, you can use the custom label in the jar package.

How to encapsulate a custom label into a jar package

Related Article

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.