Maven build tool – Advanced technique (1014 views)

01. Install an artifact what isn’t available in Maven central repository
A circumstance many Java developers faced, it is no existing Oracle JDBC library in Maven central repository [1]. Because Oracle JDBC is a property artifact what is the subject of license term. How to overcome this?

Download ojdbc14.jar from  Oracle [2]. Suppose, we put this JAR file to C:\  directory, then install by command:

How to add ojdbc14.jar to project classpath? Inside pom.xml file:

This trick can apply for all in-house artifact what packaged to JAR file(s), also property Java libraries.

02. BOM (“Bill of materials”)
For dependencies version setting in an unified way and compatible assured, Java developer set version values of dependencies by this technique. In almost case, these snippets in parent-module. However, you also it inside current pom.xml of child module.

Notice: These version values of dependencies in pom.xml of parent module is not always necessary appear in one/all child-module(s).

In pom.xml (of a child-module), we don’t specify the version of dependencies:

( As you see, It doesn’t include version value)




03. Have a private Maven repository

Clearly, you can’t public all things, you can’t publish private/property JAR files (library, module, etc.) to Maven central repository or other public repository. It’s the time you request system administrator setup own Maven repository. Stand on experience, 2 most used solutions are: jFog Artifactory [3], you must pay for their software (if install on own server) or pay for their services (jFog Artifactory as a Service), or use Sonatype Nexus OSS [4]. Currently, we have Docker, Google Cloud Launcher, etc. therefore, you have a private Maven repository in few minutes is feasibility.

04. Customize project’s directory structure

This is default/convention, you don’t necessary declare these stuff one again:

This is a customized project’s directory structure:



Xem thêm: Lập trình java cơ bản

Do Nhu Vy – developer

May be interested posts: