------ Guide to Using Maven 2 in NetBeans 4.0 (4.1 and 5.0) ------ Raphaël Piéroni ------ 2005-08-09 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Using Maven 2 in NetBeans 4.0 (4.1 and 5.0) This mini guide explain by examples how to use Maven 2 in NetBeans IDE. To use Maven 2 in NetBeans you have to follow these steps: * {{{RetreiveCreate_the_Maven_2_project}Retrieve/Create the Maven 2 project.}} * {{{Launch_Maven_2_in_command_line_using_the_netbeans-freeform_plugin}Launch Maven 2 in command line using the netbeans-freeform plugin.}} * {{{Open_the_project_with_NetBeans}Open the project with NetBeans.}} * {{{Build_the_project_and_launch_other_Maven_goals}Build the project and launch other Maven goals.}} * {{{Edit_properties_of_the_plugin}Edit properties of the plugin.}} * {{{Refresh_the_project_view}Refresh the project view.}} * {{{Build_the_Maven_2_site}Build the Maven 2 site.}} * {Retrieve/Create the Maven 2 project} This guide assume the project is created using the archetype plugin. You can also checkout the Maven 2 project using your versionning system. ------------------- [maven-user@mini-guide examples]$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DartifactId=demoquickstart -DgroupId=demoquickstart [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ---------------------------------------------------------------------------- [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ---------------------------------------------------------------------------- [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] ************************************************************** [INFO] Starting Jakarta Velocity v1.4 [INFO] RuntimeInstance initializing. [INFO] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties [INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl) [INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader [INFO] ClasspathResourceLoader : initialization starting. [INFO] ClasspathResourceLoader : initialization complete. [INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl) [INFO] Default ResourceManager initialization complete. [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach [INFO] Created: 20 parsers. [INFO] Velocimacro : initialization starting. [INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm [ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader. [INFO] Velocimacro : error using VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm' [INFO] Velocimacro : VM library template macro registration complete. [INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates [INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions [INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed. [INFO] Velocimacro : messages on : VM system will output logging messages [INFO] Velocimacro : autoload off : VM system will not automatically reload global library macros [INFO] Velocimacro : initialization complete. [INFO] Velocity successfully started. [INFO] [archetype:generate] [INFO] Defaulting package to group ID: demoquickstart [INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating Archetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: demoquickstart [INFO] Parameter: outputDirectory, Value: /demos/demoquickstart [INFO] Parameter: packageName, Value: demoquickstart [INFO] Parameter: package, Value: demoquickstart [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: artifactId, Value: demoquickstart [INFO] ResourceManager : found archetype-resources/pom.xml with loader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader [INFO] ResourceManager : found archetype-resources/src/main/java/App.java with loader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader [INFO] ResourceManager : found archetype-resources/src/test/java/AppTest.java with loader org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader [INFO] Archetype created in dir: /demos/demoquickstart [INFO] ---------------------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ---------------------------------------------------------------------------- [INFO] Total time: 2 seconds [INFO] Finished at: Tue Oct 11 21:59:22 CEST 2005 [INFO] Final Memory: 3M/7M [INFO] ---------------------------------------------------------------------------- ------------------- * {Launch Maven 2 in command line using the netbeans-freeform plugin} After having retrieved the Maven 2 project, you have to enable the project to be seen as a NetBeans 4.0, 4.1 or 5.0 project using the NetBeans Freeform project type. To enable the project, use the netbeans-freeform plugin for Maven 2. ------------------- [maven-user@mini-guide demoquickstart]$ mvn netbeans-freeform:generate-netbeans-project [INFO] Searching repository for plugin with prefix: 'netbeans-freeform'. [INFO] ---------------------------------------------------------------------------- [INFO] Building Maven Quick Start Archetype [INFO] task-segment: [netbeans-freeform:generate-netbeans-project] [INFO] ---------------------------------------------------------------------------- [INFO] Preparing netbeans-freeform:generate-netbeans-project [INFO] [netbeans-freeform:generate-netbeans-project] [INFO] JarAnalyser found [INFO] The project 'Maven Quick Start Archetype' is analysed. [INFO] The file 'nbproject/project.xml' is created. [INFO] The file 'nbproject/mavencall.xml' is created. [INFO] The file 'nbproject/project.properties' is created. [INFO] ---------------------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ---------------------------------------------------------------------------- [INFO] Total time: < 1 second [INFO] Finished at: Tue Oct 11 22:12:30 CEST 2005 [INFO] Final Memory: 1M/3M [INFO] ---------------------------------------------------------------------------- ------------------- The netbeans-freeform plugin creates one directory and three files by reading the Maven 2 project descriptor: * The <<>> directory holds the NetBeans project descriptor. * The <<<>> file is the NetBeans Freeform project descriptor. * The <<>> holds the Ant calls which execute Maven 2, as NetBeans uses Ant as its build tool. * The <<>> files holds the two properties: <<>> which is the absolute path to the Maven 2 local repository and <<>> which is the absolute path to the project directory. * {Open the project with NetBeans} Now that the Maven 2 project is eneabled for use in NetBeans, open your NetBeans IDE. Then open the project (Ctrl+Maj+O). Here is the window. [Open_Project.png] Open Project And here are: The with the opened project. [Project_Opened.png] Project Opened The project's of the opened project. [Context_Menu.png] Context Menu And the with the opened project. [Window_Files.png] Files Window * {Build the project and launch other Maven goals} It is now time to try the first execution of Maven 2 from within NetBeans. Try the NetBeans action (F11). You see the Maven 2 execution of the <<>> lifecycle goal. [Run_Build_Main_Project.png] Run Build Main Project You can also call the NetBeans action which is mapped to the <<>> Maven2 goal. [Run_Clean_Main_Project.png] Run Clean Main Project * {Edit properties of the plugin} Now you can add some additionnal views in your window in NetBeans. Like an additionnal goal in the context menu. ------------------- 4.0.0 demoquickstart demoquickstart jar 1.0-SNAPSHOT Maven Quick Start Archetype http://maven.apache.org junit junit 3.8.1 test org.codehaus.mojo netbeans-freeform-maven-plugin 2.0 source:jar ------------------- You can also configure some additionnal files and folders in the window. The last option is to create the <<>> folder and its content in another directory than in the Maven 2 project's one. The full configuration can be found at {{http://mojo.codehaus.org/netbeans-freeform-maven-plugin/}}. * {Refresh the project view} To refresh the Project view in NetBeans accordingly to the new configuration added to the Maven 2 project descriptor. Just right-clic the project in the Projects window and choose the action. [Refresh_Project.png] Refresh Project Here is the resulting refreshed Context Menu. [Refreshed_Context_Menu.png] Refreshed Context Menu * {Build the Maven 2 site} You can call The NetBeans action which is mapped to the <<>> Maven 2 goal, here in the Maven site archetype. [Generate_Site.png] Generate Site