I've a jar library that needs to be read as an argument to my class MyProject
and a respective app property in application.properties my.customJar=/WEB-INF/lib/myJar.jar
to use the jar in my local app run and it works well locally but it fail on the pcf cloud. I did some changes & respective to this property, I've tried adding an override in cloud environment application-dev.properties i.e. my.customJar=${project.basedir}/src/main/webapp/WEB-INF/lib/myJar.jar
I've also tried with relative path my.customJar=./src/main/webapp/WEB-INF/lib/myJar.jar
but neither of them appear to have worked.
The problem arises specifically when I send this code to the pcf cloud I am getting FileNotFoundException. And it fails there with error mentioned below. Can anyone please guide me with how can I set the path for the other profiles. Also, please let me know if there is any more convenient way to do this as well?
Note: I am using multiple spring profiles.
Error I am getting
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myController' defined in file [/home/abc/app/BOOT-INF/classes/com/example/myController.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jarUserBean' defined in class path resource [com/example/configuration/CommonConfigs.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.myJar.api.MyProject]: Factory method 'jarUserBean' threw exception; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/lib/myJar.jar]
2021-08-27T07:53:53.647+01:00 [APP/PROC/WEB/0] [OUT]
Here, the jarUserBean is a bean created using the jar's insputStream i.e.
@Value("${my.customJar}")
private String pathToJar;
@Bean
@ConditionalOnProperty(prefix = "my", name = "customJar")
public MyProject jarUserBean() throws IOException, ProjectInvalidException, InterruptedException {
Resource resource = loader.getResource(pathToJar);
InputStream is = resource.getInputStream();
return new MyProject(is);
}