Translation: Apache Maven - Simplified Java Construction Process - More than Apache Ant (1) Unfinished

xiaoxiao2021-03-06  39

Original: Apache Maven Simplifies The Java Build Process-Even More Ant http://www.devx.com/java/Article/17204apache Maven, a substitute for buildings based on Java-based Apache Ant. Commitment to eliminate complication Construction scripts debate. This new tool can automate the Java build process. Give Maven some information about the directory structure of the directory structure to handle the remaining. All required build items have been built in Maven. Change Say, for a standard building process, you don't have to create a custom build script. In this article, I will explain what is Maven and it will solve something. Then I will take you to automate your own build process with MAVEN. In the most popular build tool ANT in Java, this file assumes that the reader has the basic understanding of Ant. The build process enables daily task automation as a programmer, the time of the spending time is automating other tasks, IDE automation us Some work, but many developers have to use external tools to complete special tasks: build process. The concept of build has been developed for many years, but now build tools only provide some developers to develop, compile, test, and Automation of the deployment. For my job, I barely use the multi-purpose Ant allows you to customize the task, it can be reused across items. This may make the reason why Ant success, but even if there is a reusable task, you still want to my work, I am grudgingly using a general-purpose, scripting language more and more with the build tool-not unlike the macro languages ​​built into IDEs. Table 1 shows a few of the build functions that I perform daily. Table 1. Daily Build Functions I PerformCompile Run Jikes or Javac Copy Resource Files Into The Classes Directory Clean Delete The Classes Directory So That Our Next Co mpile will be a clean compileDelete any temporary, app-server-generated filesRecreate the classes directory Jar Zip up a project in to a .jar file Javadoc Generate documentation from source code Test Use JUnit to run the project's unit tests Deploy Copy runtime files to a Staging Server Kodo Run Kodo's JDO BYTE-CODE ENHANCER (Kodo Is A JDO Implement That Post-Processes Class Files To Make THEM PERSISTENCE-CAPABLE.)

Move Over Ant, Maven Is HereWhen I first started using Ant to automate the above-mentioned tasks, it was a big timesaver. Especially once I learned to use and create custom Ant Tasks. But that was for individual, fairly simple projects. I now use Ant to automate build tasks for multiple, complex projects. A considerable part of my day is spent creating and maintaining complex Ant scripts. Over time, maintaining these scripts became a major thorn in my side.Specifically, the following Ant limitations led me to start looking for a new build tool:. Cross-project reuse My 10 Ant build scripts are mostly the same So I started looking for code reuse features in Ant As it turns out, Ant has no convenient way to reuse targets across projects... Copy-and-paste is the only choice.Cross-developer reuse. Most of my Ant scripts are complex but not particularly unique to my project. In other words, since most of my build scripts perform the same functions as other people's build scripts, Why Should I have to create a build script at all-other than for project-specific functionality? Logic and looping. As mentioned previously, I now use Ant for general-purpose scripting. Therefore, I need general-purpose scripting features, like conditional logic, looping constructs, and reuse mechanisms. Ant was never meant to be a general-purpose scripting tool, however. As such, although via possible the Script Task or a custom Task, adding conditional logic and looping to the Ant build process is awkward.

To be fair, Ant does allow you to create custom Tasks, which are reusable across projects. These are a great help and probably are the reason for Ant's success. However, even with reusable Tasks, you still end up with numerous, mostly redundant Targets in each project. If your objective is to simplify or eliminate the build script, you need something more. you need reusable Target Libraries. That's where Maven comes in.Maven addresses these issues. With this new tool, targets (which Maven calls goals) are reusable (See the sidebar "Maven Term and Concept Summary" for a complete listing of Maven terminology.). In fact, for the most common tasks, Maven has already created the goals. This means you do not have to create them yourself For Simple Projects, You May Not NEED A Build File At All. (See The Sidebar "Maven Versus Ant" for a Comparrative Analysis of antid and maven.)

Maven POM = Goals AchievedTo achieve its magic, Maven uses a Project Object Model (POM), which describes a project in the form of an XML file, project.xml. Specifically, it describes the project's directory structure, its jar file dependencies, and some of its project management details. Think of the POM as project meta-data. Once you describe your project to Maven by creating the POM, you can invoke any of Maven's built-in goals (remember, a goal is like an Ant target ).

转载请注明原文地址:https://www.9cbs.com/read-54034.html

New Post(0)