0

I am developing applet code using jsp page.

    <APPLET 
      id = "app"
      codebase="<%=request.getContextPath()%>/lib/" 
      code="com.myDemo.test.RunApplet.class" 
      width=100 
      height=50 
      archive="myApp1.jar, myApp2.jar">    
   </APPLET>

My directory structure is :

DemoProject
  -- src (some classes & packeages)
  -- build
  -- WebContent
       -- css (some css file)
       -- script (some js file)
       -- WEB-INF
            -- jsp(some jsp file)
                 -- myApplet.jsp
            -- lib
                 -- myApp1.jar
                 -- myApp2.jar

When i execute myApplet.jsp it will throws the error

java.lang.ClassNotFoundException:com.myDemo.test.RunApplet.class

I had also apply

codebase = "."
codebase = "classes"
codebase = "classes/"

but still ClassNotFoundException.

Keval Trivedi
  • 1,290
  • 2
  • 13
  • 29

2 Answers2

2

Note that anything in the WEB-INF folder is only readable to the back-end servlet, not by anything running in the browser including the applet[1].

If the two jars in the lib folder are only used by the applet, you can move the folder up to webcontent level. If your backend also uses them, you'll have to either copy them or create a servlet to serve them to the front-end.

[1]What is WEB-INF used for in a Java web application?

billc.cn
  • 7,187
  • 3
  • 39
  • 79
  • 1
    Thank goodness someone who saw this question realized what the likely problem was here. :) The OP could try and fetch those Jars directly in the browser address bar to confirm your analysis. – Andrew Thompson Dec 21 '15 at 20:28
  • @billc.cn Thank you for rectified the problem and give me the solution. – Keval Trivedi Dec 22 '15 at 05:21
0

You must reference all the jar in < APPLET tag>

like you do:

archive="myApp1.jar, myApp2.jar"

beware of the location of your jars in archive :

How to specify correctly codebase and archive in Java applet?

You then must check all dependencies, and include them, one by one:

Solution 1 (if not too many jars): try, detect exception (like this one: com.myDemo.test) , include the jar, and so on.

You must give at least every dependencies.

If your code is rather short (principle for applet), it gives shorter download.

Solution 2 : use some tool: jaranalyser, ...

How to list dependencies of a JAR

Solution 3: very simple, but gives very big jar: include everything in one jar

Community
  • 1
  • 1
  • can you explain it briefly? which kind of dependencies that i have to check! and how to reference all the jar? – Keval Trivedi Dec 21 '15 at 13:04
  • I checked RunApplet.class is exist in myApp1.jar and As per my requirement i can not include everything in one jar. – Keval Trivedi Dec 21 '15 at 13:15
  • @KevalTrivedi , the exception says jvm can not find it. It is the first problem to solve : see link about locations. Second: put at least the jars you need, or refactor them (special jar with least classes). I did that once. – guillaume girod-vitouchkina Dec 21 '15 at 13:31