File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JNLP and Web Start and the fly likes Image file in cannopt access-getting error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "Image file in cannopt access-getting error" Watch "Image file in cannopt access-getting error" New topic
Author

Image file in cannopt access-getting error

shanavas ct
Greenhorn

Joined: Oct 23, 2009
Posts: 4
Hi All,

I am devoloping an application with swing as front end and tomcat as web server.Now I am using jnlp to start my application. My jar have several image files. But when running without using an image file in jar and commenting the code section using image, it works fine. When image is used the following error shows by the webstart.

An error occurred while launching/running the application.

Title: Notepad Demo
Vendor: The Java(tm) Tutorial: Sun Microsystems, Inc.
Category: Security Error

access denied (java.io.FilePermission images//Curveline.jpg read)


I tried putting the image file working directory and in a seperate folder named "images" in the jar file. Now I tries to run my application from the jar directly avoiding the web server to find whats the error.

Using the command "file:///C:/jnlp/helloworld.jnlp"

and my jnlp looks like this


---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for Notepad -->

<jnlp spec="1.0+"
codebase="file:///c:/jnlp/""
href="helloworld.jnlp">
<information>
<title>Notepad Demo</title>
<vendor>The Java(tm) Tutorial: Sun Microsystems, Inc.</vendor>
<description>Notepad Demo</description>
<description kind="short">ClickMeApp uses 3 custom classes plus several
standard ones</description>
<offline-allowed/>
</information>
<resources>
<jar href="helloworld.jar"/>
<j2se version="1.5+"
href="http://java.sun.com/products/autodl/j2se"/>
</resources>
<application-desc
main-class="CurveLineFrame"
width = "900"
height = "600"
/>
</jnlp>
-----------------------------------------

Please help me

Regaards..
Shanavas
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

"shanavas ct", please check your private messages regarding an important administrative matter.

Thank you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42046
    
  64
How are you trying to access the file? Using a File with "images//Curveline.jpg" is not going to work, since that will look on the local file system (and consequently throw a security exception). you'll need to use something like " getClass().getResourceAsStream("/images/Curveline.jpg") ".

codebase="file:///c:/jnlp/""

Don't use the "file:" protocol for this; it's not going to work once you run the application off a web server.


Ping & DNS - my free Android networking tools app
shanavas ct
Greenhorn

Joined: Oct 23, 2009
Posts: 4
Don't use the "file:" protocol for this; it's not going to work once you run the application off a web server.

Thanks for your support Mr. Dittmer., I used the the getClass().getResourceAsStream(path); as you said but I still have some problem. I gets Exception when I run my application in JNLP, but it works smoothly in ordinary run using "java" command.

I think it is of some permission error.The Error I got looks like;
-----------------------------------------------------------------------
"An error occurred while launching/running the application.
Title: Curveline BIsolution
Vendor: The Java(tm) Tutorial: Sun Microsystems, Inc.
Category: Security Error

Unsigned application requesting unrestricted access to system
Unsigned resource: file:/c:/BISolution/build/jar/BISolution.jar
------------------------------------------------------------------------

The Exception is

----------------------------------------------------------------------
JNLPException[category: Security Error : Exception: null : LaunchDesc:
<jnlp spec="1.0+" codebase="file:/c:/BISolution/" href="file:/c:/BISolution/bisolution.jnlp">
<information>
<title>Curveline BIsolution</title>
<vendor>The Java(tm) Tutorial: Sun Microsystems, Inc.</vendor>
<homepage href="null"/>
<description>Notepad Demo</description>
<description kind="short">ClickMeApp uses 3 custom classes plus several standard ones</description>
<icon href="file:/c:/BISolution/default" kind="default"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<property name="jnlp.publish-url" value="$$context/publish"/>
<jar href="file:/c:/BISolution/build/jar/BISolution.jar" download="eager" main="true"/>
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.5+"/>
</resources>
<application-desc main-class="com.curvature.presentation.CurveLineFrame"/>
</jnlp> ]
at com.sun.javaws.LaunchDownload.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.LaunchDownload.checkSignedResources(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

---------------------------------------------------------------------

My JNLP file is given below please suggest that some thing I have to add some more entries make it work.
Or in jave code

Please help me........

Thank You,
Shanavas
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42046
    
  64
Ulf Dittmer wrote:Don't use the "file:" protocol for this
 
GeeCON Prague 2014
 
subject: Image file in cannopt access-getting error