开发者

How do I make a java applet run in a browser?

I have developed an applet java with Eclipse, which is included in MyPage.html. I call a webservice and get a response. It works in Eclipse. The Webservice is not on the same server as my computer. So I think I have to sign my applet. I did it with

keytool -genkey -keystore myStore -alias myAlias
jarsigner -keystore myStore -signedjar sMyJar.jar MyJar.jar myAlias
keytool -export -alias myAlias -file myCert.cer

I got a signed jar file, that I put in the folder lib. I have a class, Test.class, of my applet, that I put in the folder src. I put this code inside my html page :

<div>
<applet codebase="src/" code="Test.class" height="80" width="300" 
hspace="10" vspace="10" name="Test" archive="lib/sMyJar.jar"></applet>
</div>  

But I have not the pop up which should ask me whether I want to execute the applet. Even if I erase the code of the request to the webservice, and I 开发者_JAVA技巧write a very simple code, it does not change anything - except the code works (displays "hello world" for example).

I ve seen a similar question of the forum : [http://stackoverflow.com/questions/908748/how-do-i-sign-a-java-applet-for-use-in-a-browser][1] : he seemed to have the same problem, and fixed it. He said " The problem was that my jar files weren't being compiled in the same way that I was referencing the class files". But I don't know how I can change that, and if it is the reason ( I m a very beginner in Java).

And should I put the Cert file in a particular folder ?

Thank you so much for your help.


When you use the archive parameter, the codebase refers not to the location of the unpackaged class files (which the browser doesn't need) but to the location of the archive. The question is, where is your HTML file relative to the JAR file. For example, suppose the HTML file were in the parent directory. Then you could write it like this:

<applet codebase="lib/" code="Test.class" height="80" width="300" 
hspace="10" vspace="10" name="Test" archive="sMyJar.jar"></applet>

Also, I know you mentioned this is a test, but as I can tell you from hard experience, it is a very bad idea to use the default package in Java. I strongly suggest you not do that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜