?
Solved

JNLP Help

Posted on 2006-05-29
54
Medium Priority
?
691 Views
Last Modified: 2012-06-27

Hello there,

I am trying to run my java application through JNLP.
i have a jar file called dslamobf.jar which i signed.then i created a dslam.jnlp file which has the following code in it.then i put the signed jar file and the jnlp file into my apache root called document.when i double click the jnlp file i get the form mentioning the application name etc, then it asks me do you trust the certificate to which i click yes,but then nothing appears.i mean the application does not run.i would also like to mention.the jar file depends on a db.properties file,oracle jdbc driver amd image folder which i have also copied into my root dir

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://download" href="dslam.jnlp">
<information>
  <title>DSLAM APPLICATION</title>
  <vendor>ZJava Developer</vendor>
  <homepage href="/jdc" />
  <description>Welcome User</description>
</information>
<offline-allowed/>
<security>
      <all-permissions/>
</security>

<resources>
  <j2se version="1.2+" />
  <jar href="dslamobf.jar"/>
</resources>
<application-desc main-class="src.com.victa.PictMenuFrameDemo" />
</jnlp>
0
Comment
Question by:zolf
  • 28
  • 15
  • 11
54 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16787723
check the java console for errors

> i would also like to mention.the jar file depends on a db.properties file,oracle jdbc driver amd image folder which i have also copied into my root dir

you'll need to specify the dependant jars in your jnlp
And also think you'll need to jar up the other required resources

0
 

Author Comment

by:zolf
ID: 16787741

also tried to run with the server.like this

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="file:///C:/Java/test1/NewFolder/">
<information>
  <title>DSLAM APPLICATION</title>
  <vendor>ZJava Developer</vendor>
  <homepage href="/jdc" />
  <description>Welcome User</description>
</information>
<offline-allowed/>
<security>
      <all-permissions/>
</security>

<resources>
  <j2se version="1.2+" />
  <jar href="dslamobf.jar"/>
</resources>
<application-desc main-class="src.com.victa.PictMenuFrameDemo" />
</jnlp>
0
 

Author Comment

by:zolf
ID: 16787747

i dont see any console to check the error.after i click on the certificate nothing comes up after that.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16787752
You need to add the jars to your resource section, and add everything that is needed to a jar:
eg.

<resources>
  <j2se version="1.2+" />
  <jar href="dslamobf.jar"/>
  <jar href="oracle.jar"/>
  <jar href="images.jar"/>
</resources>

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787774
>>i dont see any console to check the error

If you're using Windows, you can set the console to appear by using the Java Control Panel 'applet'

I you've merged your jars (i seem to recall) then you don't need to list them separately

0
 

Author Comment

by:zolf
ID: 16787787

thanks mate,you were right i had to jar those files too and then it worked. but i am not being able to run my application from the web browser.

please help me to make it work from server.

0
 

Author Comment

by:zolf
ID: 16787790

>> If you're using Windows, you can set the console to appear by using the Java Control Panel 'applet'

how do i get this thing.from where
0
 
LVL 92

Expert Comment

by:objects
ID: 16787800
To show the console start up the web start application itself (in Program files) and set it to be displayed
0
 

Author Comment

by:zolf
ID: 16787802

yes i used that build.xml to jar all the files into one.then it worked.but i cannot make it run in the web browser
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787803
Start|Settings|Control Panel
0
 
LVL 92

Expert Comment

by:objects
ID: 16787804
> <jnlp spec="1.0+" codebase="http://download" href="dslam.jnlp">

make sure that codebase is actually where your application is available at.
0
 

Author Comment

by:zolf
ID: 16787824

yes the jar and jnlp are in my root folder called document.then i have this html file called dslam.html which is also in the root

<html>
  <head>
      <title>DSLAM demo!</title>
  </head>
  <body>
       <a href="dslam.jnlp">Launch Application</a>
  </body>
</html>
0
 
LVL 92

Expert Comment

by:objects
ID: 16787862
is your server called download
so to load the jnlp you'd use:

http://download/dslam.html

If you're connecting to a database make sure you are using the correct hostname. ie. the host where the database is running and that you have the required perms to connect
0
 

Author Comment

by:zolf
ID: 16787896

i know what is going on now.
i had this build.xml file which i thought has included all the files db.properties,images,dslam.jar,mysql-connector-java-3.0.15-ga-bin.jar,ojdbc14.jar into one jar file called testdslam.jar.but infact the db.properties and images folder need to be there for the testdslam.jar file to work.without those two the application does not start.so i need to correct that first.but in my xml file below i have mentioned to add those two files.can you'll help me to correct that thing first.
  <?xml version="1.0" ?>
- <project name="dslam" default="test-jars-stuff">
- <target name="test-jars-stuff">
- <jar destfile="testdslam.jar" compress="true">
- <manifest>
  <attribute name="Main-Class" value="src.com.victa.PictMenuFrameDemo" />
  </manifest>
- <!--  Put the source in as well
  -->
  <fileset dir="." includes="c:\Java\test1\db.properties" />
  <fileset dir="." includes="c:\Java\test1\images" />
  <zipfileset src="c:\Java\test1\dslam.jar" />
  <zipfileset src="c:\Java\test1\mysql-connector-java-3.0.15-ga-bin.jar" />
  <zipfileset src="c:\Java\test1\ojdbc14.jar" />
  </jar>
  </target>
  </project>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787907
You are you accessing db.properties and the images?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787908
Sorry - typo:

HOW are you accessing db.properties and the images?
0
 

Author Comment

by:zolf
ID: 16787919

what do you mean.if i delete those 2 files the testdslam.jar application does not work
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787925
>>what do you mean.i

I mean, how do you access those files *in your code*?
0
 

Author Comment

by:zolf
ID: 16787927

from my java application

protected static void initConnection()
      {
            Properties prop = new Properties();
            
            try
            {
                  FileInputStream fis = new FileInputStream(DEFAULT_PROPERTY_FILE);
                  
                  try
                  {
                        prop.load(fis);
                  }
                  finally
                  {
                        fis.close();
                  }
            }
            catch (Exception e)
            {
                  System.err.println("Error loading config file: " + DEFAULT_PROPERTY_FILE);
                  System.exit(1);
            }
0
 
LVL 92

Expert Comment

by:objects
ID: 16787929
you can't include a jar inside a jar

make add the other jars to your jnlp seperately as I showed earlier
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787931
>>DEFAULT_PROPERTY_FILE

How is this defined?

And what about the images?
0
 

Author Comment

by:zolf
ID: 16787933

it all works fine.just need to get those two files also into the testdslam.jar.which i think we did using the build.xml file.
0
 

Author Comment

by:zolf
ID: 16787934

public static final String DEFAULT_PROPERTY_FILE = "db.properties";
0
 
LVL 92

Expert Comment

by:objects
ID: 16787935
>                FileInputStream fis = new FileInputStream(DEFAULT_PROPERTY_FILE);

you'll need to use getResourceAsStrame

               FInputStream fis = PictMenuFrameDemo.class.getResourceAsStream(DEFAULT_PROPERTY_FILE);
0
 

Author Comment

by:zolf
ID: 16787946

object:
those two files are not jar files. one is a image folder and the other is a properties file
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787949
>>just need to get those two files also into the testdslam.jar.which i think we did using the build.xml file.

This is OK

<fileset dir="." includes="c:\Java\test1\db.properties" />

but the next one possibly isn't, which is why i'm asking about how you're accessing the images
0
 

Author Comment

by:zolf
ID: 16787955

 ImageIcon testIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));
0
 
LVL 92

Expert Comment

by:objects
ID: 16787960
you'll also need to use getResourceXXX() method to load your images as they are now being loaded thru the classloader instead of via file
getResource() will give you a URL
getResourceAsStream() will give you a stream
0
 
LVL 92

Expert Comment

by:objects
ID: 16787965
should be more like:

 ImageIcon testIcon = new ImageIcon(getClass().getResource("images/dslamIcon.png"));

that assumes the images directory is under the class making the call.

if image is the base package then use:

 ImageIcon testIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787971
>>ImageIcon testIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));

should be

ImageIcon testIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));

and

>><fileset dir="." includes="c:\Java\test1\images" />

should be

<fileset dir="images" includes="c:\Java\test1\images" />
0
 

Author Comment

by:zolf
ID: 16787978

i cannot change all this code now(afraid that i might get other errors on the way to correct this) because i need to do a presentation with Java web start today.i did not expect to have so much problem with JNLP
0
 

Author Comment

by:zolf
ID: 16787984


ok since both of you'll insists that my code has to be changed i will try.fingers crossed :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16787987
>>i cannot change all this code now(afraid that i might get other errors on the way to correct this)

Just back it up before changing it



0
 
LVL 92

Expert Comment

by:objects
ID: 16787988
it won't work the way you are load because as I mentioned above you need to load resources through the classloader. You can't load from file system because the files are coming from a web server and not from file system.
0
 

Author Comment

by:zolf
ID: 16788059


somewhere in my code i have this but when i try to chnge this i get error
protected ImageIcon loadImage(String fname)
      {
            //return new ImageIcon(Toolkit.getDefaultToolkit().createImage(fname));
            
            return new ImageIcon(getClass().getResource(fname));
      }
      
      // Init images for menu items
      protected void initImages()
      {
            menuOneIm = loadImage("images/arrowIcon.png");
            menuTwoIm = loadImage("images/newIcon.png");
            menuTreeIm = loadImage("images/printIcon.png");
            
            smenuOneIm = loadImage("images/logo.png");
            smenuTwoIm = loadImage("images/def.png");
      }
0
 
LVL 92

Expert Comment

by:objects
ID: 16788068
if the images directory is a base directory in your jar then it should be:

     protected void initImages()
     {
          menuOneIm = loadImage("/images/arrowIcon.png");
          menuTwoIm = loadImage("/images/newIcon.png");
          menuTreeIm = loadImage("/images/printIcon.png");
         
          smenuOneIm = loadImage("/images/logo.png");
          smenuTwoIm = loadImage("/images/def.png");
     }
0
 

Author Comment

by:zolf
ID: 16788961

but when i change this in loadImage() i get error

//return new ImageIcon(Toolkit.getDefaultToolkit().createImage(fname));
         
          return new ImageIcon(getClass().getResource(fname));
0
 
LVL 92

Expert Comment

by:objects
ID: 16788997
Whats the value of fname, it now needs to be the path to the resource in your jar (and not the path of the file on disk)

whats the path of the image in the jar
and whats the error?
0
 

Author Comment

by:zolf
ID: 16789088

fname is the path of the image "/images/arrowIcon.png".

you had mentioned to change all the code calling the image folder like this

ImageIcon testIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at javax.swing.ImageIcon.<init>(Unknown Source)
      at src.com.victa.PictMenuFrameDemo.initImages(PictMenuFrameDemo.java:181)
      at src.com.victa.PictMenuFrameDemo.createMenuBar(PictMenuFrameDemo.java:88)
      at src.com.victa.PictMenuFrameDemo.<init>(PictMenuFrameDemo.java:69)
      at src.com.victa.PictMenuFrameDemo.createAndShowGUI(PictMenuFrameDemo.java:354)
      at src.com.victa.PictMenuFrameDemo.access$0(PictMenuFrameDemo.java:350)
      at src.com.victa.PictMenuFrameDemo$2.run(PictMenuFrameDemo.java:395)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 880 total points
ID: 16789094
Make sure that you have


images

as a root entry in your jar
0
 

Author Comment

by:zolf
ID: 16789110


cehj when i use ant to combine all the files to one jar and then i open the jar to see its contents i dont have the db.properties and image folder inside it.
0
 

Author Comment

by:zolf
ID: 16789120

that is another problem which i am facing other then opening the jnlp file in a browser
0
 
LVL 92

Expert Comment

by:objects
ID: 16789198
> n i open the jar to see its contents i dont have the db.properties and image folder inside it.

that'd be whats causing the error above, as it cannot find the images
you need to include them in the jar in an images directory
your build would be something like, you'll proibably need to adjust it a liitle as I'm not sure exactly where u have everything:

<?xml version="1.0" ?>
- <project name="dslam" default="test-jars-stuff">
- <target name="test-jars-stuff">
- <jar destfile="testdslam.jar" compress="true">
- <manifest>
  <attribute name="Main-Class" value="src.com.victa.PictMenuFrameDemo" />
  </manifest>
- <!--  Put the source in as well
  -->
  <fileset dir="c:\Java\test1" includes="db.properties" />
  <fileset dir="c:\Java\test1" includes="**/*.class" />
  <fileset dir="c:\Java\test1" includes="images/**" />
  </jar>
  </target>
  </project>
0
 

Author Comment

by:zolf
ID: 16795588

hi objects,

thanks your build xml worked properly,in the sense it add those two files.

now i need to change the code to replace all the image calls

>>ImageIcon testIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));

   to

ImageIcon testIcon = new ImageIcon(getClass().getResource("/images/dslamIcon.png"));

at one place i have initImages() which calls loadImage(String fname),i need to change the code here also to getTesource.but i get a error when i try to compile the code.the error i had sent before.


protected ImageIcon loadImage(String fname)
     {
          //return new ImageIcon(Toolkit.getDefaultToolkit().createImage(fname));
         
          return new ImageIcon(getClass().getResource(fname));
     }
     
     // Init images for menu items
     protected void initImages()
     {
          menuOneIm = loadImage("images/arrowIcon.png");
          menuTwoIm = loadImage("images/newIcon.png");
          menuTreeIm = loadImage("images/printIcon.png");
         
          smenuOneIm = loadImage("images/logo.png");
          smenuTwoIm = loadImage("images/def.png");
     }




0
 

Author Comment

by:zolf
ID: 16795611

it worked as you had mentioned in your previous comment to add / in my initImages()  :)
0
 
LVL 92

Expert Comment

by:objects
ID: 16795618
so is it all working now ?
0
 

Author Comment

by:zolf
ID: 16795739

i changed all the code to getClass.getResource........

and tested the code it worked fine.
then i jared all the class files of my application and called it newdslam.jar
then i used build.xml to combine the application jar which is newdslam.jar,image folder,db.properties,mysql and oracle jar files into one jar called testdslam.jar like this

<?xml version="1.0" ?>
- <project name="dslam" default="test-jars-stuff">
- <target name="test-jars-stuff">
- <jar destfile="testdslam.jar" compress="true">
- <manifest>
  <attribute name="Main-Class" value="src.com.victa.PictMenuFrameDemo" />
  </manifest>
- <!--  Put the source in as well
  -->
  <fileset dir="c:\Java\test3" includes="db.properties" />
  <fileset dir="c:\Java\test3" includes="images/**" />
  <zipfileset src="c:\Java\test3\newdslam.jar" />
  <zipfileset src="c:\Java\test3\mysql-connector-java-3.0.15-ga-bin.jar" />
  <zipfileset src="c:\Java\test3\ojdbc14.jar" />
  </jar>
  </target>
  </project>

then i opened the testdslam.jar to confirm if those two files are in it, and it was there.so i was happy :)

but when i ran the jar i got this :(

C:\Java\test3>java -jar testdslam.jar src.com.victa.PictMenuFrameDemo
Error loading config file: db.properties
0
 

Author Comment

by:zolf
ID: 16795752

do i need to add / to this line too ???

public static final String DEFAULT_PROPERTY_FILE = "db.properties";

like this

public static final String DEFAULT_PROPERTY_FILE = "/db.properties";
0
 
LVL 92

Accepted Solution

by:
objects earned 1120 total points
ID: 16795762
How do you load the config?  looks like it should be:

InputStream fis = PictMenuFrameDemo.class.getResourceAsStream("/db.properties");
0
 

Author Comment

by:zolf
ID: 16795768

i use it like this

public static final String DEFAULT_PROPERTY_FILE = "db.properties";


FileInputStream fis = new FileInputStream(DEFAULT_PROPERTY_FILE);
0
 

Author Comment

by:zolf
ID: 16795779

ok i changed my code to what you said and it worked fine in eclipse.

now let me again do that long process and will get back to you :)

appreciate your help.
0
 

Author Comment

by:zolf
ID: 16795844

i works to some extend.i mean now i get to see the application frame and values.but inside i have other buttons which when i click should open dialog box.it gives me error in there.i will try to sort it out.by the way thanks very much.

0
 

Author Comment

by:zolf
ID: 16795932
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16795984
:-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question