Converting a Netbeans Project to a Maven Support Project

How can I convert a project created by Netbeans to accept Maven configuration? There are options for creating Maven-based projects, but there is nothing (that I have found so far) to add Maven dependencies to existing projects.

+72
maven netbeans
Mar 31 '11 at 4:02
source share
5 answers

You need to create a separate Maven project. You can then copy the code from another project to the Maven project. This can be done from the Projects windows in NetBeans.

Just select the code files / packages in the tree, right-click to copy and paste them into the source packages of the new Maven project.

Then open the files that Maven will not compile because they skip the dependencies. A yellow light to the left of the problem line will give you options for finding missing dependencies and adding them to your project. You must be online to search.

You can also add maven dependencies manually in your new Maven project by right-clicking the dependency folder in Projects windows.

+59
Aug 04 2018-11-11T00:
source share

If you are familiar with maven, then you can always configure maven even later on, but this is not recommended.

the only reason people (including me;)) recommend creating a new maven project, Maven has its own directory structure. And this is standard. now if you want to enable maven for your project at a later stage than you can configure things in pom.xml, i.e. your source directory, destination directory, and web application directory (if applicable)

I had a large project in SVN, and I was forbidden to create a new project. I did not want to support lib management, so I configured maven according to my directory structure.

here is part of my pom.xml

<build> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>testpackages</testSourceDirectory> <testOutputDirectory>target/test-classes</testOutputDirectory> <plugins> <plugin> <version>2.3.2</version> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <webResources> <resource> <!-- this is relative to the pom.xml directory --> <directory>web-root</directory> </resource> </webResources> </configuration> </plugin> 
+15
Jun 21 2018-12-12T00:
source share

I follow this step for my java desktop application

1) open your project in eclipse (by going to a new project and going to your project) Importing the project will not work

2) Enable maven for this project

3) add dependency library

4) close the project

5) delete the NBProject folder and Build.xml from the project location (otherwise netbeans will not be able to recognize it as a maven project)

6) open this project from netbeans

backup your project before doing this

+7
Feb 03 '14 at 18:31
source share

Improvement @JVerstry Answer .. I am adding Another solution not explained here in steps.

Create a new Maven project at Netbeans. Then copy your source code to the maven folder, this can be done in Netbeans IDE Projects View Itself. Then do the following.

  • Add SPRING MVC Dependencies.
  • Add the SPRING version of MVC to your (depending on point 1)
  • Set up dispatcher-servlet.xml and web.xml in the SPRING folder.
  • Rest is to do some coordination and tuning of the main controller and the JSP / HTML page.,
  • check your homepage by running.

Point 1 :

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> 

Point 2 : add spring.version to your properties section

 <properties> <spring.version>4.0.2.RELEASE</spring.version> </properties> 

Point 3 . In the WEB-INF folder, create a file called dispatcher-servlet.xml . Open the file and copy the following code.

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <mvc:annotation-driven /> <context:component-scan base-package="com.youbequityweb.controllers" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> 

announces mvc support with annotation support using @Controller, @Service, @Component.

means scanning classes from this base package to determine all bean classes.

The view absorber locates our views (jsp) and extensions. In web.xml add the SPRING configurations inside the web application .

 <!--Spring Config--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <listener> <listenerclass>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet- class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> 

Point 4 . It's complicated, now bind the existing main controller to the base package defined in dispatcher-servlet.xml . for example: HomeController.java .

 package com.youbequityweb.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class HomeController { @RequestMapping(value="/home", method = RequestMethod.GET) public String viewHome(){ return "home"; } } 

Point 5 . In NetBeans, right-click, select โ€œCleanโ€ and โ€œCreateโ€, exit if there are any warnings and conflicts, and then run the SPRING mvc application to get the results.

0
Jan 08 '17 at 22:47
source share

I accidentally discovered the reason Netbeans 8.2. opens projects as Netbeans projects instead of Maven projects; After deleting the NetBeans and Ant files, replace them with a properly formed pom.

Netbeans seems to cache project types for already open projects, this can be resolved by deleting the specified cache.

Its windows are located here:

C:\Users\${username}\AppData\Local\NetBeans\Cache

Linux is here:

~/.cache/netbeans/${netbeans_version}/index/

Mac is here:

~/Library/Caches/NetBeans/${netbeans_version}/

0
Jan 03 '19 at 13:46
source share



All Articles