Signed Java Applet - Java Applet Development

0 down vote favorite
     
I have written an applet with Netbeans. When I click on Clean and Build then Netbean create a jar file "Test.jar" and also another folder called lib in the same directory. I've signed the Test.jar. Basically this applet upload files to server with FTP. So when Applet loads into browser then I am able to select files but when I click on upload then it stops. So my question is:
1. Have I also need to sign all dependent jar files?
2. My directory structure is as follow:
C:\AppletPage.html C:\Test.jar C:\lib
and code in html file is as follow
<applet code="UploadGUI.class"
archive="test.jar"
width=400 height=400></applet>Please advice me where am I wrong?
Thanks in Advance 

Shahid_Hanif wrote:
0 down vote favoriteHuhh?
I have written an applet with Netbeans. ..My condolences.
..lWhen I click on Clean and Build then Netbean create a jar file "Test.jar" and also another folder called lib in the same directory. I've signed the Test.jar. Basically this applet upload files to server with FTP. ..If you deploy the applet in a Plug-In 2 architecture JRE and launch it using Java Web Start - it can be sand-boxed.
..So when Applet loads into browser then I am able to select files but when I click on upload then it stops. .. What messages appear in the Java Console? Does the code of the applet [swallow exceptions|http://pscode.org/javafaq.html#stacktrace] (<- link)?
..So my question is:
1. Have I also need to sign all dependent jar files?What dependent Jars? The applet element shown lists only one Jar in the archive attribute.
2. My directory structure is as follow:
C:\AppletPage.html C:\Test.jar C:\libWhat (if anything) is in 'lib'?
Edit 1:
Also posted to [http://stackoverflow.com/questions/3740006/java-applet-sign]
Edited by: AndrewThompson64 on Sep 18, 2010 1:07 PM 

simply I've put all my dependent libraries inside archive attribute. 

Shahid_Hanif wrote:
simply I've put all my dependent libraries inside archive attribute.Simply I asked you 3 questions. Go back and read my reply more carefully and try and supply answers to all of them. I do not have time to spoon feed information to you.

Related

Reasons why signed applets don't be displayed

Hi to all:
I have a HTML that shows (in code) a signed applet, but when I open the HTML in the browser, the applet is not displayed. The Java console also is not displayed.
The applet is in the correct directory and the signature is valid.
What reasons can make the applet does not displayed??
Dani 
Bring up the Java Console ( http://www.java.com/en/download/help/javaconsole.xml) and see what it says about the Applet when you try to run it. 
When the browser tries to run the applet, the Java console appears and dissapears and the applet is not loaded.
The area where the applet should be shown in appears in black, but the applet is not loaded in.
Dani 
805978 wrote:
When the browser tries to run the applet, the Java console appears and dissapears and the applet is not loaded.
The area where the applet should be shown in appears in black, but the applet is not loaded in.So you don't even get a security screen? I might be able to give some help if you post the HTML that invokes the Applet and a listing of the jar file you have created -
jar -tf your-jar-file.jar but without this I have nothing to go on. I have no problems (other than the Applets being cached in the client for some stupid reason) creating and publishing Applets and signed Applets.
Are you able to run a simple "Hello World" unsigned Applet? 
The applet works properly on its own and the HTML code that launches it is the following:
<applet code="PinApplet.class"
               archive="PinApplet.jar"
               height=150 width=1200>
               Authentication Form is not supported by the browser
</applet> 
There is nothing obviously wrong with your HTML but you have not published the jar listing!
Have you been able to create, deploy and access an unsigned "Hello World" Applet? 
I got the HTML to show the applet only occasionally, but when I change some code, re-make the applet again and test the HTML and the applet isn't shown.
I have a java.policy.applet in the same directory as the HTML and the signature is valid. The applet only uses JDK classes, not external classes, not user-defined classes
Dani 
Other than say that you should clear out the Applet cache each time you make a change to the Applet I can't help.
I just wonder why you won't answer my question and won't publish the directory listing of the jar file?
Bye 
The directory listing of the jar file: PinApplet.jar
-- .classpath
-- .project
-- PinApplet.class
-- PinApplet.java
-- PinAppletModel.class
-- PinAppletModel.java
-- /META-INF
· signer.DSA
· signer.SF
· MANIFEST.MF
· REFACTORINGS.XML 
You seem to have some clutter in that jar file. Why do you need .classpath, .project and the java files included.
I'm not convinced the two signer files have valid names. I don't get these names in my signed jars so how did you create the signed jar file?
What utility did you use to obtain the listing of the jar file because it is not of the format I get when I use "jar -tf your-jar-file.jar". 
This is result from the command you mentioned:
--------------------------------------------------------------
META-INF/MANIFEST.MF
META-INF/DanielMerida-Barquero.SF
META-INF/DanielMerida-Barquero.DSA
META-INF/REFACTORINGS.XML
PinAppletModel.class
PinAppletModel.java
PinApplet.class
PinApplet.java
.classpath
.project
About .classpath y .project, they are included by Eclipse in the project, but I think I try to unselect them when I export the JAR.
About the names of the files, I use this name in other projects and I don't have any problems with it.
Dani

deploying a jar file

I just downloaded and installed the jdk1.3.1 into the root of my local drive. I am not sure if I am using the software correctly, I am launching a dos shell and cd to the directory c:\windows\desktop\internet, which is where the necessary files are stored. In this directory I have three class files and want to put them in a jar file. After I dir the above directory I type:
jar cvf classes.jar internet$SymAction.class internet$SymText.class internet.class
It seems to work correctly and creates classes.jar in the internet folder. In the html code I have,
<applet code="classes.jar" width="698" height="326" align="middle"></applet>
When I launch the html file, which is located in the internet folder as well, I get the error, load: class classes.jar not found. Is there something else I need to add to the applet tag? 
Hi,
You need to add the archive attribute to your applet tag:
archive = "classes.jar"
you may also want to add codebase if you plan on adding images, sounds, etc. to the jar later on.
codebase = "classes.jar"
And finally if you use any of the 1.3 API's then you need the java plug-in and must use the OBJECT tag not the APPLET tag. See this link for further details:
http://java.sun.com/products/plugin/
One last tip, you can use this method to build your jar too:
jar cvf classes.jar *.class
and that will add all of the .class files in your folder to the archive (after you navigate to c:\windows\desktop\internet as you did before).
-Ron
Almost everything you wanted to know about the APPLET tag:
http://java.sun.com/docs/books/tutorial/applet/appletsonly/html.html 
is there a way to deploy an applet without using the code or codebase tag? i have the following code and it does not work, it is giving me the same class not found error,
<applet ARCHIVE="intpress.jar" width="698" height="326" align="middle"></applet> 
Right! You need to give the name of the class that is the applet you want to run! This is done with the code tag, so therefore the code tag is always required. 
yeah, but my main class file is contained in the jar file. do i still need to have both the archive and code attributes in my applet tag? 
Yes, the code tag is always required. The archive tag is used to tell the browser to look in the archive (jar) for that class. Both are required when using jar files.
-Ron

JAR to CAB Conversion

Short and simple:
I have a jar/html file combo that specifies archive="initStrip.jar" and code="org.corp.InitStrip" in the applet tag... I had to repackage it in cab format (due to needed modifications for IE only) and have specified the CABBASE... it loads and asks for permission (which is granted), but never finds the correct file w/i the cab archive to start, instead it gives the error:
load:class org.corp.InitStrip not found
Any suggestions? 
IE specifies that you have to cab it and dubuild the same.
Follow this when you dubuild:
1) Put your cab in a subdirectory.
2) Extract the org.corp.InitStrip through jar tool only..(if it is a jar file, jarred using jar tool.)
3) put the extracted jar files in the subdirectory.
4) Now dubuild
5) you will get a cab file.
6) Put that cab file in cabbase,....
Enjoy
Rajesh 
If you would use the OBJECT tag and not the APPLET tag, you can use jar file in both (IE and Netscape).... 
this seems you have made a wrong construction of your cab file, and for instance the applet can't find your main class inside your cab file (for instance you gave a bad path). I got the same problem, have a look to this topic it may help you :
http://forum.java.sun.com/thread.jsp?forum=63&thread=215204

can you embed a jar into a webpage?

Hi, I worked out how to embed my .class file into a webpage with <applet>.
Im using netbeans which also creates a jar which includes my audio files in the archive.
Could I just upload the jar file and embed that into a webpage? 
You can put the code in JARs if that's what you mean. 
say if i just wanted to upload the jar to the server and nothing else, could it be embedded as an applet? 
slenkar wrote:
say if i just wanted to upload the jar to the server and nothing else, could it be embedded as an applet?Yes you can. You only need to mention the jar in your HTML. Don't ask me for specifics, it's been ages since I wrote an Applet. 
slenkar wrote:
say if i just wanted to upload the jar to the server and nothing else, could it be embedded as an applet?Yes. Check the 'archive' attribute here [http://java.sun.com/j2se/1.4.2/docs/guide/misc/applet.html] 
thanks

Java code to edit a .jar file

Hey, I've been researching into a project I'm planning to start and have most bases covered. Though I need help with this problem:
- If you have a .jar file in your jar application, what's the code to take that file and save it to somewhere else in the hard disk?
- What is the code to open, edit classes and add resources within it from your java application?
Thanks :)
-Gan 
GanMatt wrote:
Hey, I've been researching into a project I'm planning to start and have most bases covered. Though I need help with this problem:
- If you have a .jar file in your jar application, what's the code to take that file and save it to somewhere else in the hard disk?Google for "Java FileChannel example"
- What is the code to open, edit classes and add resources within it from your java application?Why would you want to do that? Why not just have a folder inside the root of your application installation where you keep your resources? Editing a JAR file like the way you proposed is possible but it's not the right thing to do.
It's not advised to ship your app as one JAR if you need to add/remove resources from it. Ship it as a zip file with the correct folder structure and your users can copy it to where they wish on their system and create a shortcut to the executable. You could also create an installer which did this.
Edited by: binary_coder on Apr 19, 2009 7:53 AM 
GanMatt wrote:
Hey, I've been researching into a project I'm planning to start and have most bases covered. Though I need help with this problem:
- If you have a .jar file in your jar application, what's the code to take that file and save it to somewhere else in the hard disk?
- What is the code to open, edit classes and add resources within it from your java application?Here is the command to un-jar a .jar file. You could find more options of the jar command here
jar -xf myapp.jarBut, normally, a .jar file would only contain .class files and not the .java files. It is not advisable to un-jar a .jar file to make changes to already existing project. I am sure there would be project source (.java) files in some version controlling system (such as PVCS, CSV , or sub version) or maybe in some folder in some hard disk. Take the source files make the necessary changes, test it, re-build the .jar file and again test it. This is the way to go, not the other way round starting un-jarring a .jar file. 
Perhaps I should explain my use for:
"- What is the code to open, edit classes and add resources within it from your java application?"
I'm making a java game maker which you will be able to build your game in. Inside the application itself is an empty jar file, so in the game maker when you click compile; that empty jar file is copied to the hard disk. Than the game maker opens the empty jar file and adds resources/changes the code. So when you actually open it, it's the java application you created.
Even though it's not right, I still need to figure out how to open a jar file and change it's source/resources.
-Gan 
GanMatt wrote:
"- What is the code to open, edit classes and add resources within it from your java application?"Using classes from the java.util.jar package you can read from a jar file and you can write to a jar file.
I would read from the old jar file and create a new jar file writing out the contents of the old jar file plus additional classes/resources. 
GanMatt wrote:
I'm making a java game maker which you will be able to build your game in. Inside the application itself is an empty jar file, so in the game maker when you click compile; that empty jar file is copied to the hard disk. Than the game maker opens the empty jar file and adds resources/changes the code. So when you actually open it, it's the java application you created.I don't see the need to put an empty jar file into your application. Simply have your app create a new file and write to it. Done!

Categories

Resources