Maven-Building Tools
03:40Show all | Close all
-
Overview
-
What are building tools
There many Java Build tools available for the Java programmers. These tools help the programmer to build their project efficiently. Build process is repetitive process where programmer builds the project again and again to test the changes in the project code. While developing a project code changes needs to be test and the testing requires the build of the code and finally deploying on the server for testing. Build tools automate the repetitive process and allows the programmer to concentrate on the project development. It also reduces the overall build time. Build tools makes the build process just a single click work. Here are the list of build tools available in Java:
Types of building tools
- Ant
- Maven
- Xdoclet
-
why we use building tools
There many Java Build tools available for the Java programmers. These tools help the programmer to build their project efficiently. Build process is repetitive process where programmer builds the project again and again to test the changes in the project code. While developing a project code changes needs to be test and the testing requires the build of the code and finally deploying on the server for testing. Build tools automate the repetitive process and allows the programmer to concentrate on the project development. It also reduces the overall build time. Build tools makes the build process just a single click work. Here are the list of build tools available in Java: -
Types of Building tools
What are testing tools ?
Testing tools are a form of automated testing. It is basically using programs to do different testing tasks i.e. doing the tests through some form of automated method. They are computerized and help in assisting every type of testing. Some of these testing tasks include checking the conditions, also checking the predicted results with the actual results along with many other types of testing involved. A lot of these testing tools have commonly used coding languages such as Java and C. The testing tools themselves have been made using these programming languages. A lot of the tools used have different options available to help with testing. This can be very useful when producing the essential reports of that particular product.
Different Methodologies Used For Testing
There are different methodologies that are can be used when implementing testing tools. The testing methodologies can be used together or individually. It all depends on what you are testing as they provide better resources for different tasks. Below are a few of the main different types that are used but there are other types of testing that can be used:
Unit Testing
This is the software used for verification and validation. It's a method in which the programmer can test all the separate code and see if it is viable to use. This type of testing is based on a small scale and uses small units of the program. When looking at procedural programming the unit can be any individual function or a procedure which is written in the same language as the production code.
White Box Testing
This is also known as clear box testing, glass box testing, translucent box testing or structural testing. It uses the internal perspective of the system and then designs test cases based on this internal structure. Basically the code itself and all the conditions, statements and paths along with it are tested. Programming skills are required for noticing all the paths through the software. White box testing does many things such as analyzing the data flow, control flow, information flow and coding practices.
Regression Testing
This is a type of software testing which basically looks for software regressions. The regressions can happen whenever the software stops working as it is meant to. The testing makes sure that any bugs or changes have been fixed which may have caused previous working functions to have failed as a result of the newly added features. It is better to do this type of testing under the automated tool environment. The regression testing may take place once the programmer has tried to fix a problem or has purposely added in code to give out errors.
Integration Testing
This is where the separate software modules are put together and are then tested as a whole. This normally takes place after unit testing has been done. The point of doing integration testing is because it verifies the functional and performance requirements of the design items. It is component of Extreme Programming (XP). Two different ways of doing integration testing is bottom-up and top-down.
-
-
What is Maven
At first glance Maven can appear to be many things, but in a nutshell Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:
1.Builds
2.Documentation
3.Reporting
4.Dependencies
5.SCMs
6.Releases
7.Distribution
If you want more background information on Maven you can check out The Philosophy of Maven and The History of Maven. Now let's move on to how you, the user, can benefit from using Maven.
Maven is particularly useful because it can automatically manage massive dependency trees, especially transitive dependencies where Plugin X depends on Application Y, which depends on Shared Library Z. Using Maven, you should be able to quickly and easily retrieve all the dependencies that your plugin will need, and create a working development environment in just a few steps. -
Limitations
In order for Maven to find and download all of the necessary dependencies, you need to tell it where everything is stored. This is done via the settings file, settings.xml.
Your plugin will depend on many different artifacts: the Atlassian application itself, Atlassian modules and various open-source libraries. All of those artifacts are stored in different Maven repositories scattered around the net. However, to simplify configuration and speed up downloads, Atlassian provides a Maven proxy that contains all of the dependencies for all of our applications. The example settings file contains just one repository entry for this proxy, and saves Maven from having to check several different repositories for each artifact it needs. You can read more about the repositories that are behind the Maven proxy.
Atlassian will release binary and Javadoc artifacts for all of our product releases and their Atlassian-managed dependencies. We will release source artifacts wherever we can freely do so. Some of our closed-source artifacts will only be available via manual download for source license holders.
We will also release various milestone and snapshot releases during application development, to aid plugin developers in testing their work against upcoming application releases.
You will be able to find all of these artifacts in the Maven proxy. -
Environment and requirement
Maven is Java based tool, so the very first requirement is to have JDK installed in your machine.
System Requirement
JDK 1.5 or above. Memory no minimum requirement. Disk Space no minimum requirement. Operating System no minimum requirement. Step 1 - verify Java installation in your machine
Now open console and execute the following java command.
OS Task Command Windows Open Command Console c:\> java -version Linux Open Command Terminal $ java -version Mac Open Terminal machine:~ joseph$ java -version
OS Output Windows java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)Linux java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)Mac java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)
Step 2: Set JAVA environment
Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example
OS Output Windows Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_21 Linux export JAVA_HOME=/usr/local/java-current Mac export JAVA_HOME=/Library/Java/Home
OS Output Windows Append the string ;C:\Program Files\Java\jdk1.6.0_21\bin to the end of the system variable, Path. Linux export PATH=$PATH:$JAVA_HOME/bin/ Mac not required
Step 3: Download Maven archive
Download Maven 2.2.1 from http://maven.apache.org/download.html
OS Archive name Windows apache-maven-2.0.11-bin.zip Linux apache-maven-2.0.11-bin.tar.gz Mac apache-maven-2.0.11-bin.tar.gz Step 4: Extract the Maven archive
Extract the archive, to the directory you wish to install Maven 2.2.1. The subdirectory apache-maven-2.2.1 will be created from the archive.
OS Location (can be different based on your installation) Windows C:\Program Files\Apache Software Foundation\apache-maven-2.2.1 Linux /usr/local/apache-maven Mac /usr/local/apache-maven Step 5: Set Maven environment variables
Add M2_HOME, M2, MAVEN_OPTS to environment variables.
OS Output Windows Set the environment variables using system properties.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512mLinux Open command terminal and set environment variables.
export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export M2=%M2_HOME%\bin
export MAVEN_OPTS=-Xms256m -Xmx512mMac Open command terminal and set environment variables.
export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export M2=%M2_HOME%\bin
export MAVEN_OPTS=-Xms256m -Xmx512mStep 6: Add Maven bin directory location to system path
Now append M2 variable to System Path
OS Output Windows Append the string ;%M2% to the end of the system variable, Path. Linux export PATH=$M2:$PATH Mac export PATH=$M2:$PATH Step 8: Verify Maven installation
Now open console, execute the following mvn command.
OS Task Command Windows Open Command Console c:\> mvn --version Linux Open Command Terminal $ mvn --version Mac Open Terminal machine:~ joseph$ mvn --version
OS Output Windows Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jreLinux Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jreMac Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre
-
Installation steps for Maven
Maven in 5 Minutes
Prerequisites
You must have an understanding of how to install software on your computer. If you do not know how to do this, please ask someone at your office, school, etc or pay someone to explain this to you. The Maven mailing lists are not the best place to ask for this advice.Installation
Maven is a Java tool, so you must have Java installed in order to proceed.
First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100) Maven home: D:\apache-maven-3.0.3\bin\.. Java version: 1.6.0_25, vendor: Sun Microsystems Inc. Java home: E:\Program Files\Java\jdk1.6.0_25\jre Default locale: nl_NL, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
If you are using Windows, you should look at Windows Prerequisites to ensure that you are prepared to use Maven on Windows.Creating a Project
You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
cd my-app
my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java
The POM
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies> </project>
What did I just do?
You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items".Build the Project
mvn package
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Thu Jul 07 21:34:52 CEST 2011 [INFO] Final Memory: 3M/6M [INFO] ------------------------------------------------------------------------
- validate
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Hello World!
-
Install maven in eclispe IDE
Eclipse provides an excellent plugin m2eclipse which seamlessly integrates Maven and Eclipse together.
Some of features of m2eclipse are listed below
- You can run Maven goals from Eclipse.
- You can view the output of Maven commands inside the Eclipse using its own console.
- You can update maven dependencies with IDE.
- You can Launch Maven builds from within Eclipse.
- It does the dependency management for Eclipse build path based on Maven's pom.xml.
- It resolves Maven dependencies from the Eclipse workspace without installing to local Maven repository (requires dependency project be in same workspace).
- It automatic downloads required dependencies and sources from the remote Maven repositories.
- It provides wizards for creating new Maven projects, pom.xml and to enable Maven support on existing projects
- It provides quick search for dependencies in remote Maven repositories
Installing m2eclipse plugin
Use one of the following links to install m2eclipse:
Eclipse URL Eclipse 3.5 (Gallileo) Installing m2eclipse in Eclipse 3.5 (Gallileo) Eclipse 3.6 (Helios) Installing m2eclipse in Eclipse 3.6 (Helios)
Import a maven project in Eclipse
- Open Eclipse.
- Select File > Import > option.
- Select Maven Projects Option. Click on Next Button.
- Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
- Click Finish Button.
Now, you can see the maven project in eclipse.
Now, have a look at consumerBanking project properties.You can see that Eclipse has added Maven dependencies to java build path.
Now, Its time to build this project using maven capability of eclipse.
- Right Click on consumerBanking project to open context menu.
- Select Run as option
- Then maven package option
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------- [INFO] Building consumerBanking [INFO] [INFO] Id: com.companyname.bank:consumerBanking:jar:1.0-SNAPSHOT [INFO] task-segment: [package] [INFO] ------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Nothing to compile - all classes are up to date [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Nothing to compile - all classes are up to date [INFO] [surefire:test] [INFO] Surefire report directory: C:\MVN\consumerBanking\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.companyname.bank.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] ------------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------- [INFO] Total time: 1 second [INFO] Finished at: Thu Jul 12 18:18:24 IST 2012 [INFO] Final Memory: 2M/15M [INFO] -------------------------------------------------------------------
Now, right click on App.java. Select Run As option. Select As Java Application.
You will see the result
Hello World!
-
Install maven plugin in Netbeans
NetBeans 6.7 and newer has inbuild support for Maven. In case of previous version, Maven plugin is available in plugin Manager. We're using NetBeans 6.9 in this example.
Some of features of NetBeans are listed below
- You can run Maven goals from NetBeans.
- You can can view the output of Maven commands inside the NetBeans using its own console.
- You can update maven dependencies with IDE.
- You can Launch Maven builds from within NetBeans.
- NetBeans does the dependency management automatically based on Maven's pom.xml.
- NetBeans resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
- NetBeans automatic downloads required dependencies and sources from the remote Maven repositories.
- NetBeans provides wizards for creating new Maven projects, pom.xml
- NetBeans provides a Maven Repository browser that enables you to view your local repository and registered external Maven repositories.
Open a maven project in NetBeans
- Open NetBeans.
- Select File Menu > Open Project option.
- Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
Now, you can see the maven project in NetBeans.Have a look at consumerBanking project Libraries and Test Libraries.You can see that NetBeans has added Maven dependencies to its build path.
Build a maven project in NetBeans
Now, Its time to build this project using maven capability of NetBeans.
- Right Click on consumerBanking project to open context menu.
- Select Clean and Build as option
Maven will start building the project. You can see the output in NetBeans Console
NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install' NetBeans: JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21 Scanning for projects... ------------------------------------------------------------------------ Building consumerBanking task-segment: [clean, install] ------------------------------------------------------------------------ [clean:clean] [resources:resources] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources [compiler:compile] Compiling 2 source files to C:\MVN\consumerBanking\target\classes [resources:testResources] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources [compiler:testCompile] Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes [surefire:test] Surefire report directory: C:\MVN\consumerBanking\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.companyname.bank.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [jar:jar] Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar [install:install] Installing C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar to C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\ 1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------ Total time: 9 seconds Finished at: Thu Jul 19 12:57:28 IST 2012 Final Memory: 16M/85M ------------------------------------------------------------------------
Run Application in NetBeans
Now, right click on App.java. Select Run File As option. You will see the result in NetBeans Console.
NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime -Dexec.args=-classpath %classpath com.companyname.bank.App -Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe -Dnetbeans.execution=true process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec' NetBeans: JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21 Scanning for projects... ------------------------------------------------------------------------ Building consumerBanking task-segment: [process-classes, org.codehaus.mojo:exec-maven-plugin:1.1.1:exec] ------------------------------------------------------------------------ [resources:resources] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources [compiler:compile] Nothing to compile - all classes are up to date [exec:exec] Hello World! ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------ Total time: 1 second Finished at: Thu Jul 19 14:18:13 IST 2012 Final Memory: 7M/64M ------------------------------------------------------------------------
-
Install maven plugin in IntelliJ IDEA
IntelliJ IDEA has inbuild support for Maven. We're using IntelliJ IDEA Community Edition 11.1 in this example.
Some of features of IntelliJ IDEA are listed below
- You can run Maven goals from IntelliJ IDEA.
- You can can view the output of Maven commands inside the IntelliJ IDEA using its own console.
- You can update maven dependencies within IDE.
- You can Launch Maven builds from within IntelliJ IDEA.
- IntelliJ IDEA does the dependency management automatically based on Maven's pom.xml.
- IntelliJ IDEA resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in same workspace).
- IntelliJ IDEA automatic downloads required dependencies and sources from the remote Maven repositories.
- IntelliJ IDEA provides wizards for creating new Maven projects, pom.xml
Create a new project in IntelliJ IDEA
We'll import Maven project using New Project Wizard.
- Open IntelliJ IDEA.
- Select File Menu > New Project Option.
- Select import project from existing model.
- Select Maven option
- Select Project location, where a project was created using Maven. We've create a Java Project consumerBanking.See Maven Creating Project to see how to create a project using Maven.
- Select Maven project to import.
- Enter name of the project and click finish.
Now, you can see the maven project in IntelliJ IDEA.Have a look at consumerBanking project external libraries.You can see that IntelliJ IDEA has added Maven dependencies to its build path under Maven section.
Build a maven project in IntelliJ IDEA
Now, Its time to build this project using capability of IntelliJ IDEA.
- Select consumerBanking project.
- Select Buid menu > Rebuild Project Option
4:01:56 PM Compilation completed successfully
Run Application in IntelliJ IDEA
- Select consumerBanking project.
- Right click on App.java to open context menu.
- select Run App.main()
You will see the result in IntelliJ IDEA Console.
"C:\Program Files\Java\jdk1.6.0_21\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path= C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.6.0_21\jre\lib\charsets.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar; C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar C:\MVN\consumerBanking\target\classes; C:\Program Files\JetBrains\ IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.companyname.bank.App Hello World! Process finished with exit code 0
-
Download Maven
Cilck here to download from Official website
0 comments: