maven-archetype-webapp eclipse problem

JavaEclipseMaven 2M2eclipseMaven Archetype

Java Problem Overview


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!

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

  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.

Solution 3 - Java

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

Solution 4 - Java

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.

Solution 5 - Java

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!

Solution 6 - Java

Simply create new folder named java under src/main/

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

Solution 7 - Java

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

Solution 8 - Java

> 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

Solution 9 - Java

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

Solution 10 - Java

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

Solution 11 - Java

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

Solution 12 - Java

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

Solution 13 - Java

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.

Solution 14 - Java

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

Solution 15 - Java

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

Solution 16 - Java

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.

Solution 17 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeremyView Question on Stackoverflow
Solution 1 - JavaPascal ThiventView Answer on Stackoverflow
Solution 2 - JavaUdayanView Answer on Stackoverflow
Solution 3 - JavaLinzView Answer on Stackoverflow
Solution 4 - JavaMcDowellView Answer on Stackoverflow
Solution 5 - JavaRyanView Answer on Stackoverflow
Solution 6 - JavaSyeful IslamView Answer on Stackoverflow
Solution 7 - JavaGoibniuView Answer on Stackoverflow
Solution 8 - JavadiraView Answer on Stackoverflow
Solution 9 - JavaLisaView Answer on Stackoverflow
Solution 10 - JavaShrini JaiswalView Answer on Stackoverflow
Solution 11 - JavaMiladesnovakainaView Answer on Stackoverflow
Solution 12 - JavaSid PandeyView Answer on Stackoverflow
Solution 13 - JavaDavid Auby JohansenView Answer on Stackoverflow
Solution 14 - Javapooja patilView Answer on Stackoverflow
Solution 15 - JavaVipin PurohitView Answer on Stackoverflow
Solution 16 - JavaManohar BhatView Answer on Stackoverflow
Solution 17 - Javavedavyasa kView Answer on Stackoverflow