maven-archetype-webapp eclipse problem

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.

或者,我已经尝试在主目录下创建一个新的“ Java ”目录,但仍然有相同的不存在的Java症状。

What gives? This is driving me insane..

Thanks all!

50280 次浏览

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

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.

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

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

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

  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.

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" .

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!

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

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

Simply create new folder named java under src/main/

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

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.

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

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

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"/>

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.

Following steps work in eclipse 2020-06

  1. File->New->Maven Project
  2. Choose "Create a simple project (skip archetype selection)"
  3. Choose packaging as "war" (this will create both webapp and java folders)
  4. Create the project after specifying group id and artifact id
  5. Update pom.xml with java and compiler versions, then right click on project, select Maven->Update project
  6. If the project is not faceted form (Its not in faceted form if on expanding project in Project explorer, it doesn't show details such as "Deployment Descriptor" and "JAX-WS Web Services", this happened in one of my eclipse installation and i had no clue why), then do the following steps
    1. right click on project, go to Properties, click on Project Facets, convert to faceted form, choose correct "Dynamic Web Module" version, enable the checkbox and also choose correct Java Facet version.
    2. "Further configuration available" gets displayed in that window, click on it and specify WebContent folder. (replace WebContent by src/main/webapp)
    3. If you want to run the application in servers configured in eclipse, then specify maven dependencies to be deployed in "Deployment Assembly". This will deploy maven "provided" dependencies also, but i think its fine for testing. For actual distribution, you can supply war file generated from maven package.