Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JAR! . . .What is it good for?. . .Absolutely nothing :-)

Reply
Thread Tools

JAR! . . .What is it good for?. . .Absolutely nothing :-)

 
 
Oliver Wong
Guest
Posts: n/a
 
      12-12-2006

"Richard Maher" <(E-Mail Removed)> wrote in message
news:elmcoe$lor$(E-Mail Removed)...
> Hi,
>
> Well not quite; actually love JAR files, but why does the AppletViewer
> (W2K
> SUN JDK "something", at least) insist on asking for the .CLASS file *as
> well
> as* the .JAR file?
>
> Is this *all* applet viewers? *all* html? or just something *my* code is
> doing?


If I understand your complaint correctly, it's not all applet viewers:
mine doesn't additionally ask for a JAR file when I provide it a CLASS file
nor vice versa. I can't imagine how HTML or the Java source code itself
might trigger this behaviour in your applet viewer program, so I'd have to
say "no" to your other 2 questions as well.

>
> Also why are there no hits on "noclassdeffounderror" on SUN's website?


I believe Roedy's site, mindprod.com, has a good overview of what to do
when you encounter a NoClassDefFoundError.
http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR

>
> In the attached *very short* code snippet, the EmpApplet class is
> attempting
> to invoke methods in the EmpClient class that has been built into the same
> JAR file, but the only Typing that I can see (sorry not my code, but I'm
> told this works on UNIX browsers) is: -
>
> EmpClient client;


I've never heard the term "Typing" before. Based on context, I'm
guessing you're referring to the *declaration* of "client" as being of type
EmpClient.

>
> I'm guessing that this declares "client" as an instance of the EmpClient
> class, but doesn't EmpClient have to be Imported or something?


In your code (which I've snipped), both classes are in the same package
(which happens to be the default, nameless package). Classes which are in
the same package don't need to import one another to be visible to one
another. Note that it's generally considered bad practice to use the default
package. Recommended practice is to put classes in a package whose name is
based on a domain name which you own (this is sort of to provide globally
unique package names). So if you own "google.com", you could call your
package "com.google.mypackage", for example.

> Either way,
> EmpClient is not "inited" and the -debug gives me the noclassdeffounderror
> and the browser makes no attempt to load EmpClient from the codebase.
>
> So, how does one define a class? import?


The problem here isn't that the class isn't defined, but rather that it
class definition could not be found. Check out Roedy's recommendation on
fixing this (the URL again is
http://mindprod.com/jgloss/runerrorm...DEFFOUNDERROR), but
be warned that this is one of the trickier problems to try to fix.

- Oliver


 
Reply With Quote
 
 
 
 
Richard Maher
Guest
Posts: n/a
 
      12-12-2006
Hi,

Well not quite; actually love JAR files, but why does the AppletViewer (W2K
SUN JDK "something", at least) insist on asking for the .CLASS file *as well
as* the .JAR file?

Is this *all* applet viewers? *all* html? or just something *my* code is
doing?

Also why are there no hits on "noclassdeffounderror" on SUN's website?

In the attached *very short* code snippet, the EmpApplet class is attempting
to invoke methods in the EmpClient class that has been built into the same
JAR file, but the only Typing that I can see (sorry not my code, but I'm
told this works on UNIX browsers) is: -

EmpClient client;

I'm guessing that this declares "client" as an instance of the EmpClient
class, but doesn't EmpClient have to be Imported or something? Either way,
EmpClient is not "inited" and the -debug gives me the noclassdeffounderror
and the browser makes no attempt to load EmpClient from the codebase.

So, how does one define a class? import?

Yes, I will google tomorrow but it's late and I'm old. . .

Regards Richard Maher

PS. Sorry for the school boy questions, but I honestly am RTFMing as well.

EmpClient Class
===========

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


public class EmpClient {
public static final String HOSTCHARSET="ISO-8859-1";
public static final byte [] CRLF = {'\r','\n'};
private Socket socket;
private String host;
private int port;
private BufferedReader in;
private OutputStream out;

public class Message
{
String type;
String message;
Message (String type , String message)
{
this.type = type;
this.message = message;
}
public String getMessage()
{
return message;
}
public String getType()
{
return type;
}

}
EmpClient (String host , int port)
{
this.host = host;
this.port = port;
}

public void open () throws UnknownHostException, IOException
{
socket = new Socket (InetAddress.getByName(host) , port);
in = new BufferedReader (new InputStreamReader (socket.getInputStream() ,
HOSTCHARSET));
out = new BufferedOutputStream (socket.getOutputStream());
}

public void close () throws IOException
{
try {
sendMessage ("99","");
} catch (IOException e) {
// close in any situation!
}
socket.close();
}

public void sendMessage (String type , String message) throws IOException
{
byte [] msgtype = type.getBytes(HOSTCHARSET);
byte [] msg = message.getBytes(HOSTCHARSET);

out.write(msgtype);
out.write(msg);
out.write(CRLF);
out.flush();
}
public Message readMessage () throws IOException
{
String wholemsg = in.readLine();

String type = wholemsg.substring(0,2);
String msg = wholemsg.substring(2);
return new Message (type , msg);
}
public void initEmployeeRead (String employee) throws IOException
{
sendMessage ("20" , employee);
}
public String readNextEmployee () throws IOException
{
Message msg = readMessage ();
if (msg.getType().equals("21"))
return msg.getMessage().trim();
return null;
}
}

EmpApplet Class
============

import java.applet.Applet;
import java.io.IOException;


public class EmpApplet extends Applet {
EmpClient client;

public void init ()
{
String host = getParameter("HOST");
int port = Integer.parseInt(getParameter ("PORT"));
client = new EmpClient (host , port);
try {
client.open();
} catch (Exception e) {
client = null;
}
}
public String initEmployee (String employee)
{
try {
client.initEmployeeRead(employee);
return null;
} catch (IOException e) {
return e.getMessage();
}
}
public String nextEmployee ()
{
try {
return client.readNextEmployee();
} catch (IOException e) {
return null;
}
}
public void destroy() {
try {
client.close();
} catch (IOException e) {
}
super.destroy();
}
}




 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-12-2006
Richard Maher wrote:
> Hi,


Please refrain from multi-posting, as well as using
'cute' titles, in future.

(X-post to c.l.j.p./comp.os.vms, w/ f/u to c.l.j.p. only)

Andrew T.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-12-2006
Andrew Thompson wrote:
> Richard Maher wrote:
>> Hi,

>
> Please refrain from multi-posting, as well as using
> 'cute' titles, in future.
>
> (X-post to c.l.j.p./comp.os.vms, w/ f/u to c.l.j.p. only)
>
> Andrew T.


Sorry to disagree, since most always I am with you on the Netiquette
reminders, but I recommend we not suppress 'cute' titles per se. However, to
the OP, if you give a hint as to the actual problem in the title that will
help you get better answers.

If you can do that and still be cute, more power to ye, but most likely you
will find that informative will preclude and trump cute.

- Lew
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-12-2006
Lew wrote:
> Andrew Thompson wrote:
> > Richard Maher wrote:
> >> Hi,

> >
> > Please refrain from ... using 'cute' titles, in future.

...
> Sorry to disagree,


No need for apologies..

>...since most always I am with you on the Netiquette
> reminders, but I recommend we not suppress 'cute' titles per se.


(shrugs) It is not a c.l.j.p. 'policy', nor even my
policy, as such. I would not mention it if that
was the only thing I had to say, but if I am
replying, I will mention it the way I did, and
leave it to the OP's initiative to follow it up..
(but yes, the reasons you mentioned are basically
why I advised against it)

Andrew T.

 
Reply With Quote
 
Richard Maher
Guest
Posts: n/a
 
      12-14-2006
Hi Oliver,

Thanks for your detailed reply, and your patience.

"Oliver Wong" <(E-Mail Removed)> wrote in message
newsxzfh.22160$(E-Mail Removed)...
> I can't imagine how HTML or the Java source code itself
> might trigger this behaviour in your applet viewer program,


It ended up pilot error I looked through the JAR manifest and to my
embarassment I found the EmpApplet and EmpClient classes but sadly no
EmpClient$Message class. Looks like a simple build error; sorry.

I am now getting the, equally lovely, "Incompatible magic value" error
I'm guessing that it's because I'm running the latest and greatest 1.6 JDK
and the JVM on W2K won't work with that (I have run windows update; is there
a seperate JVM download site?) Anyway I have a 1.4.2 JDK on a Windows98 box
that I'll use to build the classes and the Jar and see if that makes a
difference.

> I believe Roedy's site, mindprod.com, has a good overview of what to

do
> when you encounter a NoClassDefFoundError.
> http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR


Good pointer! I think I'll have need of that in the future

> I've never heard the term "Typing" before. Based on context, I'm
> guessing you're referring to the *declaration* of "client" as being of

type
> EmpClient.


May be useful to think of my use of Java and OO terminology as analogous the
Policeman's French accent from the Television series 'allo 'allo. I'm
struggling but you get the general gist of what I'm talking about

> In your code (which I've snipped), both classes are in the same

package
> (which happens to be the default, nameless package). Classes which are in
> the same package don't need to import one another to be visible to one
> another. Note that it's generally considered bad practice to use the

default
> package. Recommended practice is to put classes in a package whose name is
> based on a domain name which you own (this is sort of to provide globally
> unique package names). So if you own "google.com", you could call your
> package "com.google.mypackage", for example.


Good tip! Taken on board.

Thanks again.

Cheers Richard Maher

"Oliver Wong" <(E-Mail Removed)> wrote in message
newsxzfh.22160$(E-Mail Removed)...
>
> "Richard Maher" <(E-Mail Removed)> wrote in message
> news:elmcoe$lor$(E-Mail Removed)...
> > Hi,
> >
> > Well not quite; actually love JAR files, but why does the AppletViewer
> > (W2K
> > SUN JDK "something", at least) insist on asking for the .CLASS file *as
> > well
> > as* the .JAR file?
> >
> > Is this *all* applet viewers? *all* html? or just something *my* code

is
> > doing?

>
> If I understand your complaint correctly, it's not all applet viewers:
> mine doesn't additionally ask for a JAR file when I provide it a CLASS

file
> nor vice versa. I can't imagine how HTML or the Java source code itself
> might trigger this behaviour in your applet viewer program, so I'd have to
> say "no" to your other 2 questions as well.
>
> >
> > Also why are there no hits on "noclassdeffounderror" on SUN's website?

>
> I believe Roedy's site, mindprod.com, has a good overview of what to

do
> when you encounter a NoClassDefFoundError.
> http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR
>
> >
> > In the attached *very short* code snippet, the EmpApplet class is
> > attempting
> > to invoke methods in the EmpClient class that has been built into the

same
> > JAR file, but the only Typing that I can see (sorry not my code, but I'm
> > told this works on UNIX browsers) is: -
> >
> > EmpClient client;

>
> I've never heard the term "Typing" before. Based on context, I'm
> guessing you're referring to the *declaration* of "client" as being of

type
> EmpClient.
>
> >
> > I'm guessing that this declares "client" as an instance of the EmpClient
> > class, but doesn't EmpClient have to be Imported or something?

>
> In your code (which I've snipped), both classes are in the same

package
> (which happens to be the default, nameless package). Classes which are in
> the same package don't need to import one another to be visible to one
> another. Note that it's generally considered bad practice to use the

default
> package. Recommended practice is to put classes in a package whose name is
> based on a domain name which you own (this is sort of to provide globally
> unique package names). So if you own "google.com", you could call your
> package "com.google.mypackage", for example.
>
> > Either way,
> > EmpClient is not "inited" and the -debug gives me the

noclassdeffounderror
> > and the browser makes no attempt to load EmpClient from the codebase.
> >
> > So, how does one define a class? import?

>
> The problem here isn't that the class isn't defined, but rather that

it
> class definition could not be found. Check out Roedy's recommendation on
> fixing this (the URL again is
> http://mindprod.com/jgloss/runerrorm...DEFFOUNDERROR),

but
> be warned that this is one of the trickier problems to try to fix.
>
> - Oliver
>
>



 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-14-2006

"Richard Maher" <(E-Mail Removed)> wrote in message
news:elrds3$3b4$(E-Mail Removed)...
>
> I am now getting the, equally lovely, "Incompatible magic value" error
> I'm guessing that it's because I'm running the latest and greatest 1.6 JDK
> and the JVM on W2K won't work with that (I have run windows update; is
> there
> a seperate JVM download site?) Anyway I have a 1.4.2 JDK on a Windows98
> box
> that I'll use to build the classes and the Jar and see if that makes a
> difference.


Java 1.6 (AKA Java 6, Sun gives a lot of confusing aliases to their
version numbering system) just got officially released a few days ago (it
was previously in beta). You can download the JVM from
http://java.sun.com/javase/downloads/index.jsp

- Oliver


 
Reply With Quote
 
Richard Maher
Guest
Posts: n/a
 
      12-18-2006
Hi Oliver

Thanks for the reply.

"Oliver Wong" <(E-Mail Removed)> wrote in message
news:u9egh.5491$(E-Mail Removed)...
> Java 1.6 (AKA Java 6, Sun gives a lot of confusing aliases to their
> version numbering system) just got officially released a few days ago (it
> was previously in beta). You can download the JVM from
> http://java.sun.com/javase/downloads/index.jsp


I downloaded that version and it certainly progressed things a bit but I'm
still floundering. I'm gonna be a bit contemptuous here and cut and paste a
request I sent to another bloke that's helping me, but if you could have a
quick glance over the versions at least (if nothing else) and let me know if
anything stands out (like the Object tag is dodgy) I'd really appreciate it!

Regards Richard Maher

I'm dying here!

I know you've held my hand and spoon fed me and if I can't tie my own shoe
laces by now then there's no help for me, but *please* look at what I have
done and tell me what I'm doing wrong!

This is Windows 2000 5.00.2195 SP 4 and iexplore 6.0.2800.1106 SUN JDK 1.6.0
(Latest Not beta)

Javac EmpClient.java
Javac EmpApplet.java

/* Maybe I should use the -g switch for debug info as I no longer seem to be
able to "stop at EmpApplet:1" in the Appletviewer anymore and the class and
archive files seem smaller. */

Jar -cf emp.jar EmpApplet.class EmpClient.class EmpClient$Message.class

Jar -tf emp.jar

// Looks good 3115 bytes for emp.jar

FTP to VMS box 1.2.3.6 type=image

$set file/attr=(rfm:udf) emp.jar

*NOW* If I use the <Applet> tag I get the classnotfound error and the reason
is "socket error unexpected end of file" but I have sent 3115 bytes with
your VMS COPY.

So I give up on the applet tag and move to the <OBJECT> tag but I can't find
a useful syntax diagram on the web and certainly not one with your
"verbs/attributes".

In your version you say "<object type=" but I can only find "codetype" in
the html specs and name="" and id="" simply do not exist and are replaced
with "param=".

This is what I'm left with: -

<html>
<head>
<script type="text/javascript">
function empchanged (txt)
{
var selectRef = document.forms[0]["users"];
var optsRef = selectRef.options;
while (optsRef.length > 0)
{
selectRef.remove(optsRef[0]);
}
var val = txt.value;
if (val.length > 0)
{
document.EmpApplet.initEmployee (txt.value);

for (;
{
var emp = document.EmpApplet.nextEmployee ();
if (emp == null)
break;
selectRef.add (new Option (emp,emp) , null);
}
}
}
function setemp (sel)
{
document.forms[0]["employee"].value = sel.options[sel.selectedIndex].value;
}
</script>
</head>
<body>
<form>

<object
width= "0" height= "0" >
<param name="type" value="application/x-java-applet;version=1.6.0">
<param name="archive" value="emp.jar">
<param name="code" value="EmpApplet.class">
<param name="codebase" value="http://1.2.3.6/">
<param name="mayscript" value="yes">
<param name="scriptable" value="true">
<param name="name" value="EmpApplet">
<param name="HOST" value="1.2.3.6">
<param name="PORT" value="3333">
</object>


<input type="text" name="employee" onchange="empchanged (this);"
onkeyup="empchanged (this);">
<select name="users" onchange="setemp(this);"></select>
</form>
</body>
</html>


This code works with the AppletViewer and connects to my VMS name-lookup
server (Which also proves that your mickey-mouse applet uploader is doing
it's job) but won't work with the html as I get (depending on which html
page I try) document.EmpApplet is null or not an object OR Object does not
support this property or method AT
document.EmpApplet.initEmployee(txt.value)

I *have* copied the latest and greatest Frames example and I get "null is
null or not an object" at test.html aka "parent.frames.appletframe.document
is null or not an object"

I come to you cap in hand in all humility knowing full well that I am not
paying you for this and you have much work to do but *FOR PETE'S SAKE* if
this is how hard it is to get a "simple" applet working then no wonder
everyone isn't doing it

Please, please, please no frames, missionary position only code that I can
compile and run on W2K. There is every possibility that I am an idiot and
everyone else can do this, but on the other hand I submit to you that your
code will simply not *compile* and run on W2K.

Who cares? You might say; we are *nix biggots and don't care about that blah
blah blah, but have a heart will ya? I did give the casual observer a DCL
command file that could be just (AT)ed. I'm not asking for that but just
change your /test/ to a remote VMS connection or tell me "You're a dickhead
and everyone knows that your dickie$path environmental variable must be
pointing to /test/ for frame.html to pick up test and test1"



"Oliver Wong" <(E-Mail Removed)> wrote in message
news:u9egh.5491$(E-Mail Removed)...
>
> "Richard Maher" <(E-Mail Removed)> wrote in message
> news:elrds3$3b4$(E-Mail Removed)...
> >
> > I am now getting the, equally lovely, "Incompatible magic value" error


> > I'm guessing that it's because I'm running the latest and greatest 1.6

JDK
> > and the JVM on W2K won't work with that (I have run windows update; is
> > there
> > a seperate JVM download site?) Anyway I have a 1.4.2 JDK on a Windows98
> > box
> > that I'll use to build the classes and the Jar and see if that makes a
> > difference.

>
> Java 1.6 (AKA Java 6, Sun gives a lot of confusing aliases to their
> version numbering system) just got officially released a few days ago (it
> was previously in beta). You can download the JVM from
> http://java.sun.com/javase/downloads/index.jsp
>
> - Oliver
>
>



 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-19-2006
"Richard Maher" <(E-Mail Removed)> wrote in message
news:em6942$4o0$(E-Mail Removed)...
[...]
>
> This is what I'm left with: -
>
> <html>
> <head>
> <script type="text/javascript">
> function empchanged (txt)
> {
> var selectRef = document.forms[0]["users"];
> var optsRef = selectRef.options;
> while (optsRef.length > 0)
> {
> selectRef.remove(optsRef[0]);
> }
> var val = txt.value;
> if (val.length > 0)
> {
> document.EmpApplet.initEmployee (txt.value);
>
> for (;
> {
> var emp = document.EmpApplet.nextEmployee ();
> if (emp == null)
> break;
> selectRef.add (new Option (emp,emp) , null);
> }
> }
> }
> function setemp (sel)
> {
> document.forms[0]["employee"].value =
> sel.options[sel.selectedIndex].value;
> }
> </script>
> </head>
> <body>
> <form>
>
> <object
> width= "0" height= "0" >
> <param name="type" value="application/x-java-applet;version=1.6.0">
> <param name="archive" value="emp.jar">
> <param name="code" value="EmpApplet.class">
> <param name="codebase" value="http://1.2.3.6/">
> <param name="mayscript" value="yes">
> <param name="scriptable" value="true">
> <param name="name" value="EmpApplet">
> <param name="HOST" value="1.2.3.6">
> <param name="PORT" value="3333">
> </object>
>
>
> <input type="text" name="employee" onchange="empchanged (this);"
> onkeyup="empchanged (this);">
> <select name="users" onchange="setemp(this);"></select>
> </form>
> </body>
> </html>
>
>
> This code works with the AppletViewer and connects to my VMS name-lookup
> server (Which also proves that your mickey-mouse applet uploader is doing
> it's job) but won't work with the html as I get (depending on which html
> page I try) document.EmpApplet is null or not an object OR Object does not
> support this property or method AT
> document.EmpApplet.initEmployee(txt.value)


It sounds like your problem has to do with getting JavaScript to talk to
your Java applet, a topic on which I know almost nothing about. If nobody
else answers here, perhaps you can crosspost the above (the FTP stuff, etc.
does not seem relevant to me) to the JavaScript and Java newsgroup, in a new
thread, with a subject line which summarizes the problem like "How to get
JavaScript to talk to my Java applet" or something similar.

- Oliver


 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-19-2006
"Oliver Wong" <(E-Mail Removed)> wrote in message
news:VTThh.86047$(E-Mail Removed)...
> perhaps you can crosspost the above (the FTP stuff, etc. does not seem
> relevant to me) to the JavaScript and Java newsgroup


And in case you don't know how to crosspost, see
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

- Oliver


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re module: Nothing to repeat, but no sre_constants.error: nothing torepeat ? Devin Jeanpierre Python 2 02-14-2012 01:33 PM
Sony, nothing good since the A900? RichA Digital Photography 9 08-26-2009 08:53 PM
treeview renders nothing, but does look good in design view? web.siteMap jobs ASP .Net 1 10-29-2007 08:34 PM
There's nothing customers can't break through good intentions. Woolly Mittens HTML 3 01-07-2004 09:34 PM



Advertisments