Exclude a file from dependency - maven

I am using jython-slim-2.7.2.jar in my Spring Boot application. This JAR file contains a file I don't need. I want to remove that file without manually deleting it (by opening the JAR from local repository and then deleting the file). How can I configure Maven to delete that file while building executable JAR?

Related

Sping Boot to generate jar with only class files and place dependency in a separate location

I would like to create jar's with only class files for my project and to copy all it's dependency into a separate folder and put these in docker.
You can copy all dependency into a separate folder using maven's copy-dependencies
Using maven configuration profile and exec tag's you can create jar's only with class files.
Use maven manifest tag in your pom.xml, So that you can add entries in your manifest files to locate where is the jar placed. So that when application boot's the jar will take dependency from that location.
While creating docker files, make sure to copy all the dependencies. You can use docker volumes

Spring boot jar file, not reading application.properties in config folder

I have a jar file from a Spring Boot project created with "mvn clean install". I created a folder named "config" and placed the "application.properties" in that folder
However the application is still not using the external application.properties file, but it's using the one inside the jar file. How can I make it use the external application.properties if it exists.

Could not open ServletContext resource in Spring boot application [duplicate]

I have a Spring Boot application using Google Pub Sub API. I need to inject Google credentials and other properties using file credentials.json. I put the file in my src/main/resources (otherwise, it will not put the file in the built jar) like this:
spring.cloud.gcp.credentials.location=file:src/main/resources/credentials.json
However, when I build the jar, this file is placed in the root directory and this path is no longer valid. So I am able to run my application from Eclipse, since by the that time, the file is still in my resources directory but I can't run it as a standalone jar after built because the path is suddently just file:credentials.json.
Is there some easy way how to specify the path as relative so it works both in IDE and when running my jar? I can inject the path through env. variables but I would do so only if absolutely necessary.
If you use the classpath prefix then Spring will look for the file on your classapth.
If you put the file in src/main/resources then Maven will, by default, copy it to the root of your classpath and it will then be addressable as follows:
spring.cloud.gcp.credentials.location=classpath:credentials.json
This should hold true whether ...
You are running in your IDE; your IDE's Maven integration will copy the file from src/main/resources to the root of your classpath - typically target/classes
You are running a built JAR; Maven will copy the file from src/main/resources to the root of your JAR

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?

Resources