Yes. Don't put Java source code in the webapp folder. Put it underneath the src/main/java folder.
The Maven compiler plugin will compile your classes and put them in the target/classes folder by default. From there, the Maven WAR plugin will put them in the WEB-INF/classes folder of the final WAR by default.
Don't try to do anything fancy. Just use Maven's source folders as they were intended and let Maven do the rest.
Stephan van Hulst wrote:I don't know what the purpose of the archetype is. When I looked at the directory structure it generates it seems pretty useless to me.
I never really use archetypes. I suggest you learn the Maven POM reference and set up your projects manually. It's not very difficult.
I started doing some introductory reading on how Maven expects directories and files to be set up... And you are right. It's not very difficult to set up your own projects but it is very tedious and takes a lot of reading.
I'm surprised they(Apache Maven) don't have a Maven tutorial called from the ground up -> Building your own Maven projects <-.
Stephan van Hulst
posted 1 month ago
What's wrong with the Maven in 5 Minutes guide and the Getting Started guide?
Incidentally, you defined your servlet in the Java default package and that's not recommended. It's better to define a package like com.coderanch.mywebapp and then create the file /src/main/java/com/coderanch/mywebapp/MyHelloWorld.java. Or probably more informatively as "MyHelloWorldServlet.java". But that's secondary.
The universal archetypes for Maven have been for me almost universally worthless. They're basically just template POMs that people have posted and are often out of date. Although by not including the JEE libraries at least you didn't have to choose between legacy and Jakarta JEE.
If I was defining prototype projects that incorporated local shop standards, I'd likely set up some archetypes in the shop's local repository for convenience. But, as I said, the universal ones aren't so great. Aside from general quality, for a lot of projects there are multiple candidates and no good documents on why you'd prefer one or the other.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop