Maven Developers Notebook

From HaFrWiki
Jump to: navigation, search

The following is based on the book Maven Developer's Notebook. First of all Install maven 1.0.2.

Application Generation Plugin

  1. Create a directory to house the generated skeleton. (C:\dev\mavenbook\code\genapp\test-application).
  2. Goto the directory
    cd C:\dev\mavenbook\code\genapp\test-application
  3. Execute:
    maven genapp

The screen will show:

 __  _
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

Plugin cache will be regenerated
Directory C:\Maven\maven-1.0.2\.maven\repository does not exist. Attempting to create.
Attempting to download commons-jelly-tags-interaction-20030211.143817.jar.
4K downloaded
Enter a project template to use: [default]

[Enter]

Please specify an id for your application:  [app]

test-application

Please specify a name for your application:  [Example Application]

Test Application

Please specify the package for your application:  [example.app]

mdn.testapp

build:start:

genapp:
    [copy] Copying 1 file to C:\dev\mavenbook\code\genapp\test-application\src\java\mdn\testapp
    [copy] Copying 3 files to C:\dev\mavenbook\code\genapp\test-application\src\test\mdn\testapp
    [copy] Copying 1 file to C:\dev\mavenbook\code\genapp\test-application
    [copy] Copying 2 files to C:\dev\mavenbook\code\genapp\test-application
BUILD SUCCESSFUL
Total time: 1 minutes 36 seconds
Finished at: Tue Nov 07 19:54:43 CET 2006

Helas the genapp option is not available in maven 2.0.4. Has to be figured out.

Create a Jar

To create a jar run
maven jar

 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

Attempting to download dom4j-1.4-dev-8.jar.
475K downloaded
Attempting to download commons-jelly-20030902.160215.jar.
150K downloaded
Attempting to download commons-jelly-tags-jsl-20030211.143151.jar.
14K downloaded
Attempting to download commons-jelly-tags-log-20030211.142821.jar.
8K downloaded
Attempting to download commons-jelly-tags-velocity-20030303.205659.jar.
7K downloaded
Attempting to download commons-jelly-tags-xml-20040613.030723.jar.
33K downloaded
Attempting to download commons-logging-1.0.3.jar.
30K downloaded
Attempting to download velocity-1.4-dev.jar.
505K downloaded
Attempting to download velocity-dvsl-0.45.jar.
25K downloaded
Attempting to download xml-apis-1.0.b2.jar.
106K downloaded
Attempting to download isorelax-20030108.jar.
188K downloaded
Attempting to download jing-20030619.jar.
475K downloaded
Attempting to download xerces-2.4.0.jar.
874K downloaded
Attempting to download commons-io-20030203.000550.jar.
59K downloaded
Attempting to download commons-net-1.1.0.jar.
139K downloaded
Attempting to download commons-httpclient-2.0.jar.
217K downloaded
Attempting to download commons-lang-2.0.jar.
165K downloaded
Attempting to download jsch-0.1.5.jar.
79K downloaded
Attempting to download junit-3.8.1.jar.
118K downloaded
Attempting to download commons-jelly-tags-antlr-20030211.143720.jar.
7K downloaded
Attempting to download antlr-2.7.2.jar.
349K downloaded
build:start:

java:prepare-filesystem:
    [mkdir] Created dir: C:\dev\mavenbook\code\genapp\test-application\target\classes

java:compile:
    [echo] Compiling to C:\dev\mavenbook\code\genapp\test-application/target/classes
    [echo]
==========================================================

  NOTE: Targetting JVM 1.5, classes
  will not run on earlier JVMs

==========================================================

    [javac] Compiling 1 source file to C:\dev\mavenbook\code\genapp\test-application\target\classes

java:jar-resources:
Copying 1 file to C:\dev\mavenbook\code\genapp\test-application\target\classes

test:prepare-filesystem:
    [mkdir] Created dir: C:\dev\mavenbook\code\genapp\test-application\target\test-classes
    [mkdir] Created dir: C:\dev\mavenbook\code\genapp\test-application\target\test-reports

test:test-resources:

test:compile:
    [javac] Compiling 3 source files to C:\dev\mavenbook\code\genapp\test-application\target\test-classes

test:test:
    [junit] Running mdn.testapp.AppTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.016 sec

jar:jar:
    [jar] Building jar: C:\dev\mavenbook\code\genapp\test-application\target\test-application-1.0.jar
BUILD SUCCESSFUL
Total time: 46 seconds
Finished at: Tue Nov 07 20:30:41 CET 2006

This went to fast?
maven clean

Eclipse

Maven as plugins for Eclipse, JBuilder, JDeveloper adn Emacs. Here is an example using Eclipse. First run maven eclipse. This will give:

 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

build:start:

eclipse:generate-project:
    [echo] Creating C:\dev\testappl/.project ...

eclipse:generate-classpath:
    [echo] Creating C:\dev\testappl/.classpath ...
    [echo] Contains JUnit tests
    [echo] Setting compile of src/test to target/test-classes
Plugin 'cactus-maven' in project 'Test Application' is not available
    [echo] Setting default output directory to target/classes

eclipse:
    [echo] Now refresh your project in Eclipse (right click on the project and select "Refresh")
BUILD SUCCESSFUL
Total time: 2 seconds
Finished at: Wed Nov 08 14:48:29 CET 2006

Maven creates 2 files which identify this project as an Eclipse project: .project and .classpath. In Eclipse import this project by following these steps:

  1. Start Eclipse
  2. Select  File  »  Import...  from the menu.
  3. Select  Existing Project  into the workspace click on the  Next .
  4. Select the desired directory and click the  Finish .

Now Eclipse needs to be pointed to the Maven Repository. Set the MAVEN_REPO by using Maven:
maven -Dmaven.eclipse.workspace=DirectoryPathWorkspace eclipse:add-maven-repo
Or manually by following the steps:

  1. Open Eclipse  Windows  »  preferences .
  2. Select  Java  »  Build Path  »  ClassPath Variables .
  3. Create a new classpath variable and name it MAVEN_REPO.
  4. Select the  Folder  and select the Maven repository.