Not able to import jar files in JSP code - java

I have jar files which I constructed using command
jar -cf Generic.jar /java/mypackage/*.class
There are three classes in the Generic.jar
mypackage is the name of package I named so as to include my class files and create a jar file.
latter I copied the Generic.jar in the WEB-INF/lib of Glassfish
In JSP I imported these jar files using
<%# page import="java.mypackage.GenericTree;" %>
<%# page import="java.mypackage.GenericTree1111;" %>
<%# page import="java.mypackage.GenericTree2222;" %>
But I am getting the following error. Can anyone suggest whats going wrong?
HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NoClassDefFoundError: java/mypackage/GenericTree
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.
GlassFish Server Open Source Edition 3.0.1

Are you sure your command succeeded? It does not work for me when the path starts with slash. So, first remove leading slash, i.e. command should look like the following: jar -cf Generic.jar java/mypackage/*.class
Package name that starts from word java is not for you. It is for JDK classes only. Such classes cannot be loaded by regular class loader, only by bootstrap one. So, rename your package. It should look like com.mycompany.myprogram.foo.bar
Now create the jar file using command I wrote and then test the result: run jar vft and see that output looks like
1612 Thu Feb 03 14:44:34 IST 2011 com/mycompany/myprogram/Hello.class
Pay attention on the path. It must contain your package.
If everything is working copy your jar under WEB-INF/lib and enjoy. Good luck.

Related

unable to find servlet(.java) files converted from jsp

I am using eclipse luna and tomcat version 7. I have written few jsp files and executing them on tomcat easily. I have read that jsps are converted into servlets at run time and you can locate them in tomcat/work/catalina/localhost/project name and further. My project name is quizilla and there exist a folder named quizilla-1.0-SNAPSHOT, but this folder is empty. What is the reason and where can i find those .java files. I have attached the screen shot of the folder as wellAs I am in right directory in search of my java files, but the folder is empty. So what should i do
You are using Tomcat from Eclipse, so the work directory is:
projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
or something like that (if you haven't changed the Server configuration via Eclipse).
Add
<%=getClass().getResource(getClass().getSimpleName() + ".class")%>
to one of your JSP pages to detect where Tomcat has generated the servlet.

SEVERE: PWC6117: File not found - Jetty

We are facing this issue in production environment but unable to track it out.
Technology: JSP/Servlets,
Jetty Server Version: jetty-distribution-8.1.15,
Following is exception, what we are getting in Jetty Logs:
2014_08_10.stderrout.log.05300:
SEVERE: PWC6117: File "%2Ftmp%2Fjetty-0.0.0.0-8090-ExpireApp.war-_ExpireApp-any-%2Fwebapp%2FExpiry.jsp" not found
The application worked fine before but end users are unable to access .jsp file and we need a restart for the same but we want to get it resolved. Please help
We see things like this when there is a process in the background that cleans up tmp directories and things like that. The jsp gets compiled there and then gets scraped away and the JSP impl still believes it to be there resulting in an error like this.
Oh Sorry, i have not shared answer before.
Here it is:
Issue: By Default Jetty unpacks .WAR file in /TMP directory of Linux. The /TMP directory got cleared after some days by some scripts which i am unable to find.
Resolution: I have created another directory named ‘work’ in jetty, where Jetty will unpack .WAR by default, thereby preventing jetty to unpack contents in /TMP.
So issue was unpacked contents got deleted and after restart it got created again. This time i checked unpacked content before restarting so i got what issue actually was :)
Thanks all for help
I have meet the same SEVERE: PWC6117: error, the reason is
I changed below code(Spring mvc controller)
model.addAttribute("foo", foo);
return "foo";
to just
return model;

Applet on Website seems to hate Packages

So I made an Applet (not JApplet) and proceeded to upload it to my website. I put all of my .class files into a package, exported the project from eclipse to a .jar, and uploaded that to the public_html folder of my website.
In my HTML code, I put
<applet ARCHIVE="BallShooter.jar" CODE="BallShooter" width=500 height=500> </applet>
However, it seems that I kept on getting the error "ClassNotFoundException"
If I reupload the .jar WITHOUT the package, it worked fine. Could somebody please explain to me how to fix this?
For those who are wondering, this is the structure of the things in the website
/public_html/myAppletJar/myPackage/a.class
/public_html/myAppletJar/myPackage/b.class
/public_html/myAppletJar/a.png
/public_html/myAppletJar/b.png
Check all these points:
if the applet class is BallShooter, and is in the package kikiotsuka, then its source code must start with the line package kikiotsuka;. The full name of the class is thus kikiotsuka.BallShooter.
in the jar file, you should thus have a directory named kikiotsuka at the root, and this directory must contain a file named BallShooter.class
since the name of the class is kikiotsuka.BallShooter, that's what the code attribute of the applet HTML element must contain: code="kikiotsuka.BallShooter" width=...

How import a .java file into a JSP page?

this is my first time trying to use java for backend web systems.
I have been reading up some guides on how to do this, and thus far i understand the following points:
I am not allowed to import .java files, but rather, import the class files.
<%# page language="java" import="somefile.*"%> this is how i import a package.
After importing a package, I am required to create an instance of the class.
However, I am confused with a few things.
I now have a Dynamic Web Project, developing in Eclipse IDE and using TomCat7.0 apache.
I have a directory
Java_Resources/src/somepackage/
and some .java files in the above directory.
Question 1, in Eclipse, when I run these files, they are automatically compiled. Where does these class files go?
Question 2, when I run the following code, I recieved some errors. What am I doing wrong? Is it because I do not have my class files in the right directory?
<%# page language="java" import="twitter.*"%>
<%
JavaFile jf = new Javafile();
String result = jf.searchTweets("someString");
System.out.println(result);
%>
Error report:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /hello.jsp at line 10
7: <%# page language="java" import="twitter.*"%>
8:
9: <%
10: Javafile jf = new JavaFile();
11:
12: String result = jf.searchTweets("someString");
13: System.out.println(result);
Thank you for your time and effort.
note: I have read the following links, but they do not seem to provide a solution on how to write your own .java files and import these classes into your jsp files.
http://www.jsptut.com/
How do you import classes in JSP?
http://www.coderanch.com/t/288534/JSP/java/importing-class-file-jsp
EDIT: I found my own answer.
This is my original directory
As you can see, my WEB-INF/lib is empty.
All that was required to do, is to move the relevant .jar files into this directory.
Note: I have already imported the relevant .jar files to the Eclipse project, but it seems that I need to move them into WEB-INF/lib on top of importing them into the project.
Thank you to all that helped answer my question.
This is my final directory image
Only classes may be imported into a .java file, and a JSP "compiles" to a .java file, so this requirement holds for JSP files too.
From a quick glance at the API, it seems that your import is formatted correctly; but, you are importing the wrong namespace. The javadoc for the twitter4j API indicates that you should be importing "twitter4j" namespaces, not "twitter" namespaces.
Question 1, in Eclipse, when I run these files, they are automatically compiled. Where does these class files go?
The class files go inside WEB-INF/classes directory.
Question 2, when I run the following code, I recieved some errors. What am I doing wrong? Is it because I do not have my class files in the right directory?
Perhaps you have forgotten to put twitterXXX.jar (or whatever it is called) into WEB-INF/lib directory.

Error in Tomcat Server while reading JSP file

I have placed Commonsfileuploadservlet folder inside webapps. And inside that folder i have written upload.jsp
After switching on the tomcat server, while attempting to run the jsp file, the below error comes in the browser.
What might be the cause?
The requested resource (/Commonsfileuploadservlet/upload.jsp) is not available.
As requested by OP, I am reposting the comment which solved the problem as an answer:
Anything in server logs? Check for most recent log updates in Tomcat/logs folder. It might contain detail about startup errors.

Categories