Add classpath pointing to jars in Maven - maven

I have lot of external jar files that needs to be pointed in the project. Since these jar files will be available on end users system by default, I am maintaining config parameter file which will hold that directory location.
Is there any way to include this classpath in maven?

Related

Read file in pom.xml from a dependency - Maven

has any way to read a file inside on dependency?
For example, I have my pom.xml and I using the maven-antrun-plugin to copy the .war generated to my remote server, but i need to pass two attributes: keyfile and knowhosts, today, I have these files inside my project, in java/resources path, but i would like to know if has any way to wrapper these files in a .jar, and use this as dependency in my project, and read theses files from this dependency.
Thank very much!
I'm not sure if I understand your question correct so let's summarize your question how I understand it:
You have a project based on Maven and build a WAR file for deployment on an application server.
In your current situation you have two files in your projects resource folder that you read from/with your project code.
You want a situation that the two files are packed in a custom jar file and put that file as dependency on the classpath/in the pom file. The question is if you can still read them from your project code.
Yes, that's possible. If you add the dependency to the dependency list in the pom file the file will be also included in the war file and then available on the classpath of your application.
Only if your project jar is marked as sealed it won't work (Sealed jar files only can read classed from it's jar file and I think that is also not possible for resource files).
If this is also a good solution is more complex to answer and I can't answer that with the current limited info I have about your project.

Adding external jars in classpath to an executable WAR file

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.

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

In maven how to create jar where lib is outside?

How do I configure my pom.xml so that maven generates a jar where the lib folder and all it's jars are a separate folder outside of my generated jar?
What you need here is to use :
Maven Jar Plugin to copy your generated jar to a different location you want.
Maven Dependency Plugin to copy your dependent jars to a location that you want.
You need to use the outputDirectory property in both the plugins to define the required location where you would like the jars to be copied to, respectively.
Here is an example of the configuration you would add in your POM.

Maven - load all jars inside a system folder

Is there a way we can load all the jar files inside a folder, as dependencies in a maven project.
So that, I do not have to mention each and every jar files in pom.xml, just mention or tell maven to pick all the jar files from folder 'x' and build the system.
Is this supported by maven?
I think this is supported by ant. Not sure whether gradle supports either.
In
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
you see that you can reference single files, but there is no mechanism for directories. As I mentioned in the comment, using the disk is discouraged in general.
If you need the same set of dependencies in many projects, you can write a pom for that and use it (as parent or by setting a dependency to it).

Resources