Reputation: 46137
How can I embed one of the JRE libraries (say, rt.jar) into my WAR using Maven?
Is there a maven plugin/command to do so?
Upvotes: 1
Views: 3839
Reputation: 27880
As adarshr above has already pointed out, it's not a good idea to provide your own JRE jars.
Just in case you need to include some other jar you don't find on the maven repositories, you can add downloaded jars following these steps:
Put rt.jar in the maven local repository, with for instance
mvn install:install-file -Dfile=myjar.jar -DgroupId=some.group -DartifactId=someartifact Dversion=1.0 -Dpackaging=jar
Place a dependency to this rt.jar on the pom.xml
<dependency>
<groupId>some.group</groupId>
<artifactId>someartifact</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
When building the artifact, someartifact.jar will be included in it.
Upvotes: 2
Reputation: 718836
Putting an rt.jar
file into your WAR file is not going to cause Java to use it. The web container's classloader should always try the system classloader before looking at the JARs in your webapp, and the system classloader will use the rt.jar
on the boot classpath; i.e. the one that is in the JRE installation directory.
This is just as well. If the Java runtime used your rt.jar
it could get into an awful mess. Code in your rt.jar
could try to make calls to native methods that are not implemented in the Java executable, or it could make calls to internal methods whose behavior and/or signatures have changed in an incompatible way.
If you are planning to do this to "fix" some behavior in the class library, my advice would be:
Upvotes: 6
Reputation: 62593
I don't think that's a good idea. rt.jar
is part of your JRE and is best kept separate.
Upvotes: 4