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.

1

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

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.
@billc.cn Thank you for rectified the problem and give me the solution.
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

3 Comments

can you explain it briefly? which kind of dependencies that i have to check! and how to reference all the jar?
I checked RunApplet.class is exist in myApp1.jar and As per my requirement i can not include everything in one jar.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.