Adding external jars in classpath to an executable WAR file - spring-boot

I have a spring-boot executable WAR file which I launch using java -jar . Now I want to add the flexibility of having it reference JAR files outside of WAR file so as to enable customization of code.
So e.g. I want to have to flexibility of having a jar being present in d:\mylib\my.jar and reference the classes in my.jar from code within the WAR file.
Is this possible?
If yes, how?
I tried adding Class-Path and even editing the spring-boot-lib path in manifest.mf but no use.

Related

spring boot jar not picking profile specific properties outside jar

I have a spring boot jar(name : myjar) located in the directory structure
D:/hello/myjar
The fat jar contains profile specific application.properties in src/main/resources for e.g. application-local.properties
I want to override the attributes defined in the application-local.properties inside the jar with application-local.properties outside the jar
Hence I created application-local.properties and kept it in the same folder as jar i.e. D:/hello
However when I run my jar using the command :
java -jar -Dspring.profiles.active=local D:/hello/myjar.jar
it still picks the properties which is inside the jar. Am I missing something ?
Try this use -D before -jar
java -Dspring.profiles.active=local -jar D:/hello/myjar.jar
let's see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config
I think it was more of point that from where I was running my jar from the command prompt.
If I run the jar from the folder where my jar is present, it does picks the profile specific files present outside the jar.

WildFly - Adding JARs to classpath

I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.

How to add a xml a file as dependency using gradle?

I have a project build on gradle and it has a directory src/main/dist/deploy. In deploy folder there is a xml file. This xml file i want to add as a dependency in the jar file which my build.gradle is generating. This jar i am adding in the lib folder of another project that has a dependency on my gradle project. The other project is built using ant. When classes bundled in gradle jar are loaded from ant project they are unable to read that xml file from the gradle jar.
The standard java plugin does not look in src/main/dist/deploy for resources.
You should either move the xml file into java plugin's standard resource folder src/main/resources, or add the dist/deploy folder to your main sourceSet's resource list.

How to put a directory first on the classpath with Spring Boot?

I am building my Spring Boot application using Maven, so I can start it with:
java -jar myjar-1.0-SNAPSHOT.jar --spring.profiles.active=prod
I want to have a directory first on the classpath that would allow me to place some files on the filesystem without having to unzip the jar to change them.
I have tried using loader.path, but it does not seem to work.
java -Dloader.path="config/*" -jar myjar-1.0-SNAPSHOT.jar --spring.profiles.active=prod
The config dir is a subdirectory of where the jar is located. I am trying to load a keystore file which is injected as a Resource in my application. There is such a file in the src/main/resources, but that only works in my IDE, not when packaged as a jar. So I want to put a file first on the classpath so that that one is found first on the classpath.
You can use loader.path but only if the Main-Class is PropertiesLauncher (so it depends how you built the JAR file). Maybe you need to re-build the JAR with packaging=ZIP in the Boot plugin (e.g. docs here)? Can you not set the path to the keystore as a "file:" URL?

how to make maven war:explode do not pack a jar file

I'm new to maven.
I'm now working on a multi module maven project, when i use maven war:exploded ,it will packaging classes files to WEB-INF/lib/***SNAPSHOT.jar.
Is there any way to leave the classes files under WEB-INF/classes , for when java file changes, there is no need to replace the whole jar file?
Thanks

Resources