• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

class file in jar works when invoked on local machine, but gets "class not found" when run from web

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello -
The java file (this version has code that requires signing commented out - at this point I am just trying to get a jar'd class file to work.)

import java.applet.Applet;
import java.awt.Graphics;
import java.io.*;
import java.awt.Color;

/**
*
* A simple Signed Applet Demo
*
*/

public class SignedAppletDemo extends Applet {

public String test() {

setBackground(Color.white);

//String fileName = System.getProperty("user.home") +
// System.getProperty("file.separator") +
// "newfile";
String fileName = "c:\\java\\newfile";
String msg = "This message was written by a signed applet!!!\n";
String s ;

try {

//FileWriter fos = new FileWriter(fileName);
//fos.write(msg, 0, msg.length());
//fos.close();
s = new String("Successfully created file (not) :" + fileName);

} catch (Exception e) {
System.out.println("Exception e = " + e);
e.printStackTrace();
s = new String("Unable to create file : " + fileName);
}
return s;

}

public void paint(Graphics g) {

g.setColor(Color.blue);
g.drawString("Signed Applet Demo", 120, 50);
g.setColor(Color.magenta);
g.drawString(test(), 50, 100);
System.out.println("hello2");
}

}

I put this into a jar file with the commands -
javac SignedAppletDemo.java
jar cvf SignedAppletDemo.jar SignedAppletDemo.class

The html file -----
<html>
<head>
</head>
<body>
<applet code=SignedAppletDemo.class archive="SignedAppletDemo.jar"
width=100 height=100>
</applet>
</body>
</html>


The jar and html files are in the same folder.

When I run this on my machine (double clicking the html file in Explorer, which starts Chrome) it works fine. When I put these two files in the same directory on the web ( http://www.mathcarpenter.com/demo.html ) and navigate there with Chrome, I get a "class not found" error on SignedAppletDemo.class .

The jar file looks like this -
c:\Users\John\workspace2\documentsClient\src>jar tvf SignedAppletDemo.jar
0 Tue Aug 09 23:14:28 CDT 2011 META-INF/
71 Tue Aug 09 23:14:28 CDT 2011 META-INF/MANIFEST.MF
1460 Tue Aug 09 23:14:28 CDT 2011 SignedAppletDemo.class

The manifest file looks like this -
Manifest-Version: 1.0
Created-By: 1.6.0_26 (Sun Microsystems Inc.)

What am I missing?
 
J Carpenter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A little more info - if I put the class file itself on the web site in the same directory, this also works fine.
 
J Carpenter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the html to this ---

<html>
<head>
</head>
<body>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="SignedAppletDemo.class">
<PARAM name="archive" value="SignedAppletDemo.jar">
<comment>
<embed code="SignedAppletDemo.class"
archive="SignedAppletDemo.jar"
width="200"
height="200"
scriptable="true"
mayscript="false"
my_param="my_param_value"
type="application/x-java-applet;version=1.6.0"
pluginspage="http://java.sun.com/j2se/1.6.0/download.html">
<noembed>No Java Support.</noembed>
</embed>
</comment>
</OBJECT>
</body>
</html>

----
This doesn't work either.
 
J Carpenter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Posting the error message, if anyone is interested...

load: class SignedAppletDemo.class not found.
java.lang.ClassNotFoundException: SignedAppletDemo.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: SignedAppletDemo.class
 
Sheriff
Posts: 28409
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get that class-not-found message. Instead I get some guff about having to install a plugin whose type is "application/x-java-applet". I can load other people's applets just fine, so it's probably that <object> tag which is confusing Firefox. Why not just use the plain old <applet> tag?

I can also download the jar file directly using this URL: http://www.mathcarpenter.com/SignedAppletDemo.jar, which is as it should be (the browser needs to download it to get at the applet). Only problem is, your site sends it with a content type of "text/html", which is wrong.
 
Ranch Hand
Posts: 77
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:..I can also download the jar file directly using this URL: http://www.mathcarpenter.com/SignedAppletDemo.jar, which is as it should be (the browser needs to download it to get at the applet). Only problem is, your site sends it with a content type of "text/html", which is wrong.



Maybe not 'wrong' in that sense. I downloaded the Jar and (quick'n'dirty) renamed it to .zip and double clicked it. The report was to the effect that it was not a valid zip file. So based on your comment I renamed it to .txt and opened it to see..

..which ain't class files (Dorothy).
 
J Carpenter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul and Andrew - thanks for the help! I put the same stuff on another site that does not have the ads that godaddy puts on free sites, and it worked fine. I guess when the client makes the request for the jar file, godaddy attaches the ad to the jar file when it sends it (or something along those lines.)

Thanks again!
 
Paul Clapham
Sheriff
Posts: 28409
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

J Carpenter wrote:I guess when the client makes the request for the jar file, godaddy attaches the ad to the jar file when it sends it (or something along those lines.)



Ouch!

Anyway it's good you got the problem straightened out. There's all kinds of things that can go wrong but I've never seen that one before.
 
reply
    Bookmark Topic Watch Topic
  • New Topic