Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bad magic number

0 views
Skip to first unread message

Peter Kirk

unread,
Jul 2, 2004, 4:33:12 AM7/2/04
to
Hi there

I need to make some extensions to an applet I have (packaged as a jar), and
need to use a few other 3rd party jar files.

(1) Is it possible to package these extra jar files inside my jar file; or
do I need to unjar the other jars and include the class files in my jar.

(2) What does "bad magic number" mean? I get this message in the java
console when I try to run my applet. The applet works fine without the extra
classes, but if I try to include them, I get the bad magic number message.
Oddly enough the message says my main applet class has a bad magic number -
yet I know it works, and the only difference is that I have included some
3rd party class files in my jar.


Thanks,
Peter

Christophe Vanfleteren

unread,
Jul 2, 2004, 4:41:42 AM7/2/04
to
"Peter Kirk" <peter> wrote:

> Hi there
>
> I need to make some extensions to an applet I have (packaged as a jar),
> and need to use a few other 3rd party jar files.
>
> (1) Is it possible to package these extra jar files inside my jar file; or
> do I need to unjar the other jars and include the class files in my jar.
>

Yes, you'd need to unjar them first.

> (2) What does "bad magic number" mean? I get this message in the java
> console when I try to run my applet. The applet works fine without the
> extra classes, but if I try to include them, I get the bad magic number
> message. Oddly enough the message says my main applet class has a bad
> magic number - yet I know it works, and the only difference is that I have
> included some 3rd party class files in my jar.

Those 3rd party jars are probably compiled for a higher version of Java then
the JVM you're using (eg. compiled with -target=1.4, and you try to run it
on 1.3).

--
Kind regards,
Christophe Vanfleteren

Peter Kirk

unread,
Jul 2, 2004, 4:48:55 AM7/2/04
to
Wow, quick reply!

"Christophe Vanfleteren" <c.v4nf...@pandora.be> skrev i en meddelelse
news:ad9Fc.172003$bu3.8...@phobos.telenet-ops.be...


> "Peter Kirk" <peter> wrote:
> > (2) What does "bad magic number" mean? I get this message in the java
> > console when I try to run my applet. The applet works fine without the
> > extra classes, but if I try to include them, I get the bad magic number
> > message. Oddly enough the message says my main applet class has a bad
> > magic number - yet I know it works, and the only difference is that I
have
> > included some 3rd party class files in my jar.
>
> Those 3rd party jars are probably compiled for a higher version of Java
then
> the JVM you're using (eg. compiled with -target=1.4, and you try to run it
> on 1.3).

Well, actually my applet uses 1.4 stuff, and the browser is confugured to
use 1.4. Could it be the other way around - the 3rd party class files are
compiled with 1.3, and won't run under 1.4?

But why does it report a "bad magic number" in my class? My class doesn't
change, the only difference is that I package extra 3rd party classes in my
jar. And, as a matter of fact, I am not even referencing the 3rd party
classes yet from my applet (they are just sitting there in the jar).

Thanks,
Peter

Roedy Green

unread,
Jul 2, 2004, 11:25:44 AM7/2/04
to
On 2 Jul 2004 10:33:12 +0200, "Peter Kirk" <peter> wrote or quoted :

>(1) Is it possible to package these extra jar files inside my jar file; or
>do I need to unjar the other jars and include the class files in my jar.

You have two options:

1. mention more than one jar in the applet tags to invoke the Applet.
This approach is preferable if one of the jars contains classes you
might not use in any given run. See
http://mindprod.com/jgloss/applet.html

2. unpack the jars and repack them into one big one with jar.

What won't work is nesting jars, putting entire jars inside jars.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Roedy Green

unread,
Jul 2, 2004, 11:26:21 AM7/2/04
to
On 2 Jul 2004 10:33:12 +0200, "Peter Kirk" <peter> wrote or quoted :

>(2) What does "bad magic number" mean?

see http://mindprod.com/jgloss/errormessages.html#BADMAGICNUMBER

Peter

unread,
Jul 2, 2004, 2:58:50 PM7/2/04
to
"Roedy Green" <loo...@mindprod.com.invalid> skrev i en meddelelse
news:sjvae09eh5q50jik6...@4ax.com...

> On 2 Jul 2004 10:33:12 +0200, "Peter Kirk" <peter> wrote or quoted :
>
> >(2) What does "bad magic number" mean?
>
> see http://mindprod.com/jgloss/errormessages.html#BADMAGICNUMBER

Good description, but I can't think it applies to my situation
unfortunately....

My webserver is running on the same machine as the classes are compiled, so
there is no FTP involved. Could there be a problem with the browser
"downloading" the jar file? (The browser is also running on the same
machine).

If the error is being reported because a class can't be found then I really
don't understand that either. The class it reports "bad magic number" for is
my main applet class - which I know is there because I can see it in the jar
file, and it runs if I don't include the 3rd party classes when I make the
jar.

Mysterious.

Thanks,
Peter


Roedy Green

unread,
Jul 2, 2004, 3:06:16 PM7/2/04
to
On 2 Jul 2004 20:58:50 +0200, "Peter" <peter@ciber> wrote or quoted :

>My webserver is running on the same machine as the classes are compiled, so
>there is no FTP involved. Could there be a problem with the browser
>"downloading" the jar file? (The browser is also running on the same
>machine).

Examine the class file in question. It should start with CAFEBABE.

Perhaps you are trying to load something that is not even a class
file.

Roedy Green

unread,
Jul 2, 2004, 3:09:17 PM7/2/04
to
On 2 Jul 2004 20:58:50 +0200, "Peter" <peter@ciber> wrote or quoted :

>If the error is being reported because a class can't be found then I really
>don't understand that either. The class it reports "bad magic number" for is
>my main applet class - which I know is there because I can see it in the jar
>file, and it runs if I don't include the 3rd party classes when I make the
>jar.

Post the exact text of the error message.

Post the exact text of the member name of your main class, taken from
inside the jar, peeking with winzip.

Post a hex dump of the first line of that class file.

Post your classpath.

Post the exact line you used to invoke the jar.

You may be getting some OTHER copy of the class lying about on the
classpath.

Peter Kirk

unread,
Jul 5, 2004, 4:00:00 AM7/5/04
to
"Roedy Green" <loo...@mindprod.com.invalid> skrev i en meddelelse
news:6icbe0tg471o0a4v3...@4ax.com...

> On 2 Jul 2004 20:58:50 +0200, "Peter" <peter@ciber> wrote or quoted :
>
> >If the error is being reported because a class can't be found then I
really
> >don't understand that either. The class it reports "bad magic number" for
is
> >my main applet class - which I know is there because I can see it in the
jar
> >file, and it runs if I don't include the 3rd party classes when I make
the
> >jar.
>
> Post the exact text of the error message.

Well, this time when I run it it says "class not found", and not a "bad
magic number" like last time. Hmm.
This text comes from the java console:

load: class dk.ciber.danbro.applets.elementTree.ElementApplet.class not
found.
java.lang.ClassNotFoundException:
dk.ciber.danbro.applets.elementTree.ElementApplet.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:162)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:566)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
at sun.applet.AppletPanel.run(AppletPanel.java:298)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:265)
at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)
at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:152)
at java.security.AccessController.doPrivileged(Native Method)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:149)
... 9 more


> Post the exact text of the member name of your main class, taken from
> inside the jar, peeking with winzip.

ElementApplet.class


> Post a hex dump of the first line of that class file.

I am not sure how much the first line is, but here is a short dump...

ca fe ba be 00 00 00 2e 03 fa 01 00 31 64 6b 2f 63 69 62 65 72 2f 64 61 6e
62 72 6f 2f 61 70 70 6c 65 74 73 2f 65 6c 65 6d 65 6e 74 54 72 65 65 2f 45
6c 65 6d 65 6e 74 41 70 70 6c 65 74 07 00 01 01 00 13


> Post your classpath.

Embarrassingly I must admit that I don't know how to find this! The applet
is loaded via HTML generated via JSP, which is invoked from a
web-application running under Tomcat (on a windows 2000 machine). Where do I
find the classpath?


> Post the exact line you used to invoke the jar.

The jar file containing the applet, and all the extra 3rd party classes, is
called "anlaeg.jar", and it is loaded like this in the JSP:

<DIV id=viewapplet style="z-index:99">
<APPLET
name="DanBroApplet"
code="dk.ciber.danbro.applets.elementTree.ElementApplet.class"
archive="<%=serverUrl%>/lib/anlaeg.jar"
align="center" height="100%" width="100%"
mayscript
id="danbroappletten"
style="z-index:99">
<param name="base-server-url" value="<%=serverUrl%>" />
<param name="scriptable" value="true" />
</APPLET>
</DIV>`


> You may be getting some OTHER copy of the class lying about on the
> classpath.

I don't think so, because any small changes I make, for exmple a new
"debug", are executed (as long as I don't include the 3rd party classes that
is). So I am pretty sure that the correct class is found and executed.


Thanks for your help,
Peter

Roedy Green

unread,
Jul 5, 2004, 11:22:21 AM7/5/04
to
On 5 Jul 2004 10:00:00 +0200, "Peter Kirk" <peter> wrote or quoted :

>Embarrassingly I must admit that I don't know how to find this! The applet
>is loaded via HTML generated via JSP, which is invoked from a
>web-application running under Tomcat (on a windows 2000 machine). Where do I
>find the classpath?

see http://mindprod.com/jgloss/classpath.html
http://mindprod.com/wassup.html
http://mindprod.com/jgloss/properties.html

it is one of the system proprieties. Just print it out.

Roedy Green

unread,
Jul 5, 2004, 11:24:09 AM7/5/04
to
On 5 Jul 2004 10:00:00 +0200, "Peter Kirk" <peter> wrote or quoted :

>
><DIV id=viewapplet style="z-index:99">
><APPLET
>name="DanBroApplet"
>code="dk.ciber.danbro.applets.elementTree.ElementApplet.class"
>archive="<%=serverUrl%>/lib/anlaeg.jar"
>align="center" height="100%" width="100%"
>mayscript
>id="danbroappletten"
>style="z-index:99">
><param name="base-server-url" value="<%=serverUrl%>" />
><param name="scriptable" value="true" />
></APPLET

What does that look like when it gets to the user as HTML?

the suspicious part in the archive parm.

Roedy Green

unread,
Jul 5, 2004, 11:27:10 AM7/5/04
to
On 5 Jul 2004 10:00:00 +0200, "Peter Kirk" <peter> wrote or quoted :

>
>> You may be getting some OTHER copy of the class lying about on the
>> classpath.
>
>I don't think so, because any small changes I make, for exmple a new
>"debug", are executed (as long as I don't include the 3rd party classes that
>is). So I am pretty sure that the correct class is found and executed.

I don't think that is true. Your Applet is not even starting. It may
work when you run it locally, but that is a whole different kettle of
fish.

Peter Kirk

unread,
Jul 6, 2004, 3:28:54 AM7/6/04
to
"Roedy Green" <loo...@mindprod.com.invalid> skrev i en meddelelse
news:iisie059ua1mehogm...@4ax.com...

> On 5 Jul 2004 10:00:00 +0200, "Peter Kirk" <peter> wrote or quoted :
> >
> ><DIV id=viewapplet style="z-index:99">
> ><APPLET
> >name="DanBroApplet"
> >code="dk.ciber.danbro.applets.elementTree.ElementApplet.class"
> >archive="<%=serverUrl%>/lib/anlaeg.jar"
> >align="center" height="100%" width="100%"
> >mayscript
> >id="danbroappletten"
> >style="z-index:99">
> ><param name="base-server-url" value="<%=serverUrl%>" />
> ><param name="scriptable" value="true" />
> ></APPLET
>
> What does that look like when it gets to the user as HTML?

<DIV id=viewapplet style="z-index:99">
<APPLET
name="DanBroApplet"
code="dk.ciber.danbro.applets.elementTree.ElementApplet.class"

archive="http://pak:8080/danbro/lib/anlaeg.jar"


align="center" height="100%" width="100%"
mayscript
id="danbroappletten"
style="z-index:99">

<param name="base-server-url" value="http://pak:8080/danbro" />


<param name="scriptable" value="true" />
</APPLET>

</DIV>

> the suspicious part in the archive parm.

"pak" is the name of my computer.
If I enter http://pak:8080/danbro/lib/anlaeg.jar in my browser window, then
internet explorer asks if I want to download the file, and I can save it to
another place on my harddisk - so the browser can indeed find the jar.


Thanks again,
Peter

Peter

unread,
Jul 6, 2004, 5:12:13 PM7/6/04
to
"Roedy Green" <loo...@mindprod.com.invalid> skrev i en meddelelse
news:cgvae093uoirlj9fi...@4ax.com...

> On 2 Jul 2004 10:33:12 +0200, "Peter Kirk" <peter> wrote or quoted :
> 1. mention more than one jar in the applet tags to invoke the Applet.
> This approach is preferable if one of the jars contains classes you
> might not use in any given run. See
> http://mindprod.com/jgloss/applet.html

This works for me!

I really didn't believe that it would make a difference whether you unpacked
the various jar files, and then packed them into one jar file for the APPLET
tag; or if you kept the jars intact and supplied their names in a
comma-separated list in the APPLET tag...

but, well, it did make a difference. My applet likes it better if it is in
its own jar, and the 3rd party jars stay in theirs.

My applet runs normally now (ie. as it did before I started adding 3rd party
stuff into the mix). And now I can actually start using the 3rd party
jars...

Thanks heaps for your patience and help!

Peter


FISH

unread,
Jul 7, 2004, 8:56:31 AM7/7/04
to
"Peter Kirk" <peter> wrote in message news:<40ea54b6$1...@news.wineasy.se>...
[snipped...]

> <DIV id=viewapplet style="z-index:99">
> <APPLET
> name="DanBroApplet"
> code="dk.ciber.danbro.applets.elementTree.ElementApplet.class"
^^^^^
Try getting rid of the .class on the end of the class name, then see
what happens. The exception you posted would suggest it is being
treated as part of the fully qualified class name.


-FISH- ><>

0 new messages