Tuesday, July 19, 2011

Finding the Artifact ID of a Java Library

To build one’s Java applications with Maven, one has to at first find the group ID, the artifact ID, and the version number that together identify each of the Java libraries (artifacts, in Maven’s term) used by each of the Java applications. One also has to find where (i.e. a Maven repository) the artifacts reside. Fortunately the Maven Central Repository contains almost all popular open source Java libraries. And it is very easy to find the artifact ID, the group ID, and the version number of a Java library in that repository through The Search Engine for Maven Central.

For example, I was developing a Java application that used the StringTemplate Java template engine created by Terence Parr. The StringTemplate website told me that the latest version of StringTemplate then was 4.0.3. The website also said that I would need to download two jar files, ST-4.X.jar and antlr-complete.jar, to my classpath. That is, however, not the way with Maven. So I visited The Search Engine for Maven Central, and searched “StringTemplate”. The search engine found about seven artifacts (i.e. Java libraries) in the repository. One has the group ID “org.antlr”,  the artifact ID “stringtemplate, and the  latest version number 4.02. It is what I need. So I added the following fragment into my POM file:

<dependency>
    <groupId>org.antlr</groupId>
    <artifactId>stringtemplate</artifactId>
    <version>4.0.2</version>
</dependency>

It works! Since my application does not directly use Antlr. I do not have to do anything about it. Obviously StringTemplate uses Antlr but Maven will handle it automatically. With the Advanced Search feature of the The Search Engine for Maven Central, one can even search by Java class names.

There is an alternative Maven repository search engine at http://mvnrepository.com/. It works pretty well too. When I cannot find what I need using The Search Engine for Maven Central, I will try MVNRepository. Often it helps.

Background

Most Java applications use Java libraries. Usually one has to download each Java library to the same computer where the JVM runs, and to place the library file (usually a .jar file) on the classpath of the JVM. If one Java library uses other Java libraries, one has to find out what they are and from where one can get them, and download them to the classpath of the JVM; and repeat it recursively. That is quit a headache. In addition, when one deploys that Java application to another computer, one has to repeat all the works to make the libraries available on that computer. To do so, one has to keep well the knowledge of the dependency tree somewhere in an ad hoc manner.

Maven helps by explicitly keeping direct dependencies on other libraries in the Project Object Model (POM file) and handling indirect dependency automatically. In Maven’s term, a Java library is an artifact, and an artifact is usually identified by a group ID, an artifact ID, and a version number. For more information about Maven, check out the Apache Maven website, and the (free) Sonatype Maven Books.

7 comments:

Tanika Co Valda said...

Very much useful article. Kindly keep blogging

Java Training in Chennai

Java Online Training India

neha raje said...


Very Nice Information I like this very much!!
#Computer #Software #Library, #School library #automation #solution.
Best Computer software Library

sai said...

Read all the information that i've given in above article. It'll give u the whole idea about it.
python interview questions and answers
python tutorials
python course institute in electronic city

jai said...

This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
Data Science course in rajaji nagar
Data Science with Python course in chenni
Data Science course in electronic city
Data Science course in USA
Data science course in pune | Data Science Training institute in Pune

manisha said...

I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
Best Devops Training in pune
Microsoft azure training in Bangalore
Power bi training in Chennai

Saro said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
rpa training in bangalore
best rpa training in bangalore
rpa training in pune | rpa course in bangalore
rpa training in chennai

priya said...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
Data Science training in chennai
Data Science training in OMR
Data Science training in chennai
Data Science Training in Chennai
Data Science training in Chennai
Data Science training in anna nagar
Data science training in bangalore