Applet deployment problem

N

NickPick

I'm compiling a JavaApplet which works fine when I run it with
NetBeans. But when I try to start it with a Browser with the generated
HTML file I get error messages and I don't know what went wrong:
thanks

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
.....
 
D

Dave Miller

NickPick said:
I'm compiling a JavaApplet which works fine when I run it with
NetBeans. But when I try to start it with a Browser with the generated
HTML file I get error messages and I don't know what went wrong:
thanks

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
....
Your applet depends on PieDataset. Have Netbeans create a jar (with all
of the needed classes) and then run the applet from that archive
(archive="your_jar").
 
N

NickPick

Your applet depends on PieDataset. Have Netbeans create a jar (with all
of the needed classes) and then run the applet from that archive
(archive="your_jar").

That doesn't seem to be working. I generated a jar file with NetBeans
(which it does automatically, although I'm not entirely sure what's in
there) and added arhive in the html file. Does NetBeans know
automatically which classes need to be in the Jar file?
 
D

Dave Miller

NickPick said:
That doesn't seem to be working. I generated a jar file with NetBeans
(which it does automatically, although I'm not entirely sure what's in
there)
You can list the contents of the jar with the command
jar tf your_jar.jar

and added arhive in the html file. Does NetBeans know
automatically which classes need to be in the Jar file?

Set your target server in Netbeans to be other than something internal
to the IDE and it should know to package all of the needed classes.
Otherwise, it will use its internal dependencies which break as you move
outside of the IDE (as you've learned).

In the alternative, you can track down all of the needed classes and
place them in the same directory as your applet and /or jar them up.
 
N

NickPick

You can list the contents of the jar with the command
jar tf your_jar.jar

and added arhive in the html file. Does NetBeans know


Set your target server in Netbeans to be other than something internal
to the IDE and it should know to package all of the needed classes.


How can I change the target server in Netbeans?
 
R

Roedy Green

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

Try building your jar with GenJar and ANT. This will ensure all that
is needed in is there.

See http://mindprod.com/jgloss/ant.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Man has been endowed with reason, with the power to create, so that he can add
to what he’s been given. But up to now he hasn’t been a creator, only a destroyer.
Forests keep disappearing, rivers dry up, wild lifes become extinct,
the climate’s ruined and the land grows poorer and uglier every day."
~ Anton Chekhov (born: 1860-01-29 died: 1904-07-15 at age: 44)
 
D

Dave Miller

How can I change the target server in Netbeans?
Install a server (i.e. Tomcat) on your computer.
Add the server to Netbeans at Tools Server Add Server
Point your project to it in Project Properties.
 
A

Arne Vajhøj

NickPick said:
I'm compiling a JavaApplet which works fine when I run it with
NetBeans. But when I try to start it with a Browser with the generated
HTML file I get error messages and I don't know what went wrong:
thanks

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
....

Put a Class-Path directive that refers to both the JFreeChart jar files
in the manifest of your jar file. And put those two in the same dir
as your jar file. Then it should work.

Arne
 
L

Lew

Arne said:
Put a Class-Path directive that refers to both the JFreeChart jar files
in the manifest of your jar file. And put those two in the same dir
as your jar file. Then it should work.

Alternatively, put the library JARs in a subdirectory of the dir wherein your
main JAR resides. For example, NetBeans likes to build a JAR into a directory
with a subdirectory 'lib/' containing the libraries, e.g.,

dist/ foo.jar
|= lib/ postgresql-8.3-603.jdbc4.jar
 
N

NickPick

Alternatively, put the library JARs in a subdirectory of the dir wherein your
main JAR resides.  For example, NetBeans likes to build a JAR into a directory
  with a subdirectory 'lib/' containing the libraries, e.g.,

  dist/  foo.jar
      |= lib/ postgresql-8.3-603.jdbc4.jar

That's exactly what Netbean has done in my case (the Project's Jar
file is in the dist folder and the library jar files are in the
subfolder lib). On the other hand the html file calling the java
applet is in the build folder with a subfolder that contains the
applet.class file.

Do I have to somehow merge these two folders? And why do I really have
to edit the html file so that it includes the Jar files?
 
J

John B. Matthews

[...]
That's exactly what Netbean has done in my case (the Project's Jar
file is in the dist folder and the library jar files are in the
subfolder lib). On the other hand the html file calling the java
applet is in the build folder with a subfolder that contains the
applet.class file.

You may find it useful to enable the Java Console in your browser. On my
platform, this is done using the Java Preferences application.
Do I have to somehow merge these two folders? And why do I really
have to edit the html file so that it includes the Jar files?

Your HTML file has to reflect the locations of your applet class and any
associated jars. In this case, the JFreeChart & JCommon libraries are
required. Given a project named scratch, here is a typical applet tag
and corresponding class declaration:

<applet width=500 height=400
code="chart.ChartApplet.class"
archive="dist/scratch.jar,
dist/lib/jcommon-1.0.15.jar,
dist/lib/jfreechart-1.0.12.jar">
</applet>

package chart;
....
public class ChartApplet extends JApplet {
public void init() {
this.add(new RandomWalk());
}
}

class RandomWalk extends ChartPanel {
....
}
 
N

NickPick

[...]
That's exactly what Netbean has done in my case (the Project's Jar
file is in the dist folder and the library jar files are in the
subfolder lib). On the other hand the html file calling the java
applet is in the build folder with a subfolder that contains the
applet.class file.

You may find it useful to enable the Java Console in your browser. On my
platform, this is done using the Java Preferences application.
Do I have to somehow merge these two folders? And why do I really
have to edit the html file so that it includes the Jar files?

Your HTML file has to reflect the locations of your applet class and any
associated jars. In this case, the JFreeChart & JCommon libraries are
required. Given a project named scratch, here is a typical applet tag
and corresponding class declaration:

<applet  width=500 height=400
    code="chart.ChartApplet.class"
    archive="dist/scratch.jar,
        dist/lib/jcommon-1.0.15.jar,
        dist/lib/jfreechart-1.0.12.jar">    
</applet>

package chart;
...
public class ChartApplet extends JApplet {
    public void init() {
        this.add(new RandomWalk());
    }

}

class RandomWalk extends ChartPanel {
...

}

I've put all those file in all possible sub folders and folder but I
still get an error message (albeit slightly shorter): Any advice is
appreciated.

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
 
J

John B. Matthews

NickPick said:
<a89e46a4-5c22-408e-af00-dc991e27b...@m24g2000vbp.googlegroups.com>, [...]
You may find it useful to enable the Java Console in your browser. On my
platform, this is done using the Java Preferences application.
[...]
I've put all those file in all possible sub folders and folder but I
still get an error message (albeit slightly shorter): Any advice is
appreciated.

java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset

When you enable the console, you can use the "l" (ell) command to print
out the class loader list and see what's there. The "x" command is handy
to clear the decks as you make changes.
 
N

NickPick

[...]
That's exactly what Netbean has done in my case (the Project's Jar
file is in the dist folder and the library jar files are in the
subfolder lib). On the other hand the html file calling the java
applet is in the build folder with a subfolder that contains the
applet.class file.

You may find it useful to enable the Java Console in your browser. On my
platform, this is done using the Java Preferences application.
Do I have to somehow merge these two folders? And why do I really
have to edit the html file so that it includes the Jar files?

Your HTML file has to reflect the locations of your applet class and any
associated jars. In this case, the JFreeChart & JCommon libraries are
required. Given a project named scratch, here is a typical applet tag
and corresponding class declaration:

<applet  width=500 height=400
    code="chart.ChartApplet.class"
    archive="dist/scratch.jar,
        dist/lib/jcommon-1.0.15.jar,
        dist/lib/jfreechart-1.0.12.jar">    
</applet>

package chart;
...
public class ChartApplet extends JApplet {
    public void init() {
        this.add(new RandomWalk());
    }

}

class RandomWalk extends ChartPanel {
...

}

Thanks! That works all fine now. However, it means that when I upload
the files the users end up downloading the whole jFreeChart.jar and
jCommon.jar files although only a fraction of them is used. I noticed
that NetBeans creates another Jar File with the name of the project.
Isn't that a compressed version of the classes that are accessed in
the libraries from my program? Would it be possible to use only this
file to start the applet without all the library jar files? If so,
what would I have to put into the archive tag in the html file and
would I still need to upload the .class file? Or is the .class file
included as well in the project .Jar file?
thanks!
 
J

John B. Matthews

[...]
Thanks! That works all fine now. However, it means that when I upload
the files the users end up downloading the whole jFreeChart.jar and
jCommon.jar files although only a fraction of them is used. I noticed
that NetBeans creates another Jar File with the name of the project.
Isn't that a compressed version of the classes that are accessed in
the libraries from my program? Would it be possible to use only this
file to start the applet without all the library jar files?

No, that other JAR is your project's classes. Use the tf option of the
jar command to see what's in it.
If so, what would I have to put into the archive tag in the html file
and would I still need to upload the .class file? Or is the .class
file included as well in the project .Jar file?

I suppose it's technically possible, but laborious. You'd have to study
the license to see about terms for distributing a derivative work. Most
people use JFreeChart on a server or in an application, not an Applet.
Java Web Start is an alternative that saves downloading over and over
when nothing has changed:

<http://java.sun.com/docs/books/tutorial/deployment/webstart/deploying.html>

[Please trim signatures lines when responding.]
 
A

Arne Vajhøj

Lew said:
Alternatively, put the library JARs in a subdirectory of the dir wherein
your main JAR resides. For example, NetBeans likes to build a JAR into
a directory with a subdirectory 'lib/' containing the libraries, e.g.,

dist/ foo.jar
|= lib/ postgresql-8.3-603.jdbc4.jar

It is de facto standard in server products and development
tools.

I am not sure that it is for applets as well.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top