开发者

Not able to import jar files in JSP code

开发者 https://www.devze.com 2023-02-09 09:04 出处:网络
I have jar files which I constructed using command jar -cf Generic.jar /java/mypackage/*.class There are three classes in the Generic.jar

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 preve开发者_如何学Pythonnted 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


  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
  2. 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
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消