There are several ways to solve this.
Keeping your repository
The ideal is to install the jars in a repository of your company/home. For this you need a server with Artifactory or Nexus.
The advantage of having your own repository is that you can use it to manage the versions of your projects as well.
Another advantage is that it caches the central repository and its environment gets faster.
Dependencies with scope system
You can also point to the dependency path of the type system
. Consider the following example:
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
These dependencies can also be inside the project. Use the variable ${basedir}
to indicate the base directory of the project.
The problem with this approach is that you need to keep the Jars in the repository, which is not very indicated.
See the documentation for more details.
Note: Maven added a restriction to the use of libs within the project, as can be seen in the error edited in the question. One should then use a directory outside the project.
Installing dependencies in the local repository
Another solution is to use the plugin install
to install the jars in a local repository. This can be done with the command mvn install:install-file
and the appropriate parameters. See documentation more details.
Example:
mvn install:install-file -Dfile=morena7.jar -DgroupId=sk.gnome \
-DartifactId=morena -Dversion=7.0 -Dpackaging=jar
Note that the above data has been invented and will only work in the environment in which it was installed.
The problem with this approach is that the installation process needs to be repeated in each environment, that is, on each development machine and on the Continuous Integration server, if any.
edited my question with the attempt I made following your tip.
– NilsonUehara
@Nilsonuehara You must be using one of the newer versions of Maven. I just noticed that they added this restriction. However you can put the files in a folder outside the project and specify the absolute path. Another alternative is to install the jar in your local repository using any groupid and artifactId. I will update the response with this.
– utluiz
I have come to the conclusion that the best thing to do is to install the Nexus or even Artifactory, as it will facilitate the maintenance work.
– NilsonUehara
@Nilsonuehara If you have this option, it’s really the best way!
– utluiz