Basic question about compiling

S

simplicity

I know this is kind of basic but somehow the solution escapes me.

I have the applet which is supposed to hook up with the hardware
attach to the computer. The hook-up interface is available in the
external JAR archive called sbsdk.jar. So, I compile the applet with
the following command:

javac -d %DST% ^
-classpath %CLASSPATH_1%;%CLASSPATH_2% ^
%SRC%\MyApplet.java >%DST%\MyApplet.log 2>%DST%\MyApplet.err

where
%CLASSPATH_1% points to the location of the sbsdk.jar, namely "C:\Users
\User\\Java\lib\sbsdk.jar"
and
%CLASSPATH_2% points to "%JRE%\lib\plugin.jar" (for JSObject to
communicate with javascript in the page).

OK, so far so good. Applet compiles with no issues. But that's where
it ends. When I load the HTML file containing the applet into a
browser I am getting the exception

Exception in thread "thread applet-MyApplet.class-1"
java.lang.NoClassDefFoundError: com.<blah-blah>.sbsdk/SBSDKListener

Luckily, I have the access to the sbsdk.jar source code. When I copy
the folder structure containing compiled classes of sbsdk (com\<blah-
blah>\sbsdk), my applet loads and everything works as expected.

Can someone help me understand why this is happening? I know that this
is generally caused by SBSDKListener class not being available at the
run time (while it is available at compile time, hence no build
errors) but I do not understand what it means in practical terms.
 
K

Knute Johnson

I know this is kind of basic but somehow the solution escapes me.

I have the applet which is supposed to hook up with the hardware
attach to the computer. The hook-up interface is available in the
external JAR archive called sbsdk.jar. So, I compile the applet with
the following command:

javac -d %DST% ^
-classpath %CLASSPATH_1%;%CLASSPATH_2% ^
%SRC%\MyApplet.java>%DST%\MyApplet.log 2>%DST%\MyApplet.err

where
%CLASSPATH_1% points to the location of the sbsdk.jar, namely "C:\Users
\User\\Java\lib\sbsdk.jar"
and
%CLASSPATH_2% points to "%JRE%\lib\plugin.jar" (for JSObject to
communicate with javascript in the page).

OK, so far so good. Applet compiles with no issues. But that's where
it ends. When I load the HTML file containing the applet into a
browser I am getting the exception

Exception in thread "thread applet-MyApplet.class-1"
java.lang.NoClassDefFoundError: com.<blah-blah>.sbsdk/SBSDKListener

Luckily, I have the access to the sbsdk.jar source code. When I copy
the folder structure containing compiled classes of sbsdk (com\<blah-
blah>\sbsdk), my applet loads and everything works as expected.

Can someone help me understand why this is happening? I know that this
is generally caused by SBSDKListener class not being available at the
run time (while it is available at compile time, hence no build
errors) but I do not understand what it means in practical terms.

Do you have an archive statement in your APPLET tag that lists all the
jar files?

http://docs.oracle.com/javase/1.4.2/docs/guide/misc/applet.html
 
L

Lew

So far all you've done is specify the compile-time classpath.

Because you did not provide the JAR to the runtime classpath!

You need to study the Java tutorial.

Your expectations are what are at fault.

You must provide the dependencies *at run-time*.

We can tell you why this is happening; we cannot help you understand it.

It means, in practical terms, that you neglected to provide the applet with
its dependencies. Consider Knute's question:
Do you have an archive statement in your APPLET tag that lists all the
jar files?

http://docs.oracle.com/javase/1.4.2/docs/guide/misc/applet.html

Presumably he linked you to ancient docs to make the point that nothing has
changed in this area for a very long time.

You should read the tutorials and other documentation.
 
K

Knute Johnson

I do, but I only specify MyApplet.jar there. Does it mean that I
should have sbsdk.jar added to archive attribute?

If you are using classes from sbsdk.jar at runtime, you need to include
that file in the archive statement.
How about plugin.jar? Obviously, I do not have the access to its
compiled classes but this one loads without complains. What's the
difference?

I'm not familiar with what plugin.jar does so I don't know if it would
be included by some other method. So I would try including it.
 
S

simplicity

So far all you've done is specify the compile-time classpath.


Because you did not provide the JAR to the runtime classpath!

You need to study the Java tutorial.


Your expectations are what are at fault.

I guess you are right. When I post the question on the public forum my
expectations are (1) get the answer, regardless of how trivial, basic
and obvious it might be or (2) get a gibberish like the stuff you
spent time on creating.

"Go do your research" is a typical response of a clueless buffoon
whose only characteristic is that he/she cannot keep his/her mouth
shut.
You must provide the dependencies *at run-time*.

Didn't I say that I know WHAT is causing it? I thought I did. What I
do not know is WHY and HOW to fix it.

Anyway, thanks for your time you spent typing your response. Sorry to
state it to you though that it is useless. I always DO my research and
if I decide to go public with questions it means I did not find the
answer myself. I suppose the same applies to majority of folks here
and my advise to you is: give people a bit of a slack.
We can tell you why this is happening; we cannot help you understand it.

And also thanks for your attempt to point out to me how really stupid
I am. I am going to try to improve...
 
S

simplicity

If you are using classes from sbsdk.jar at runtime, you need to include
that file in the archive statement.


I'm not familiar with what plugin.jar does so I don't know if it would
be included by some other method.  So I would try including it.

It contains JSObject which provides the interface between the applet
and Javascrip so I can pass the info back and forth between the applet
and the HTML.

Thanks for the hint. I am going to try.
 
S

simplicity

If you are using classes from sbsdk.jar at runtime, you need to include
that file in the archive statement.


I'm not familiar with what plugin.jar does so I don't know if it would
be included by some other method.  So I would try including it.

Including sbsk.jar in the archive

<applet code="MyApplet.class" archive="MyApplet.jar,sbsdk.jar"
mayscript
width="700" height="500">
</applet>

works.

For some reason I do not need to spec plugin.jar. Well, this is a
"system" archive so maybe there is a global setting of JVM to link it.
Anyway...

Appreciate your help. Thanks.
 
L

Lew

I guess you are right. When I post the question on the public forum my
expectations are (1) get the answer, regardless of how trivial, basic
and obvious it might be or (2) get a gibberish like the stuff you
spent time on creating.

"Go do your research" is a typical response of a clueless buffoon
whose only characteristic is that he/she cannot keep his/her mouth
shut.

So you're saying that reading the documentation is not a good idea?
Didn't I say that I know WHAT is causing it? I thought I did. What I
do not know is WHY and HOW to fix it.

You asked specifically for help understanding the issue. Another respondenthad
given you a recipe for repair; I did not see any point in wasting your time
repeating his good advice. However, that only answered part of your question.
You also asked, "Can someone help me understand why this is happening?" I am so
very sorry I took your question seriously and tried to answer it more fully..
I guess I was under the assumption that you actually wanted the information
that you requested.
Anyway, thanks for your time you spent typing your response. Sorry to
state it to you though that it is useless. I always DO my research and
if I decide to go public with questions it means I did not find the
answer myself. I suppose the same applies to majority of folks here
and my advise [sic] to you is: give people a bit of a slack.

Your answer showed no signs of you having read or understood the very basic
need in Java to have the JAR present at runtime as well as at compile time.
Under the circumstances, telling you what to research and where seemed
appropriate. Now, untwist your knickers, please.
And also thanks for your attempt to point out to me how really stupid
I am. I am going to try to improve...

With that level of response to the help you received, I doubt it.
 
R

Robert Klemme

If you are using classes from sbsdk.jar at runtime, you need to include
that file in the archive statement.

But that's not the only option. The Jar's classpath would be another.

Cheers

robert
 
R

Roedy Green

OK, so far so good. Applet compiles with no issues. But that's where
it ends. When I load the HTML file containing the applet into a
browser I am getting the exception

You either have to put links to the other jars in your jar, or include
their contents. The third way to do it is with JNLP that has a
mechanism for specifying extra jars in the *.jnlp file3.

See http://mindprod.com/jgloss/jar.html
http://mindprod.com/jgloss/jarexe.html
http://mindprod.com/jgloss/classpath.html
http://mindprod.com/jgloss/jnlp.html
 
A

Arne Vajhøj

Including sbsk.jar in the archive

<applet code="MyApplet.class" archive="MyApplet.jar,sbsdk.jar"
mayscript
width="700" height="500">
</applet>

works.

For some reason I do not need to spec plugin.jar. Well, this is a
"system" archive so maybe there is a global setting of JVM to link it.
Anyway...

The Java browser plugin automatically adds plugin.jar - maybe
not so surprising that a plugin uses plugin.jar.

Arne
 
A

Arne Vajhøj

Didn't I say that I know WHAT is causing it? I thought I did. What I
do not know is WHY and HOW to fix it.

If WHY is the question, then you certainly need to study some
more Java.

HOW to fix it was already answered by someone else.
Anyway, thanks for your time you spent typing your response. Sorry to
state it to you though that it is useless. I always DO my research and
if I decide to go public with questions it means I did not find the
answer myself. I suppose the same applies to majority of folks here
and my advise to you is: give people a bit of a slack.

Agreed.

Arne
 
S

simplicity

If WHY is the question, then you certainly need to study some
more Java.

Correct. I am extremely rarely involved in projects requiring Java.
This one is a one-off prototype to see if our toolkit can integrate
with a Java in a browser. I did most of it after looking into docs and
examples from the web: sample applet itself, Java to native interface,
java policies. Unfortunately I tripped on one of the most trivial
steps in the project - everything worked fine in Eclipse and
appletviewer but broke when the same was loaded into a browser.

BTW, didn't it happen to you that you suddenly got the WHY part after
someone showed you the HOW aspect? It did to me on countless
occasions. Just as it did in this case... :).
HOW to fix it was already answered by someone else.

And I expressed my appreciation to him. About a minute of Knute's
typing saved me possibly hours of searching. Big and measurable
difference from Lew's "RTFM, stupid!!!" type of response.

The purpose of the forum like this is to help each other, not to bash
people. Lew with his attitude is definitely in the wrong place.
 
S

simplicity

So you're saying that reading the documentation is not a good idea?

No. What I am saying is that, in the professional world, question
asked, any question for that matter, mandates answer different than
"RTFM" type.
You asked specifically for help understanding the issue.

That's right. What you covered in your answered I got from reading the
exception in the console. So, from the quality point of view you were
not very revealing.
Another respondent had
given you a recipe for repair; I did not see any point in wasting your time
repeating his good advice.

There was a big difference between his and your replies. If you don't
see this, well, too bad...
However, that only answered part of your question.
You also asked, "Can someone help me understand why this is happening?" Iam so
very sorry I took your question seriously and tried to answer it more fully.
I guess I was under the assumption that you actually wanted the information
that you requested.

Wrong. You wrote, quote, "We can tell you why this is happening; we
cannot help you understand it." I do not know who that "we" is in your
statement, the fact remains that "we" did neither.

OK, I got the help I sought and a bit of entertainment at the same
time.

Cheers...
 
A

Arne Vajhøj

Correct. I am extremely rarely involved in projects requiring Java.
This one is a one-off prototype to see if our toolkit can integrate
with a Java in a browser. I did most of it after looking into docs and
examples from the web: sample applet itself, Java to native interface,
java policies. Unfortunately I tripped on one of the most trivial
steps in the project - everything worked fine in Eclipse and
appletviewer but broke when the same was loaded into a browser.
BTW, didn't it happen to you that you suddenly got the WHY part after
someone showed you the HOW aspect?

More times than I can count.

Arne
 
A

Arved Sandstrom

Correct. I am extremely rarely involved in projects requiring Java.
This one is a one-off prototype to see if our toolkit can integrate
with a Java in a browser. I did most of it after looking into docs and
examples from the web: sample applet itself, Java to native interface,
java policies. Unfortunately I tripped on one of the most trivial
steps in the project - everything worked fine in Eclipse and
appletviewer but broke when the same was loaded into a browser.

BTW, didn't it happen to you that you suddenly got the WHY part after
someone showed you the HOW aspect? It did to me on countless
occasions. Just as it did in this case... :).
[ SNIP ]

HOW without the WHY is often legit. In fact you may never need to know
the WHY. That's why we've got dozens upon dozens of domain specialists
in software development. Even an individual who seems to know how to do
everything by themselves - e.g. learns how to configure a new app server
(SSL, LDAP/S, database connections, JMS, clustering, security realms
etc) in a day or less - is probably just someone who has been in the
business long enough that they have become very good at locating,
reading and applying all the HOW material: instruction manuals, online
forums, READMEs and what have you. In a number of areas there may not be
that deep WHY knowledge...and often there doesn't need to be.

Even in teaching situations where the WHY is important, and has to be
communicated, there are many approaches to getting it across. Like you
suggested, with some people you do best in showing them a HOW, and the
they make good progress with the WHY. I know folks like this. Then there
are others, and I know some like this, who do best with WHY instruction,
and only then do they handle the HOW. Most people are a combination of
the two: I learn some things best with a HOW->WHY approach, other things
best with a WHY->HOW approach.

Many of us have built C/C++ executables or libraries from scratch, on
various operating systems. Maybe it's the ./configure, make, make
install sequence, or equivalents in the VS world, doesn't matter. The
point is that most of the time we're not building the executable or
shared library because we have any interest in the source of what we're
building, and often we don't even have the slightest interest in *what*
we're building. We simply need that executable or library on the path to
accomplishing something else productive, and that build process is the
only way to get the correct binary.

Under the circumstances, if halfway through "make" you get a complicated
compile or link error, do you really care about the WHY? Not bloody
likely. If you looked at the README and INSTALL, and they even had a
section specific to your OS there, and you followed the instructions,
that error is an unexpected nuisance. If you're like me you just want to
know HOW to fix it, and couldn't care less about WHY. Off to Google we
go with the exact error, often we're lucky and some dude has a patch
suggestion for obscure.cpp or someone else tells you to tweak a compile
switch for OS version 13.4.2 because the INSTALL docs were for version
13.4.0. And you do it mindlessly, your build and install succeeds, you
often never understood the WHY, and you don't care.

It's possible to get too hung up on the "give a man a fish, teach a man
to fish" idea. Frequently the most productive thing to do, for all
concerned, is just to give the man a fish.

In other spheres of human activity we already know to balance and ration
the HOW and WHY accordingly. We do that both in horizontal and vertical
silos. Why should it be any different in software development?

As far as any given responder is concerned, we all have our strengths.
None of us are good with all the domain areas, nor with all types of
questions. By and large Lew is among the more consistently good
responders in the NG, but he'll be a mismatch for some posters. We all
are from time to time. Best thing to do is suck it up, you'll eventually
get a suitable answer, like this time from Knute. Doesn't mean that the
next time you ask on this group that your best answer won't come from Lew.

AHS
 
A

Arne Vajhøj

No. What I am saying is that, in the professional world, question
asked, any question for that matter, mandates answer different than
"RTFM" type.

Occasionally RTFM is the best answer.

If the level of the question is below what is the expectation
in the group.

Arne
 
L

Lew

Arne said:
Occasionally RTFM is the best answer.

If the level of the question is below what is the expectation
in the group.

"simplicity", you seriously need to get over yourself. This is not your
personal, private little slave pool to offer answers to any questions you ask
and take abuse from you. This is a Usenet *discussion* group, and any help you
get is at the discretion and voluntary desire to help of the other
participants.

It is just too bad for you that you didn't find my answer helpful, but thatis
not any kind of excuse for your rudeness and ingratitude and downright
snarkiness. You have no basis whatsoever for this arrogant attitude of
entitlement you evince, nor have I done anything so rude as to merit the kind
of personal attack in which you've engaged. The answers I gave are helpful to
you, should you get down off your high horse to do the kind of studying and
learning you so clearly need to do. As Arne said, this newsgroup will point
you to basic documentation if that exists for basic questions such as yours..

It is a personal failing on your part, and a darned shame, "simplicity", that
you cannot or will not observe the rudiments of basic human decency and
understand your proper place here. We are all equals here; none of us is your
subordinate, not that you should behave that way to subordinates either.
 
S

simplicity

Occasionally RTFM is the best answer.

Disagreed. Just ask yourself this question: how long would you survive
in the organization if you gave your colleague the "RTFM answer"? I
thing you would be a history before the day's end.

Why would this forum be any different than the organization we work
for?
If the level of the question is below what is the expectation
in the group.

Who are we to make ruling on "expectations in the group"?

We progress when we can build from what our predecessors accomplished.
Starting from zero and going through the same over and over - sort of
what Lew's suggested in his reply, is counter to this philosophy. And
when I read his latest post it makes me think tat he still does not
get it.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top