Beginner maven (4)-implementing non-standard packaging with Maven ant task

Source: Internet
Author: User
Tags config pack

MAVEN is powerful, but there are always things that don't work as well as the sense of fluency that you can do without using ant. Especially when it comes to packaging a special (relative to Maven's standard architecture), it often feels overwhelmed. Of course, this should not be related to their understanding of Maven, after all, "beginner maven".

But Maven is so powerful in dependency management that it's totally impossible to go back to the original Ant method, and I think people who have used maven don't usually get back to checkin/checkout N jar packs in Cvs,subversion. That's one reason enough to stick with Maven.

But Ant's agility is hard to forget, especially from Ant's Build.xml, who always comes to think of Ant's goodness. I want both the fish and the bear's paw. Recently want to pack a Java application, very simple but that is not the standard EE appication is not a Web application, with Maven completely do not know how to pack, package out of the completely not what I want, on the internet around Google When MAVEN data is available, it always has the urge to go back to ant.

Let me give you a background, I want to pack the procedure, is this appearance:

demo1
   |____lib
   |_____demo1.jar
   |_____*****.jar
   |_____*****.jar
   |____config
   |_____*****.properties
   |_____*****.xml
   |____log
   |_____*****.log
   |____run.bat
   |____run.sh

This application packaging mode is very simple, a bat or SH script to execute, Lib directory to store all the jar packages, including their own source code compiled packaged jar and Third-party packages. Config file, these files need to be installed or before the operation to modify, such as listening to the port Ah, database information and so on. Log files are stored in the logs directory. The final packaged product is a ZIP package (or tar,tar.gz).

The problem is that the MAVEN standard package does not consider a similar situation at all, and what Jar,ear,war does not apply at all. and maven Some of the ideas are also surprised, such as the Maven Standard config directory is src/main/config, but the directory inside the configuration file by default will be packaged into the jar bag, Halo, all in the jar inside also let people how to change ah?

In the spirit of trying to use only maven without ant, I looked at Maven's data for a long time and didn't find a solution. Halo, do we all only pack standard Ear,jar,war, only I such a boring person will have this packaging needs?

After searching and exploring, it turns out that maven ant tasks seems like a good choice. With Mavenanttasks's official documents and several articles Google has found, start experimenting and successfully implement functionality. Now share the process and method to everyone.

First set up Java Project Anttaskdemo1, as recommended by MAVEN, the file structure is as follows:

anttaskdemo1
   |____src/main/java
   |____src/main/config
   |____src/main/bin
   |____src/main/resources
   |____src/test/java
   |____src/test/resources
   |____target
   |____build.properties
   |____build.xml
   |____pom.xml

Where Src/main/java the Java code, src/main/resources a *.properties file, the resource file is packaged into a jar, the contents of the package does not need to change after packaging. Src/main/config a standard log4j.xml, which is required to be temporarily modified before the installation runs. Src/main/bin to place the executable file.

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.