Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven2 Dependencies and Native Libraries [duplicate]

I have the following scenario:

mylib is a library (for which I have the sources, so I'd like to put them into a Maven project mylib:mylib for example). This library has a jar dependency for which I only have the jar, and it is not to be found in the Maven repository (and I do NOT want to install it there either). To make it compile, something like this would work: add the jar file to the mylib project in a "lib" folder, e.g. "lib/thirdpartylib.jar" and in mylib's pom.xml, add a dependency with self-chosen group/artifact/version and a "<scope>system</scope><systemPath>${project.basedir}/lib/thirdpartylib.jar</systemPath>" entry. The mylib project will compile fine.

Note that mylib also has a runtime dependency to a dll file, say thirdparty.dll. But for compilation this is not important.

However, now what I am wondering how to achieve the following:

Any other projects, e.g. project "X", that uses mylib, will need the

- mylib.jar
- thirdpartylib.jar
- thirdpartylib.dll

,

and it'll have to set the java.library.path to the directory (e.g. ".") such that the thirdparty jar and dll are found by the executing VM.

My concern is this: I would like the thirdparty jar/dll things to be the responsibility of the mylib project. I.e. I want to define the knowledge, that you need to copy the thirdparty jar and dll to the target folder and that java.library.path refers to them, to be part of the mylib project (the mylib pom knows how the thing is to be used in other projects). Yet, I want this knowledge (i.e. copy instructions, regardless how they are exactly done in Maven) to be transitively handed over to any other project using mylib, like X for example. Is that somehow possible?

[My hack solution for now would be that I have a copy of the thirdparty things in X, but even then I dunno how to copy/deal with the dll file, so I'd have to write a readme saying that the dll file has to be copied to the bin folder of the executing VM).

Any suggestions are appreciated!

like image 576
NameZero912 Avatar asked Sep 22 '11 13:09

NameZero912


People also ask

How do I delete duplicate dependencies in Maven?

you can use mvn dependency:tree command to find duplicate dependencies into your project. Use the <exclusions> tag into <dependency> tag of the pom to exclude that duplicate dependencies from maven project. Save this answer.

How do I remove duplicate dependency?

Removing Duplicate Dependencies Once we have identified our duplicate dependencies, the simplest way to remove them is to delete them from pom. xml and keep only those unique dependencies that are used by our project.

How do I fix Maven dependency issues?

If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local . m2 repository to see if it was downloaded correctly.

How do you fix the container Maven dependencies references non existing library?

Try to update your Maven configuration : In the Project Explorer, right-click on the project, Maven -> Update project. If the problem still remains, try to clean your project: right-click on your pom. xml, Run as -> Maven build (the second one). Enter "clean package" in the Goals fields.


1 Answers

The base idea is the following:

  • Maven is good in handling with one result per Maven POM.
  • It is possible to have libraries and dependencies to these libraries in your local repositories only.

So you have to do the following steps:

  1. Define for the additional library a separate project (or a module in your project) and define the library as the result.
  2. Change your POM so that this POM has now a dependency to the new project.
  3. Do the same steps for your DLL (see the post Managing DLL dependencies with Maven) how to do that).
  4. Deploy your additional library and your DLL to your local repository.

Now you should be able to use Maven for the build process again, and by using additional plugins like the maven-assembly-plugin, you are able to pack all together.

like image 75
mliebelt Avatar answered Sep 22 '22 01:09

mliebelt