Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to compile with module-info.java #337

Closed
erwire opened this issue Mar 25, 2024 · 2 comments
Closed

Failed to compile with module-info.java #337

erwire opened this issue Mar 25, 2024 · 2 comments

Comments

@erwire
Copy link

erwire commented Mar 25, 2024

Hi! I'm new to Java development, so I apologize in advance if the question turns out to be stupid, but I couldn't find an answer to my question on the Internet.
I need to create an HTML page by template to send it for printing via JavaFX modules. However, if the module-info file is present in the project, then an error appears during the compilation of the project:

G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:2: error: package com.example.demo2 does not exist
import com.example.demo2.Body;
                        ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:6: error: package gg.jte.html does not exist
	public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Body page) {
	                                     ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:6: error: package gg.jte.html does not exist
	public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Body page) {
	                                                                               ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:6: error: cannot find symbol
	public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Body page) {
	                                                                                                                    ^
  symbol:   class Body
  location: class JteexampleGenerated
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:28: error: package gg.jte.html does not exist
	public static void renderMap(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, java.util.Map<String, Object> params) {
	                                        ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:28: error: package gg.jte.html does not exist
	public static void renderMap(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, java.util.Map<String, Object> params) {
	                                                                                  ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:11: error: package gg.jte.runtime does not exist
			if (gg.jte.runtime.TemplateUtils.isAttributeRendered(__jte_html_attribute_0)) {
			                  ^
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:29: error: cannot find symbol
		Body page = (Body)params.get("page");
		^
  symbol:   class Body
  location: class JteexampleGenerated
G:\tmp.work\demo2\jte-classes\gg\jte\generated\ondemand\JteexampleGenerated.java:29: error: cannot find symbol
		Body page = (Body)params.get("page");
		             ^
  symbol:   class Body
  location: class JteexampleGenerated
9 errors

	at gg.jte@3.1.9/gg.jte.compiler.java.JavaClassCompiler.runCompiler(JavaClassCompiler.java:49)
	at gg.jte@3.1.9/gg.jte.compiler.java.JavaClassCompiler.compile(JavaClassCompiler.java:38)
	at gg.jte@3.1.9/gg.jte.compiler.TemplateCompiler.precompileClasses(TemplateCompiler.java:114)
	at gg.jte@3.1.9/gg.jte.compiler.TemplateCompiler.precompile(TemplateCompiler.java:94)
	at gg.jte@3.1.9/gg.jte.compiler.TemplateCompiler.load(TemplateCompiler.java:50)
	at gg.jte.runtime@3.1.9/gg.jte.TemplateEngine.lambda$resolveTemplateOnDemand$0(TemplateEngine.java:354)
	at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1916)
	at gg.jte.runtime@3.1.9/gg.jte.TemplateEngine.resolveTemplateOnDemand(TemplateEngine.java:347)
	at gg.jte.runtime@3.1.9/gg.jte.TemplateEngine.resolveTemplate(TemplateEngine.java:337)
	at gg.jte.runtime@3.1.9/gg.jte.TemplateEngine.render(TemplateEngine.java:210)
	at com.example.demo2/com.example.demo2.Main.main(Main.java:16)

There is no error without the module-info.java file and everything functions as expected.
Please tell me how to modify the module-info file.java or my code to make project compiles without an error? Thanks!

Current file module-info.java is

open module com.example.demo2 {
    requires javafx.controls;
    requires javafx.fxml;
    requires gg.jte;
    requires gg.jte.runtime;
}

Project structure:

image

Executable code:

        CodeResolver codeResolver = new ResourceCodeResolver("jte");
        TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);
        TemplateOutput output = new StringOutput();
        templateEngine.render("example.jte", new Body("Hello", "World"), output);

JDK Version - 17

JTE Version - 3.1.9

@casid
Copy link
Owner

casid commented Mar 27, 2024

Hi @JahnGeor,

I haven't used Java modules seriously so far, so have no pointer for you in the right direction.

I guess the Java Compiler would need a hint to allow access of your module, when compiling jte files.

There is this method TemplateEngine#setCompileArgs. Maybe you can specify there that this module is accessible?

@erwire
Copy link
Author

erwire commented Mar 27, 2024

Hi @JahnGeor,

I haven't used Java modules seriously so far, so have no pointer for you in the right direction.

I guess the Java Compiler would need a hint to allow access of your module, when compiling jte files.

There is this method TemplateEngine#setCompileArgs. Maybe you can specify there that this module is accessible?

First of all, I would like to thank you very much for your response! After doing some research, I found the "precompilation" feature on the "gg.jte" web page and decided to use it through the "Maven" plugin. Everything is working as expected!

@erwire erwire closed this as completed Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants