0

I'm trying to add a JAR local file as a dependency to a Maven project in Eclipse, but I have the restriction that the client doesn't want me to edit the pom.xml file.

My JAR is located in WEB-INF/lib. I tried the solution proposed in Adding Jar File to WEB-INF/lib but it didn't work.

To verify that the project compiles correctly adding the JAR, I added it in the pom.xml file in my machine and it worked.

The official documentation of Maven proposes three solutions, all of them involve editing the pom.xml file: http://maven.apache.org/pom.html#Dependencies

Is it actually possible to include a JAR dependency to a Maven project without editing the pom.xml file?

Berna
  • 131
  • 1
  • 3
  • 14
  • What is the reason behind the pom.xml limitation? And is the final artifact a war archive? – ernest_k Dec 28 '17 at 11:33
  • Sorry but if you need a dependency than you have to add it to the pom file....otherwise you are producing something which can't be reproduced by using Maven...Furthermore a local file do you mean a jar file which does not exist in a repository manager ? – khmarbaise Dec 28 '17 at 11:35
  • @ErnestKiwele yes, the final artifact is a war archive. The limitation is because we share the souces repository, and he says that in the actual state the project compiles correctly. I don't see how that could be possible, but he insists. – Berna Dec 28 '17 at 11:37
  • @khmarbaise yes, the JAR file is not in a repository manager, it's a package they distribute separately. I guess there must be a way of telling Maven at compile time to include the file, as some sort of parameter... – Berna Dec 28 '17 at 11:39
  • Sorry but there is not. If it's only a jar which is needed for compile time you have to add it to the pom. Best is to put such package into your own repository manager and you can use it as a dependency. Furthermore if you are using the source you should build it before and offer it as a dependency from your repository manager (and tag it with a particular version number) so you can reproduce your build otherwise you can't... – khmarbaise Dec 28 '17 at 11:50
  • @ErnestKiwele wouldn't that require me to edit the pom.xml file? – Berna Dec 28 '17 at 12:21
  • Oh my bad. Can you then just add the jar to web-inf/lib in the source project? I've done this before and maven will just add other pom dependencies to what it finds in the lib directory. – ernest_k Dec 28 '17 at 12:26
  • @ErnestKiwele yes, the JAR is already in my WEB-INF/lib folder, and it appears in the Java Build Path, but Maven doesn't seem to include it, and the build throws an exception of ClassNotFoundException. – Berna Dec 28 '17 at 12:32

1 Answers1

0

You can add a JAR by right clicking your project and going to properties.

Janitha
  • 79
  • 9