#GetResource

8 messages · Page 1 of 1 (latest)

old nimbus
#

Hi,
Im deploying my app, getting core and web. Core is dependency.
Having my core and web folders in same folder.

I try to get my json file in src/main/resources so i set this

        URL resourceUrl = getClass().getClassLoader().getResource("/initialiseCategories.json");
        File jsonFile = new File(resourceUrl.getFile());

But it doesn't success to get the file...
I tried to add jsonfile in core and in web too but it doesn't find it..

FROM maven:3.8.3-openjdk-17 AS build
COPY . .
WORKDIR /Cregister
RUN mvn clean install
WORKDIR /CRegisterWeb
RUN mvn clean install
WORKDIR /
FROM eclipse-temurin:17-jdk
COPY --from=build CRegisterWeb/target/cregister-web-0.0.1-SNAPSHOT.jar demo.jar
ENTRYPOINT ["java", "-jar", "demo.jar"]
copper oysterBOT
#

This post has been reserved for your question.

Hey @old nimbus! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

rocky wind
#

Resources aren't files, you can't access them with File API. They're inside your .jar

oak breach
#

You have to use getClass().getResourceAsStream()

#

You can pass the stream to objectmapper

old nimbus
copper oysterBOT
# old nimbus Thanks, its working

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.