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.

NoSuchFileException

See original GitHub issue

Hi,

I’m trying to run your sample in IntelliJIdea, but get this error when I run it: Caused by: java.nio.file.NoSuchFileException: jte/hello.jte

I have this in my pom.xml:

<dependency>
            <groupId>gg.jte</groupId>
            <artifactId>jte</artifactId>
            <version>1.0.0</version>
        </dependency>
...
 <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/jte</sourceDirectory>
                    <targetDirectory>${basedir}/jte-classes</targetDirectory>
                    <contentType>Html</contentType>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>precompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

And in the main function:

CodeResolver codeResolver = new DirectoryCodeResolver(Path.of("jte")); // This is the directory where your .jte files are located.
        TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html); // Two choices: Plain or Html
        TemplateOutput output = new StringOutput();
        templateEngine.render("hello.jte", 1, output);
        System.out.println(output);

How does compiler find template files? What is the path Path.of("jte") relative to? Are the .jte files source or resources?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
casidcommented, Sep 13, 2020

Hey @mahdix, the TemplateEngine can now be created so that the application class loader is used. This way it should be possible to bundle templates into the application JAR!

At least it worked in my test setup 😃 Here’s a working example: https://github.com/casid/jte/tree/master/jte-runtime-cp-test

TemplateEngine creation is even easier that way! TemplateEngine.createPrecompiled(ContentType.Html);

And in pom.xml, you’d need to change the target directory to: <targetDirectory>${basedir}/target/classes</targetDirectory>

Would you mind to check it out and see if this works for you? I’d then release 1.1.0 shortly after.

If you want to try it you’d need to change ${jte.version} in your pom.xml to 1.1.0-SNAPSHOT and build jte locally.

To build the jte:

  • Clone this repository
  • Run mvn clean install in the project’s root directory

Hope it works! Also, thanks for your suggestion, I really like this new way of running in production 😃

1reaction
casidcommented, Sep 14, 2020

@mahdix I’ve just released 1.2.0. With this version it is even easier to achieve precompiled templates with application class loader:

https://github.com/casid/jte/issues/7

Just in case you’re interested 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

NoSuchFileException (Java Platform SE 8 ) - Oracle Help Center
Checked exception thrown when an attempt is made to access a file that does not exist. Since: 1.7; See Also: Serialized Form ...
Read more >
How to solve the java.nio.file.NoSuchFileException?
The problem is that your default directory at application startup is not what you think it is. Try adding the following line to...
Read more >
How to resolve error java.nio.file.NoSuchFileException
This error occurs most commonly when a file name, directory name or file path has been incorrectly specified when using the file handling ......
Read more >
NoSuchFileException - Android Developers
public NoSuchFileException (String file, String other, String reason). Constructs an instance of this class. Parameters. file, String : a string identifying ...
Read more >
NoSuchFileException - Kotlin Programming Language
An exception class which is used when file to copy does not exist. NoSuchFileException( file: File, other: ...
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