Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Understanding of Maven / POM.xml

 
Fred Funks
Greenhorn
Posts: 10
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello community,

I started to learn Java EE not a long time ago but most of the time I learned the theory. Now I wanted to try out some practical tutorials, but there is a giant problem: I can't understand how the POM.xml should be created.

From what I understand, it seems like you have to have all the dependencies in it, like the packages you need for your project and write some details about the project itself, like the version and name.

So, I tried a basic "hello-world tutorial" from jboss.org (I'm using Eclipse + JBoss + Maven), where some javax packages are needed for annotations, like



Then I found out, that you have to use the Maven Repository for such packages, if you're using Maven in your project. I found this code on MVNrepository for javax.inject:



I added it to my POM.xml, but the import still could not be resolved. Then I saw, that the author of that helloworld tutorial uses this dependency in his POM:



With this dependency the project works without problems.

Now the questions:

1. Why does it have to be this particular repository?
2. How can I find out, which repository to use in my dependencies?
3. What is an easy / right way to create the POM? You can let maven create it for you, but you gotta choose what archetype to use. How do I know, which archetype I need?
4. Is there a way to automatically adjust an existing POM in an imported project?
5. Is there a good explanation about maven / pom, that would answer my question?


Thank you a lot in advance. If you need more information - just ask.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Why does it have to be this particular repository?

javax.inject just contains a handful of classes (well interfaces) related to injection. ServletException is not in there. The JBoss dependency is actually a pom dependency not a jar. This means it contains a reference to other dependencies. You can look at it and see that it does in fact include javax.inject.


It also includes a number of other dependencies that are used in Java EE including the servlet one. You don't have to use the JBoss package. But it certainly makes things easier since it is your server.

One thing that surprises me is that they don't use <scope>provided</scope> in those dependencies. You wouldn't want all these dependencies to be in your war or ear file.

2. How can I find out, which repository to use in my dependencies?

Either an example or searching. Your idea to search was fine.

3. What is an easy / right way to create the POM? You can let maven create it for you, but you gotta choose what archetype to use. How do I know, which archetype I need?

It depends on the type of the project. For example for a web application, you might used maven-archetype-webapp. I don't typically use archetypes. I have a parent pom file with the dependencies I commonly need and just inherit it. Which is similar to what you did with JBoss pom except you didn't extend it.

4. Is there a way to automatically adjust an existing POM in an imported project?

I'm not sure what you mean by this.

5. Is there a good explanation about maven / pom, that would answer my question?

I like the free e-book Better Builds with Maven. It explains the parts of the pom nicely.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic