Resolves an issue where Tomcat lost dependent jar packages was released after Gradle generated eclipse support

Source: Internet
Author: User


In a recent project, build your project using Gradle, the next-generation build tool.

A problem was found in use, Gradle. jar files downloaded from the Central Library in other directories in the system, and when you add eclipse support using Gradle Eclipse, the jar files are imported as external dependencies. When Eclipse publishes Web projects to Tomcat, these dependencies are not automatically published.

With eclipse, you can right-click-Propertics-deployment Assembly on the project, add "Java Build Path Entries", add all the dependent jar packages, and publish the externally dependent jar packages automatically when you publish.

However, manually added, is not in line with the requirements of automated construction, open the. classpath file, found that Gradle automatically generated files contain code similar to the following

<ClasspathentrySourcePath= "C:/Documents and settings/xxx/.gradle/caches/artifacts-24/filestore/commons-collections/ Commons-collections/3.2/source/73d0340eaecbb0ec9d3e0ace90547ef08cbfaf27/commons-collections-3.2-sources.jar " Kind= "Lib"Path= "C:/Documents and settings/xxx/.gradle/caches/artifacts-24/filestore/commons-collections/ Commons-collections/3.2/jar/f951934aa5ae5a88d7e6dfaa6d32307d834a88be/commons-collections-3.2.jar "exported= "true" />

After you set up deployment assembly in Eclipse, the code changes to this

<ClasspathentrySourcePath= "C:/Documents and settings/xxx/.gradle/caches/artifacts-24/filestore/commons-collections/ Commons-collections/3.2/source/73d0340eaecbb0ec9d3e0ace90547ef08cbfaf27/commons-collections-3.2-sources.jar " Kind= "Lib"Path= "C:/Documents and settings/xxx/.gradle/caches/artifacts-24/filestore/commons-collections/ Commons-collections/3.2/jar/f951934aa5ae5a88d7e6dfaa6d32307d834a88be/commons-collections-3.2.jar "exported= "true"> <attributes> <attributename= "Org.eclipse.jst.component.dependency"value= "/web-inf/lib" /> </attributes> </Classpathentry>

This is simple, we let gradle automatically add deployment Assembly

Add the following code in the Gradle.build

Automatic generation of deployment Assembly ECLIPSE.CLASSPATH.FILE.WITHXML {def node = It.asnode () when generating eclipse support; For (Node N:node.children ()) {if ("Lib". Equals (N.attribute ("kind"))) {def node_attributes =new Nod             E (n, "attributes");             def map =new HashMap ();             Map.put ("name", "Org.eclipse.jst.component.dependency");             Map.put ("Value", "/web-inf/lib");         def node_attribute =new node (node_attributes, "attribute", map); }     } }

Save later rerun Gradle Eclipse, go back to Eclipse Refresh project, publish project now, can automatically publish all external dependent jar package to Tomcat

Resolves an issue where Tomcat lost dependent jar packages was released after Gradle generated eclipse support

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.