'Import jsp page coming from Tomcat plugin's WEB-INF folder
I have the following plugins that contain 3 files, a template.jsp file, a Properties.class file and a logout.properties file from the following folders
Files exist: WebApp/plugins/CustomPlugin/jsp/template.jsp
WebApp/plugins/CustomPlugin/WEB-INF/classes/utils/Properties.class
WebApp/plugins/CustomPlugin/WEB-INF/classes/resources/logout.properties file
The logout that JSP file contains the following page import line
<%@ page import="utils.PropertiesFile"%>
This is throwing the following error:
An error occurred at line: [14] in the generated java file: [C:\DEV\apache-tomcat-9.0.43\work\Catalina\localhost\MicroStrategy\org\apache\jsp\plugins\CustomLogout\jsp\logoutTemplate_jsp.java]
Only a type can be imported. utils.PropertiesFile resolves to a package
An error occurred at line: [5] in the jsp file: [/plugins/CustomLogout/jsp/logoutTemplate.jsp]
PropertiesFile cannot be resolved
2: <%@ page contentType="text/html; charset=UTF-8"%>
3:
4: <%
5: String logoutUrl = PropertiesFile.getProperty("LOGOUT_URL");
6: out.println(logoutUrl);
7: %>
8: <%@ page import="java.util.ResourceBundle"%>
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:482)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:605)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:378)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:326)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
However, if I move the Property.class file and the logout.properties file to the following path:
WebApp/WEB-INF/classes/utils/Properties.class
WebApp/WEB-INF/classes/resources/logout.properties file
There's no issue and the plugin works properly.
How would I reference the plugins folder in JSP so I can use it from the original location without having to move these two files?
WebApp/plugins/CustomPlugin/WEB-INF/classes/utils/Properties.class
WebApp/plugins/CustomPlugin/WEB-INF/classes/resources/logout.properties file
Solution 1:[1]
You're mentioning that PropertiesFile can't be imported, even though you have Properties defined. Is that what you meant? In that case, import what actually exists.
Also, however you build your application: If you expect something on the classpath at runtime, it must end up in /WEB-INF/classes (or in a jar in /WEB-INF/lib). It doesn't matter where the file is when it's in your development environment, as long as the buildscript makes sure that it ends up in a place where it can be found at runtime.
Apparently the contents of your plugins folder (of which I've never heard) do not end up where the runtime expects it. Fix that - either by moving the files in your dev environment, or by fixing your build script.
Which of the two options you pick will depend on the nature of this "plugins" environment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Olaf Kock |
