Magazine
 
Eclipse IDE
 

Upon executing this command you should see output like the following:

C:\maventest\HelloMaven>mvn compile [INFO] Scanning for
projects...[INFO]
-----------------------------------------------------------------------------------------
[INFO] Building HelloMaven[INFO] task-segment:
[compile][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]
-----------------------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL[INFO]
-----------------------------------------------------------------------------------------
[INFO] Total time: 1 second[INFO] Finished at: Sat Jul 21
17:33:27 GMT+05:30 2007[INFO] Final Memory: 2M/5M[INFO]
-----------------------------------------------------------------------------------------

The first time you execute this command, Maven will
download all the plugins and related dependencies it
requires to fulfill the command. From a clean installation
of Maven this can take quite a while (in the output above,
it took almost 4 minutes).

If you execute this command again, Maven will now have what it needs, so it won’t need to download anything new and will be able to execute the command much more quickly.

As you can see from the output, the compiled classes were
placed in ${basedir}/target/classes, which is another standard
convention employed by Maven. So, if you’re a keen observer,
you’ll notice that by using the standard conventions the POM
above is very small and you haven’t had to tell Maven explicitly where any of your sources are or where the output should go.

5. To compile your test sources and run your unit tests. Now
you’ve got some unit tests that you want to compile and
execute.
Execute the following command:

C:\maventest\HelloMaven>mvn test
C:\maventest\HelloMaven>mvn test[INFO]
Scanning for projects...[INFO]
-----------------------------------------------------------------------------------------
[INFO] Building HelloMaven[INFO] task-segment: [test][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:\maventest\HelloMaven\target\surefire-reports

 

-------------------------------------------------------------------------------
T E S T S
-------------------------------------------------------------------------------
[surefire] Running
net.roseindia.maven.quickstart.TestCalculator[surefire] Tests
run: 1, Failures: 0, Errors: 0, Time elapsed: 0.001 sec Results
:[surefire] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[INFO]
-------------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL[INFO][INFO] Total time: 2
seconds[INFO] Finished at: Sat Jul 21 11:34:53 GMT+05:30
2007[INFO] Final Memory: 3M/7M[INFO]
------------------------------------------------------------------------------

6. Now you need to create a jar. Making a JAR file is straight
forward.Just execute the following command:

C:\maventest\HelloMaven>mvn package

7. Now to install the artifact you’ve generated (the JAR file) in your local repository (~/.m2/repository is the default location). If you take a look at the POM for your project you will notice the packaging element is set to jar. This is how Maven knows to produce a JAR file from the above command. You can now take a look in the ${basedir}/target directory and you will see the generated JAR file. Let’s move on to installing our artifact. To do so execute the following command:

C:\maventest\HelloMaven>mvn install

We will dig Maven 2 deeper, in our forth coming issues…

 

August 2007 | Java Jazz Up | 21
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40           Download PDF