• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run JAR file in Applet

 
Parth Pateld
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Parth Pateld
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can include dependent jars in your JNLP configuration.
 
Parth Pateld
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic