0

I have a Maven-Springboot project setup. After doing a mvn install I can run the jar file in command prompt using java -jar <my-jar-file.jar>

There was a dependency to a jar say as-common-1.0.0.jar that is there in my-jar-file.jar. Now I want to override the version of this dependent jar at run time by giving an external jar. something like:

java -jar my-jar-file.jar using as-common-1.0.1.jar

I went through many SO posts like thisinclude external jar when running java -jar but they didn't help.

is it achievable?

EDIT: The issue we have is many of our applications depend upon one of our internal framework jar which gets updated(version) often. So every time changing the pom file and re-deploying all the apps doesn't look feasible to us. We want somehow the dependency of this particular jar is given at run time. Any idea regarding best possible way to manage this scenario?

mukund
  • 2,866
  • 5
  • 31
  • 41
  • The ***version*** of a jar file changes when new functionality is added, bugs are fixed, and (sometimes) old functionality is removed. As mentioned, it is neither reasonable nor sane to attempt to set a jar file version at run time. Instead of asking "how do I implement this solution?", consider stating "I want to solve this problem" and then asking "is there are reasonable solution for this problem>?" – DwB Mar 18 '19 at 12:26
  • The first thing is: If you use a lib you have to define that during build time via pom.xml and run your unit- and integration tests with it. The other question: Why is it changed that often that it causes such issues? Is it really needed to use all the time the most recent version? Furthermore in Spring Boot the classpath for starting will be done by a Starter which is inside the jar afterwards it will bootstrap the jar's in BOOT-INF/lib etc. so I don't see any way of it... – khmarbaise Mar 21 '19 at 10:18

1 Answers1

0

No, this is not sensible. At best, you would load classes twice and this may/may not work.

If you build a complete jar containing everything, you cannot swap content at runtime. You need to rebuild it.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Thanks. I have added the situation in edit section. Do you have any suggestion on that? – mukund Mar 18 '19 at 14:24
  • If you don't recompile, you may get runtime errors. I am not sure this is a good idea. I would rather question whether a central framework needs to change all the time and everybody needs to have the latest version of it. – J Fabian Meier Mar 18 '19 at 14:51