I am trying to run spring jar executable based on the documentation provided here . I expect the resources to be copied to the executable jar at startup
mvn clean package
This is how I run .jar in my project folder
./my-application.jar
In my project, I have a batch process that starts at startup, where I try to load a resource defined in
src/main/resources/batch/request_customers.csv
This is how I load application.properties resource
data.customers.input=classpath:batch/request_customers.csv
the class
import org.springframework.util.ResourceUtils;
@Component
public class DataManager {
@Value("${data.customers.input}")
private String usersExistingData;
public File jsonCustomerData() throws FileNotFoundException {
return ResourceUtils.getFile(usersExistingData);
}
}
error log
s]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.groupon.batch.CustomerItemReader]: Factory method 'reader' threw exception; nested exception is java.io.FileNotFoundException: class path resource [batch/request_customers.csv] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/xxx/projects/myproject/target/myproject-0.0.2-SNAPSHOT.jar!/BOOT-INF/classes!/batch/request_customers.csv; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'job' defined in class path resource [com/mycompany/batch/BatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.Job]: Factory method 'job' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1' defined in class path resource [com/mycompany/batch/BatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.Step]: Factory method 'step1' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reader' defined in class path resource
I also tried the following way
data.customers.input=src/resources/batch/request_customers.csv
data.customers.input=batch/request_customers.csv
When I launch the application using my IDE and spring plugin, resources are loaded without any problems. But crash when starting an executable bank using. / my -application.jar
, , .
UPDATE
, . .
BOOT-INF/classes/batch/request_customers.csv
jar , - , . .
StringBuffer = StringBuffer();
BufferedReader inputStream =
new BufferedReader(new InputStreamReader(resourceloader.getResource(file).getInputStream()));
String line = null;
while ((line = inputStream.readLine()) != null){
buffer.append(line);
}