I develope a jsp using eclipse, and try to call a jar file that I made.
The problem is that when I import the jar into the jsp page, I get an error says:
'The import myClass cannot be resolved'.
I included the jar in the Libraries in the build path. The class I'm trying to use in the jar is public.
I also read that running a 'clean' action (project -> clean) can solve it, and I did it. It didn't solve
I still get The import cannot be resolved error.
I'll be glad to here any idea, I didn't find a solution yet :-(
Hi, thanks for your advice.
Well, that is what I put my jar inside the lib in the web project, but it is still not working:
Actually, the jar contains some classes that some of them are recognizad in the "import",
but the class that I built and want to use is not recognized.
I don't know why, driving me crazy !
The both classes are public.
Thanks for any help
ok, so I tried it again an now I put my class in import:
and I can use it, I did:
document.write(<%=hasp_demo.main(new String) %>); just for a test - it autocompletes the methods in hasp_demo,
so I understand that it recognizes this class.
the problem is that in the import line, it red underlines the "hasp_demo" and when I pass the mouse over the red line, it
writes: "The import hasp_demo cannot be resolved". Moreover - when I run my jsp file, I get exception:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
The import hasp_demo cannot be resolved
An error occurred at line: 11 in the jsp file: /test.jsp
hasp_demo cannot be resolved
8: <title>Insert title here</title>
11: document.write(<%=hasp_demo.main(new String) %>);
The short explanation is "because classes that are not in packages don't work as JSP beans (and in some other contexts)", the longer explanations have to do with code maintenance reasons (like polluting the global namespace) and some arcane JVM internals.
Good morning guys, I'm back :-)
Well, I created again my jar, but now - as you suggested - I put my class inside of a new Package. (Not the default package, but a new one).
The problem is that I can't run it in console - I write: java -jar myJar.jar (like I did before - when the class was out of package), and I get:
Exception in thread "main" java.lang.NoClassDefFoundError....
Any idea ?
so write now it seem that my class is recognized !
BUT.... when I run my jsp, I get an exception that I have no clue what it says:
The server encountered an internal error () that prevented it from fulfilling this request.
Hi , thanks for your reply.
I changed the class inside the jar, to start with capital later. I thought that it has something to do with it.
my class: HaspDemo is inside the package: Hasp.
my code inside the jsp is: