maven-archetype-webapp eclipse problem

旧街凉风 提交于 2019-12-17 07:09:31

问题


I'm trying to create a very simple webapp with maven and eclipse, but I'm having no joy at all, in fact the reverse of joy.

I go to File -> New Project, select Maven Project, and select the maven-archetype-webapp. When I finish the wizard, a webapp structure gets generated but with no 'java' directory under main, just resources and webapp.

So I right click on main and select new Class. The class gets created under resources (?!), and furthermore, there seems to be no compilation of it by java. I can make stupid errors and no syntax highlighting comes up. It's like java isn't recognizing it.

Alternatively I have tried creating a new 'java' directory under main where it should be, but still with the same non-existent java symptoms.

What gives? This is driving me insane..

Thanks all!


回答1:


Simply create a java directory under main (i.e. src/main/java) and right-click on your project and select Maven > Update Project Configuration.




回答2:


  1. By default, When you create a project with maven archetype "maven-archetype-webapp", it doesn't create any java and test folders.
  2. You can manually add those folders as src/main/java and src/test/java.
  3. After adding these folders, right click on your project in project explorer, go to maven>update project conf.



回答3:


Simply create a java directory under main (i.e. src/main/java) and right-click -> Build Path -> Use a Source Folder




回答4:


  • Read the m2eclipse WTP mini-howto.
  • Check the online Developing with Eclipse and Maven.
  • Ensure your settings.xml is configured in the Eclipse preferences.
  • Check the m2eclipse FAQ.

Anything else is likely to be down to the archetype and how you've configured your pom.xml. The directory structure you describe is identical to the one maven-archetype-webapp creates on the command line.




回答5:


This is a great article that I read when I was having trouble understanding how to build multiple projects into one using Maven. Specifically, this article explains how to set up a WEB project (war file) to consume an inner standard java project (jar file).

If you have a basic understanding of Maven, skip to the sections at the end: How do I build other types of projects? How do I build more than one project at once?

http://maven.apache.org/guides/getting-started/index.html#How_do_I_build_other_types_of_projects

If you aren't familiar with Maven yet, check out:

http://www.mkyong.com/spring/quick-start-maven-spring-example/

Trust me, mkyong knows what is up!




回答6:


Simply create new folder named java under src/main/

Then right click on project and select maven->update project




回答7:


There is an option to create a source directory in eclipse. Or you can go to build path under project properties, and add an existing directory as a source directory.

If you are going to use non-standard directory structure you will have to specify it in maven though




回答8:


a webapp structure gets generated but with no 'java' directory under main

Create src/main/java on your own.

furthermore, there seems to be no compilation of it by java. I can make stupid errors and no syntax highlighting comes up. It's like java isn't recognizing it.

after creating appropriate dir structure execute the maven command

mvn eclipse:eclipse 

then refresh the project in eclipse.

-SE




回答9:


for src/main/java your project >> properties >> java build path >> source >>
search "Your Project src/main/java (missin)" >>>

edit > folder name >> next >> Inclusion patterns: -----> Add >> src/main/java OK

and if errors still don't disapear

>>>  look in Target Runtimes  and check your apache in checkbox



回答10:


in IntelliJ IDEA 13 you must first create "java" folder in main folder then --> go to "open module setting"- for this you can click on project name and press f4- , and set label of "java" folder to "source" .




回答11:


Here is my solution. It works without any issue.

There could be questions regarding why all this steps are required and i believe they are pretty genuine. But this is one of the ways to make your web application or any other component working on eclipse using Maven from command line.

1) Open a command window

2) mvn archetype:generate -DgroupId=your package -DartifactId=your Project -DarchetypeArtifactId= your archetype. In my case "maven-archetype-webapp" -DinteractiveMode=false

3) cd your Project

4) mvn eclipse:eclipse -Dwtpversion=2.0

5) Go to file system. Go to your newly created project. create folders, a) java under main
b) test under src c) java and resources under test

6) mvn eclipse:clean

7) mvn eclipse:eclipse -Dwtpversion=2.0

8) import your Project project in eclipse

Thanks, Sid




回答12:


Do it the other way around. First make a webapp project, then add the Maven framework (in Intellij - right click project and select Add framework support). It will create the right folders for you.




回答13:


Right click the Maven Project -> Build Path -> Configure Build Path In Order & Export tab, you can see the message like select 'JRE System Library' and 'Maven Dependencies' checkbox Click OK Now you can them




回答14:


I had the same problem even when i added JRE system library to my current java version but still had same problem then i just deleted JRE system library and added once again it worked for me

  • To delete JRE System Library right click on project ->properties ->java build path -> select JRE system library -> remove

  • To add JRE go to properties->java build path -> add library ->JRE system library -> choose JRE -> finish




回答15:


Just add a new folder "java" under src/main. will solve the problem. Because the classpath with java folder is already available in .classpath file of created project, so adding java folder will not cause any error. see below entry in .classpath file, which allows to add java folder.

<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>




回答16:


error occurs when the JRE System Library is wrongly pointed. Now go to Libraries tab and change the JRE System Library to the correct version.



来源:https://stackoverflow.com/questions/3042518/maven-archetype-webapp-eclipse-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!