Reputation: 242
I have the following issue. Say I have a directory with a bunch of external jars that are not under my supervision. Those jars are stored in the lib directory
lib
|_folder1
| |_jar1.jar
| |_jar2.jar
|_folder2
| |_jar3.jar
|_jar4.jar
Now every time a new version of the library is released I got a copy of the lib folder that I need to integrate into my application.
Since there are many jars in it and I don't want to integrate a myriad of jars every time I start a new project or the version of the library changes I thought maybe I can integrate all those jars into one library hosted by my local Maven repository.
So the idea is to have a script that crawls to the whole directory searches for all the jar files and install them in my local repository.
Here is what the first version of the script looks like:
SET @libPath="C:\path\to\lib"
SET @groupId="group.id.custom.lib"
SET @artifactId="custom-lib"
SET @version="1.0"
SET @packaging="jar"
for /r %@libPath% %%i in (*.jar) do mvn install:install-file ^
-Dfile="%%i" ^
-DgroupId=%@groupId% ^
-DartifactId=%@artifactId% ^
-Dversion=%@version% ^
-Dpackaging=%@packaging%
The idea would be to just have to add the dependency to my pom.xml file and be done with it:
<dependency>
<groupId>group.id.custom.lib</groupId>
<artifactId>custom-lib</artifactId>
<version>[1.0,)</version>
</dependency>
The script crawls through all the files but only puts the jar it finds into my local respository and overrides the jar that was installed before.
The question would be if there is a way to achieve this through the help of a script.
Greetings
[edit:] After the comments by Essex Boy I've adapted my script to this:
SET @libPath="C:\path\to\lib"
SET @groupId="group.id.custom.lib"
SET @artifactId="custom-lib"
SET @version="1.0"
SET @packaging="jar"
SET @tempDir="C:\Temp\temp-dir"
SET @tempJar="temp.jar"
if not exist %@tempDir% mkdir %@tempDir%
cd %@tempDir%
del *.* /f /q
for /r %@magicDrawLib% %%i in (*.jar) do copy %%i %@tempDir%
for /r %@tempDir% %%j in (*.jar) do jar -xvf %%j del %%j
jar -cvf %@tempJar% *
mvn install:install-file ^
-Dfile=%@tempJar% ^
-DgroupId=%@groupId% ^
-DartifactId=%@artifactId% ^
-Dversion=%@version% ^
-Dpackaging=%@packaging%
Which seems to be working. I have to test the resulting Maven dependency to verify it.
Upvotes: 0
Views: 2160
Reputation: 7950
Firstly overwriting an existing jar with another defeats the object of using maven. All artifacts are supposed to be imutable (never changing). If you have a new jar it is a new version and should be added to your repository as such.
I think the script is a good idea.
If more than one person is sharing this repository then I would create your own shared repository https://www.jfrog.com/open-source/ is an excellent free one.
Upvotes: 1