Create executable jar with maven where libraries can be replaced

Yupp

Is it possible to create an executable jar with maven where it is possible to replace a particular library with a newer version of the library without creating a new executable jar?

Pierre B.

Yes, you should define a provided dependency such as:

<dependency>
  <groupId>group-a</groupId>
  <artifactId>artifact-b</artifactId>
  <version>[1.0,)</version>
  <type>bar</type>
  <scope>provided</scope>
</dependency>

And make sure the dependency is available on your application classpath when running. For example using java command to run an executable jar:

java -jar MyExecutableJar.jar -cp /path/to/my/library.jar

You can then build your executable jar and run it. Not there are several shortcoming using this method:

  • Your will have to make sure your library is on the classpath when you'll execute your jar
  • Maven won't be able to know which version of the dependency to use, making your build less reproducible.
  • Maven requires each dependency to have a version. In my example I used [1.0,) to tell Maven I needed version 1.x or greater, you can adapt for your context.
  • If your library's API changes in a way that is not compatible with your current JAR, you will have no choice but to re-compile your jar

That being said, I don't know why you want to make a JAR with such conditions, but chances are you'll be better of rebuilding your JAR each time you need a newer version rather than keeping it, or change your dependency and project architecture. Doing this is against best practices and Maven design.

If you provide a little more context I'll try and explain more.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Including Signed Libraries in Executable JAR with Maven

From Java

How can I create an executable jar without dependencies using Maven?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How can I create an executable/runnable JAR with dependencies using Maven?

From Java

To create a single executable jar file Maven

From Dev

How do I create an executable jar file including dependencies where the main class is in Test, using Maven

From Java

How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __ Can someone makes the subject resolve/close please

From Java

Building executable jar with maven?

From Java

spring-boot Maven: How to create executable jar with main class?

From Java

How to create spring-based executable jar with maven?

From Dev

How to create a executable jar file using Maven and Netbeans

From Dev

How to create executable jar file from springboot - maven application?

From Dev

Maven - Create runnable jar and extract classes from dependent libraries

From Dev

How to make an executable .jar file using maven with local external libraries inside through pom without IDE?

From Dev

Create an executable jar

From Java

How can I create single executable jar in my gradle project

From Dev

maven external libraries - jar files

From Dev

How to create executable JAR with Gradle?

From Dev

Linking multiple C libraries to C create executable

From Dev

How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

From Java

Can I make an executable jar with "build-info" by "Spring Boot Maven Plugin"?

From Java

how can I reference a local file and include it with my maven assembly when creating an executable jar?

From Dev

Building an executable jar that can be published to maven local repo with `publishToMavenLocal` - spring boot project

From Java

IntelliJ GUI Designer Maven Executable JAR Export

From Dev

Generate executable jar with maven : class not found exception

From Java

How to generate executable jar in JavaFX with maven project

From Java

How to make an executable jar using maven?

From Dev

Creating a executable far jar with dependancies (gradle or maven)

From Java

Maven executable Jar throws error on start

Related Related

  1. 1

    Including Signed Libraries in Executable JAR with Maven

  2. 2

    How can I create an executable jar without dependencies using Maven?

  3. 3

    How can I create an executable JAR with dependencies using Maven?

  4. 4

    How can I create an executable/runnable JAR with dependencies using Maven?

  5. 5

    To create a single executable jar file Maven

  6. 6

    How do I create an executable jar file including dependencies where the main class is in Test, using Maven

  7. 7

    How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __ Can someone makes the subject resolve/close please

  8. 8

    Building executable jar with maven?

  9. 9

    spring-boot Maven: How to create executable jar with main class?

  10. 10

    How to create spring-based executable jar with maven?

  11. 11

    How to create a executable jar file using Maven and Netbeans

  12. 12

    How to create executable jar file from springboot - maven application?

  13. 13

    Maven - Create runnable jar and extract classes from dependent libraries

  14. 14

    How to make an executable .jar file using maven with local external libraries inside through pom without IDE?

  15. 15

    Create an executable jar

  16. 16

    How can I create single executable jar in my gradle project

  17. 17

    maven external libraries - jar files

  18. 18

    How to create executable JAR with Gradle?

  19. 19

    Linking multiple C libraries to C create executable

  20. 20

    How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

  21. 21

    Can I make an executable jar with "build-info" by "Spring Boot Maven Plugin"?

  22. 22

    how can I reference a local file and include it with my maven assembly when creating an executable jar?

  23. 23

    Building an executable jar that can be published to maven local repo with `publishToMavenLocal` - spring boot project

  24. 24

    IntelliJ GUI Designer Maven Executable JAR Export

  25. 25

    Generate executable jar with maven : class not found exception

  26. 26

    How to generate executable jar in JavaFX with maven project

  27. 27

    How to make an executable jar using maven?

  28. 28

    Creating a executable far jar with dependancies (gradle or maven)

  29. 29

    Maven executable Jar throws error on start

HotTag

Archive