Netbeans 프로젝트를 Maven 지원 프로젝트로 변환
Netbeans 생성 프로젝트를 Maven 구성 수락으로 전환하려면 어떻게해야합니까? Maven 기반 프로젝트를 만드는 옵션이 있지만 Maven 종속성을 기존 프로젝트에 추가 할 수있는 옵션이 없습니다 (지금까지 찾았습니다).
별도의 Maven 프로젝트를 만들어야합니다. 그런 다음 다른 프로젝트에서 Maven 프로젝트로 코드를 복사 할 수 있습니다. NetBeans의 프로젝트 창에서이 작업을 수행 할 수 있습니다.
트리에서 코드 파일 / 패키지를 선택하고 마우스 오른쪽 버튼을 클릭하여 복사 한 다음 새 Maven 프로젝트의 소스 패키지에 붙여 넣습니다.
다음으로 Maven이 종속성을 놓치기 때문에 컴파일하지 않을 파일을 엽니 다. 문제가있는 줄의 왼쪽에있는 노란색 전구는 누락 된 종속성을 검색하여 프로젝트에 추가 할 수있는 옵션을 제공합니다. 검색을 수행하려면 온라인 상태 여야합니다.
프로젝트 창에서 종속성 폴더를 마우스 오른쪽 버튼으로 클릭하여 새 Maven 프로젝트에서 수동으로 maven 종속성을 추가 할 수도 있습니다.
maven에 익숙하다면 나중에 언제든지 maven을 구성 할 수 있지만 권장하지 않습니다.
사람들이 (나를 포함하여;)) 새로운 maven 프로젝트를 만들 것을 권장하는 유일한 이유는 Maven이 자체 디렉토리 구조를 가지고 있기 때문입니다. 그리고 그것은 표준입니다. 이제 이후 단계에서 프로젝트에 대해 maven을 활성화하려면 pom.xml의 항목, 즉 소스 디렉토리, 대상 디렉토리 및 웹 앱 디렉토리 (해당하는 경우)를 구성 할 수 있습니다.
SVN에 큰 프로젝트가 있었는데 새 프로젝트를 만들 수 없었습니다. lib 관리를 지원하고 싶지 않았기 때문에 디렉토리 구조에 따라 maven을 구성했습니다.
여기 내 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>
내 데스크톱 Java 애플리케이션에 대해 다음 단계를 따릅니다 (이 작업을 수행하기 전에 프로젝트를 백업합니다).
Eclipse에서 프로젝트를 엽니 다 (새 프로젝트로 이동하여 프로젝트를 찾습니다). 프로젝트 가져 오기가 작동하지 않습니다.
이 프로젝트에 Maven 사용
종속성 라이브러리 추가
프로젝트 닫기
프로젝트 위치에서
NBProject
폴더를 삭제Build.xml
하십시오 (그렇지 않으면 NetBeans가이를 Maven 프로젝트로 인식 할 수 없습니다).NetBeans에서이 프로젝트 열기
@JVerstry 답변 개선 .. 여기에 설명되지 않은 다른 솔루션을 단계적으로 추가 합니다.
Netbeans에서 새 Maven 프로젝트를 만듭니다. 그런 다음 Maven 폴더에 소스 코드를 복사하여 붙여 넣으십시오. Netbeans IDE 프로젝트에서 수행 할 수 있습니다. 그 후에 다음 단계를 따르십시오.
- SPRING MVC 종속성을 추가합니다.
- 속성 섹션에 Spring MVC 버전을 추가합니다 (포인트 1에 따라 다름).
- Spring 폴더에서 dispatcher-servlet.xml 및 web.xml을 구성하십시오.
- 나머지는 메인 컨트롤러 및 JSP / HTML 페이지를 일치시키고 구성하는 것입니다.,
- 실행하여 홈페이지를 확인하십시오.
포인트 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: and add spring.version to your properties section
<properties>
<spring.version>4.0.2.RELEASE</spring.version>
</properties>
Point 3: Under WEB-INF folder, create a file named 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>
The declares support annotation driven mvc such using @Controller, @Service, @Component.
The means to scan classes from this base package to determine all bean classes.
The view resolver specifies the locations of our views(jsp) and the extension. In your web.xml, add the spring configurations inside web-app section.
<!--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: This is tricky, now Link your existing main controller to the base package defined in dispatcher-servlet.xml. e.g: HomeController.java shown below.
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, now right click, choose clean and build, get away if any warnings and conflicts and than run your spring mvc application for results.
I discovered by accident, the reason why Netbeans 8.2. opens projects as Netbeans projects instead of Maven projects; after you have deleted the netbeans and ant specific files then replaced them with the correctly formed pom.
Netbeans seems to cache the project types for already opened projects, this can be resolved by deleting said cache.
Windows its located here:
C:\Users\${username}\AppData\Local\NetBeans\Cache
Linux here:
~/.cache/netbeans/${netbeans_version}/index/
Mac here:
~/Library/Caches/NetBeans/${netbeans_version}/
참고URL : https://stackoverflow.com/questions/5495213/converting-a-netbeans-project-to-a-maven-enabled-project
'IT TIP' 카테고리의 다른 글
왜 instanceof가 babel-node 아래에있는 Error 서브 클래스의 인스턴스에서 작동하지 않습니까? (0) | 2020.10.24 |
---|---|
Docker : 마운트가 거부되었습니다. (0) | 2020.10.24 |
{before _,} {install, script} .travis.yml 옵션의 차이점은 무엇입니까? (0) | 2020.10.24 |
데이터베이스에 업무 시간 저장 (0) | 2020.10.24 |
Sqlite에서 이미지를 blob으로 저장하는 방법 및 검색 방법? (0) | 2020.10.24 |