Applet and jar
Hi,
I'm trying to run a Java applet that depends on an external jar to run, my html is here:
<applet archive="../Code/acqui.jar" code="DirTreeTester"
codebase="Code" width="100" height="100"></applet>
As one can see, the jar file is located in the parent's Code directory, and the applet (DirTreeTester) is located in the present folder's Code directory. The code in DirTreeTester is very short so I might as well paste it here:
package code;
import javax.swing.*;
import java.awt.*;
// acqui.jar
import acqui.dance.*;
publicclass DirTreeTesterextends JApplet
{
publicvoid init()
{
new DirTreeTester();
}
//////////// Vars
private DirTree dirTree;
private JScrollPane scr;
//////////////// Constructor
public DirTreeTester()
{
// Make
dirTree =new DirTree();
dirTree.setSize(400,400);
dirTree.setLocation(10,10);
// Add to srcoll pane
scr =new JScrollPane(dirTree);
// Do this
this.getContentPane().add(scr);
this.setSize(420,420);
this.setVisible(true);
}
}
The applet and the jar have been made in Eclipse Version: 3.2.2 if that matters at all, the package code is also lower case, but I don't suppose that matters when the things compiled.
It all looks well to me, but when I view the page in FF 2 I just get a very unhelpful cross in the top left of the applet area.
If anyone could help with this that would be grand, the aim of this website if to show off my Java knowledge gained from my course, but if I can't get a simple applet to run, one might question that knowledge ;)
Regards,
Luke
[2624 byte] By [
dfgstga] at [2007-11-27 8:11:54]

# 3
> tutorial
>Code
>acqui.jar
> acqui-dance
> DirTree.htm
> Code
> DirTreeTester.java
> DirTreeTester.class
>
> Think the jar's the prolem, have had trouble with the
> Eclipse export-to-jar thingy before, just have to put
> all code into a single Code folder I guess *sigh* :)
Nope. It is a path problem. You are calling the DirTreeTester.class file and to call the acqui.jar file you are goin up one directory and then into the Code directory. The DirTreeTester.class file is already in the Code directory, so it is basically looking in the same directory as the DirTreeTester.class file. Instead, I believe you need to do a
<applet archive="../../Code/acqui.jar" code="DirTreeTester"
codebase="Code" width="100" height="100"></applet>
# 4
Thanks, it seems to work, I've had to use a different example, I'm know using my search component tester.
The reason for using this is because the DirTree class uses a JFileChooser class (it opens a directory root into a tree) and when I tried running the applet in applet viewer I got an assess denied exception, I have another applet (Backdrop) and I even get an java.io.filePermission exception just by trying to read an image, and almost all of my applets use images.
Another strange thing is that when I run the Backdrop applet from the same directory, so in the applet viewer tags the codebase=敂, it loads the image fine.
The image is ?4.jpg? not a very good name I know, and it's inside a folder called 揑mages?and that is inside the 揅ode?directory, that's the one with all the classes in.
And it the Backdrop tester applet I am loading it like this:
backImg=ImageIO.read(new File("Images"+File.separator+"04.jpg"));
The rest of the applet loads up fine, but the image is missing.
Is there anyway to get round the security issue? Or perhaps convince the browser that my files are secure?
Thanks,
Luke
# 5
You might want to post this to a new topic if what I suggest doesn't work or is too much work for what you need to do. I'm sure there is another way to do it, but I'm not sure what it is. I haven't done a lot with applets, but I can answer some questions, things with which I have experience.
Anyway, from what I can tell, you are trying to load a file from the local hard drive, at least I think that is how it sees it. There might be another way to do this, such as a resource, but that is the part with which I do not have any experience. But, to load a file from the local hard drive, you must use a signed applet. There are tutorials out there for this, so you would need to refer to them because it would be too much to re-type here. But, here is a thread that has some of those links as well as instructions on how to get the certificate to sign the applet, or rather jar file. Actually to use this method you would need to bundle this entire thing into a jar file and sign that jar file.
Come to think of it, you might just be able to bundle the entire structure into one jar file, including the image, and use it that way. That might possibly solve the security problem as well. It would be worth a try, anyway, because if it doesn't work and you need to sign the jar file (entire applet), you will need to jar everything up anyway.
Anyway, here is the thread with the jar signing information.
http://forum.java.sun.com/thread.jspa?threadID=5186246