IT story

Maven 종속성을 사용하도록 Eclipse 빌드 경로를 구성하는 방법은 무엇입니까?

hot-time 2020. 7. 17. 07:58
반응형

Maven 종속성을 사용하도록 Eclipse 빌드 경로를 구성하는 방법은 무엇입니까?


Maven이 프로젝트의 종속성 관리를 위해 제공하는 기능을 활용하고 싶습니다. Maven의 작동 방식에 대한 간단한 이해는 필요한 JAR을 확보 한 다음 이러한 라이브러리를 사용하여 프로젝트를 빌드한다는 것입니다.

현재 간단한 POM 파일을 테스트로 설정했습니다.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jamesgoodwin.test</groupId>
  <artifactId>com.jamesgoodwin.test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.0.0.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

일반적으로 프로젝트의 종속성을 관리 할 때 프로젝트 또는 JAR을 프로젝트 빌드 경로에 추가 한 다음 프로젝트를 빌드 할 수 있습니다.

그러나 M2Eclipse를 사용할 때 종속성이 빌드 경로에 자동으로 추가되지 않습니다. Eclipse가 Maven이 종속성을 관리하고 있음을 알 수 있도록 이것을 구성해야 할 곳이 있습니까?


프로젝트를 마우스 오른쪽 버튼으로 클릭하면 "maven"아래에 "dependency management 활성화"옵션이 있어야합니다. 그게 다야.


당신이 실행한다면

mvn eclipse:clean

뒤에

mvn eclipse:eclipse

이클립스 .classpath파일을 준비하면됩니다 . 즉, 이러한 명령은 명령 줄에서 즉, 외부에서 maven에 대해 실행됩니다.


당신이 언급 한대로 m2eclipse를 사용하고 있다고 가정합니다. 그러나 Eclipse에서 프로젝트를 만들 었는지 여부는 확실하지 않으므로 모든 경우를 다룰 것입니다.

  1. Eclipse (Ctrl + N> Java 프로젝트)에서 "Java"프로젝트를 작성한 경우 패키지 탐색기 보기 에서 프로젝트 마우스 오른쪽 단추로 클릭 하고 Maven> 종속성 관리 사용 (초기 프로젝트 구조에 따라)으로 이동하십시오. 예를 들어 빌드 경로의 소스 폴더에 추가하여 maven과 일치합니다 .src/java

  2. Eclipse (Ctrl + N> Maven Project)에서 "Maven Project"를 생성 한 경우 이미 "Maven ready"상태 여야합니다.

  3. Eclipse 외부에서 Maven 프로젝트를 작성했거나 (수동으로 또는 아키 타입으로) Eclipse에서 가져 오기만 하면됩니다 ( 패키지 탐색기 보기를 마우스 오른쪽 단추로 클릭 하고 가져 오기 ...> Maven 프로젝트 선택 ). "Maven ready"가됩니다.

이제 종속성을 추가 하려면 프로젝트를 마우스 오른쪽 단추로 클릭 하고 Maven> 종속성 추가를 선택 하거나 pom을 수동으로 편집하십시오.

추신 : m2eclipse를 사용하는 경우 maven-eclipse-plugin을 사용하지 마십시오 . 절대적으로 필요가 없으며 혼란스럽고 혼란을 일으킬 수 있습니다. 실제로 무엇을하고 있는지 알지 못한다면 사용하지 마십시오.


이것을 .classpath 파일에 추가하십시오.

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

고마워


프로젝트 구성을 마우스 오른쪽 버튼으로 클릭하고 Maven 프로젝트로 변환

그런 다음 프로젝트의 모든 Maven 관련 메뉴를 볼 수 있습니다.


나는 이것을 좋아했다 ..

프로젝트-> 구성-> maven 프로젝트로 변환을 마우스 오른쪽 버튼으로 클릭하십시오. 프로젝트-> 메이븐-> 종속성 추가를 마우스 오른쪽 버튼으로 클릭하십시오.


이클립스 (화성)에서 다음으로 이동하십시오.

프로젝트 속성-> Maven. "작업 공간 프로젝트의 종속성 해결"이 사용 불가능 한지 확인하십시오 .


maven 또는 configure 메뉴를 찾지 못했지만 내 문제를 해결하는 다음 버튼을 찾았습니다.

enter image description here


When m2eclipse is installed properly, it should add dependencies automatically. However, you should generate the eclipse project files by entering:

mvn eclipse:m2eclipse

or, alternatively if you don't use m2eclipse:

mvn eclipse:eclipse

I had a slight variation that caused some issues - multiple sub projects within one project. In this case I needed to go into each individual folder that contained a POM, execute the mvn eclipse:eclipse command and then manually copy/merge the classpath entries into my project classpath file.


For newer Eclipse versions (>=Mars) right click on project > configure > convert to Maven project


Adding my answers for a couple of reasons:

  • Somehow none of the answers listed directly resolved my problem.
  • I couldn't find "Enable dependency management" under Maven. I'm using Eclipse 4.4.2 build on Wed, 4 Feb 2015.

What helped me was another option under Maven called as "Update Project" and then when I click it this window opens which has a checkbox that says "Force update of Snapshot/Releases". The real purpose of this checkbox is different I know but somehow it resolved the dependencies issue. enter image description here


None of that solved my problem. but what I did was if click on the pom.xml, there is a tab at the bottom named dependencies. in this tab it is split into 2 section, one called dependencies and one called dependency management. select every thing in the dependency section and click add to be under the dependency management control. close and reopen your project.


Maybe you could look into maven-eclipse-plugin instead of M2Eclipse.

There you basically add maven-eclipse-plugin configuration to your pom.xml and then execute mvn eclipse:eclipse which will generate the required .project and .classpath files for Eclipse. Then you'll have the correct build path in Eclipse.


Make sure your POM follows the naming convention, and is named in lowercase lettering as pom.xml and NOT POM.xml.

In my case all was right, but Eclipse still complained when trying to Right-click and Update project configuration - told me that the POM could not be read. Changed the name to lowercase - pom.xml from POM.xml - and it worked.


I met this issue too. When I add dependencies in the pom.xml, I checked in the local folder /Users/xyz/.m2/ and the jars are already downloaded there, but cann't added the the buildpath of the eclipse.

My eclipse Version: Mars.2 Release (4.5.2)

right click project > Maven > Enable Workspace Resolution

And this solved my issue.


Typically, you can copy the .classpath file from a working project since there isn’t anything project specific here assuming you’re structured as a standard Maven project.


This worked for me in Eclipse Oxygen (4.7.0):

Right click Project -> Maven -> Select Maven Profiles... then check the Repository Proxy box, press OK.

참고URL : https://stackoverflow.com/questions/2037188/how-to-configure-eclipse-build-path-to-use-maven-dependencies

반응형