question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to read files from directories other that /src/main/resources

See original GitHub issue

I ran into this issue today when I was trying to add a css file that resided in my java project that I’m using j2html in. I was trying to do this using the following code.

Tag css = styleWithInlineFile("style.css");

However, css was continually being set to null. Looking through the code, I think I see why. In InlineStaticResource.java, when the getFileAsString method is called, the file path is constructed using InlineStaticResource.class.getResource(path). However, I believe this method is constructing and incorrect file path. From how I understand the line above to work, it’s basically only looking in the directory of InlineStaticResource.java and below. Which means j2html effectively can’t see any files outside of this directory.

I’m using java 8 inside eclipse along with Maven.

Please let me know if my understanding is correct or if I should be able to add a css file given the current code.

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Apr 12, 2017

@mrtinkz, @austinlostinboston What do you think about #50 ?

0reactions
tipsycommented, Apr 25, 2017

Try it out in

<dependency>
    <groupId>com.j2html</groupId>
    <artifactId>j2html</artifactId>
    <version>0.99</version>
</dependency>

if you haven’t 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't read from my src/main/resources directory - Stack Overflow
I can read the file from the resources directory with an InputStream, but I'm trying to avoid doing that way. The file variable...
Read more >
Java - Read a file from resources folder - Mkyong.com
In Java, we can use getResourceAsStream or getResource to read a file or multiple files from a resources folder or root of the...
Read more >
Read a File from Resources Directory - HowToDoInJava
Learn to read a file from the resources folder in a Java application. We will learn to read the file present inside the...
Read more >
how to access resource folder file in mule 4 as getting error as ...
In file read I am able to get but for java component It is not recognising ... is how to read files from...
Read more >
Read a File From the Resources Folder in Scala - Baeldung
In this tutorial, we'll learn different approaches to reading a file from the resources folder in Scala.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found