wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Understanding of Maven / POM.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Understanding of Maven / POM.xml" Watch "Understanding of Maven / POM.xml" New topic
Author

Understanding of Maven / POM.xml

Fred Funks
Greenhorn

Joined: Mar 07, 2014
Posts: 10

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
 
subject: Understanding of Maven / POM.xml