문제

I am used to the layout provided by the Dynamic Web project in eclipse where you have all your Java code under the src folder, your JSP files, etc under the WebContent folder and the WEB-INF resides right under the WebContent folder. Also, the Output folder is hidden from the project tree. Maven has its own format which I find somewhat confusing, it creates its now target folder and source/main/java folder and some test folder under target...

Is there a way to create a Maven project and have it use the Dynamic Web project project tree layout?

I tried changing the Deployment Assembly entries to match that of the Dynamic web project and have also update the Java Build Path src and output to match the Dynamic Web project one but I get strange, cryptic unfriendly errors when I do a Run/Install. Can you provide me with details on how to go about doing this cleanly?

도움이 되었습니까?

해결책

What you need to get used to using is the concept of archetypes in Maven. The concept is like project templates ready for you to use that are automatically understood by Maven.

mvn archetype:generate

will get you an interactive listing of all the available archetypes

What you want to look for is maven-archetype-webapp this will give you a basic skeleton framework of what Maven is expecting a webapp to look like.

There are others that include support for different frameworks and what not.

mvn archetype:generate | grep webapp

will filter out all the choices that are webapp archetypes

Then it is a simple mvn clean package and you get an exploded dir and a .war in the target directory, you can even enable the Tomcat plugin to automatically deploy to Tomcat. Other J2EE servers are supported as well.

Then you use the Maven plugin for eclipse to load the project based on the pom.xml file.

You could create your own non standard layout and get it working by manually configuring everything thing and create an archetype out of it but that kind of defeats the purpose of a single way of doing things with a tool like Maven.

다른 팁

Using m2e 1.3+ and m2e-wtp 0.16.0+, you can just :

  • create a new Dynamic Web project
  • right-click on the project > Configure > Convert to Maven...
  • Fill in the Maven coordinates of your project and finish

It'll mavenize your project, keeping the standard Eclipse project layout.

See http://wiki.eclipse.org/M2E-WTP/New_and_Noteworthy/0.16#New_project_conversion_participants for more information

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top