*
The moose likes Java in General and the fly likes Run JAR file in Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Run JAR file in Applet" Watch "Run JAR file in Applet" New topic
Author

Run JAR file in Applet

Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Hello,
I have created Swing based GUI Desktop application using netbeans.

Now I have created JAR file of that project using Netbeans.

I want to run that JAR file in applet. But I dont know how to run JAR file in Applet.

Need Help on this.

Waititng for reply.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
An applet is not the same as a desktop app; you may have to refactor your code so that it supports both. YOu can learn all about applets here: http://download.oracle.com/javase/tutorial/deployment/applet/index.html, and specifically about deployment at http://download.oracle.com/javase/tutorial/deployment/applet/deployingApplet.html and http://download.oracle.com/javase/tutorial/deployment/applet/html.html
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Thanks for you quick response.

But how can I run that GUI which is built using Swing. How can i run that jar files.

Tim Moores wrote:An applet is not the same as a desktop app; you may have to refactor your code so that it supports both. YOu can learn all about applets here: http://download.oracle.com/javase/tutorial/deployment/applet/index.html, and specifically about deployment at http://download.oracle.com/javase/tutorial/deployment/applet/deployingApplet.html and http://download.oracle.com/javase/tutorial/deployment/applet/html.html
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
There's no problem with using Swing in an applet. But applets are written differently than desktop apps - they extend the JApplet class instead of having a main method. The pages I linked to explain all that; have you read them?
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
I have seen and read links send by you.

But do I have to create whole application again in Applet.

Or is there any way to convert my Swing Desktop application in Applet.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Not sure why you think you'd have to re-create the whole application. It may be sufficient to rewrite the main class -which probably opens a JFrame- to be a JApplet instead. Try it with a small example, and it should become clear what needs to be done.

This class may also help, although it's written with an Applet in mind, not a JApplet: http://www.acme.com/resources/classes/Acme/ApplicationApplet.java

But yes - some work on your part will be required. Retargeting an app for a different environment generally entails that, especially if that wasn't foreseen when the app was designed.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Parth Pateld wrote:I have created Swing based GUI Desktop application using netbeans.
..I want to run that JAR file in applet. But I dont know how to run JAR file in Applet.


A better alternative is to launch the Swing desktop app. using Java Web Start. JWS can launch the app. from a link, and offers desk-top integration, automatic update, and many other nice features.


Andrew Thompson
http://pscode.org/
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Thanks Thomas for your great idea.

I have refered following link http://pedroassuncao.com/2010/10/java-web-start-jnlp-simple-example/

I have created jar file of my Swing based desktop application.
and created jnlp file for it.


As we have to provide parent path in codebase where we have our html file. As I am running this html file from a local machine and jar file is located on same location.
I dont know how to provide codebase path for windows which is bolded in code part.
"file:///C:/Document and Settings/abc/Desktop/"

But it can not find path.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, no. You are distributing this application via HTTP over the network, so that means that you have to provide a URL for the jar file. Not a file path. So configure your server so that you have a URL for the jar.

You were planning to distribute the applet over the network, weren't you? I mean, there's no other reason for converting a perfectly good application into an applet.
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Ok I got your point.
Yes I would like to put my application in web.
But i have doubt that. From the Main Program of my swing application i am calling some other java files also and doing File IO operation also.
I need other jar files also to run that swing application.
I have created .jar of my swing applicarion using netbeans.

Will above issues work with JWS after creating its jnlp file and running it on server.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, you can include dependent jars in your JNLP configuration.
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Do I have to provide paths for dependent jar files in jnlp program.

if yes, then
Can i provide abstract path for dependent jar files. ?
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Paul Clapham wrote:Yes, you can include dependent jars in your JNLP configuration.

hello I have created a jnlp file which is using other jar files.
I have provided that jar files in a separate folder named 'lib'
Now i have given path for each jar file as below

But this is showing me following exceptio while i am running my html file which is calling jnlp file
com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://localhost:8084/setup/lib/avalon-framework-4.2.0.jar
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

and also showing me following Wrapped Exception.

java.util.zip.ZipException: duplicate entry: LICENSE.txt
at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)
at java.util.jar.JarOutputStream.putNextEntry(Unknown Source)
at com.sun.deploy.net.HttpDownloadHelper.decompressWrite(Unknown Source)
at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source)
at com.sun.deploy.cache.Cache.downloadResourceToTempFile(Unknown Source)
at com.sun.deploy.cache.Cache.downloadResourceToCache(Unknown Source)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


How can i solve this error? I am running this jnlp file on localhost.
 
 
subject: Run JAR file in Applet
 
Similar Threads
deploying applet
Packaging applet in web application
Problem in applet when invoking jinvoke
xtapi.inf not found
Including a jar file in an Applet