Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Incorporating a class from another directory

Thread view: 
poener - 28 Aug 2006 15:21 GMT
Hello all,

I think this should be a pretty simple question, but I can't figure out
how to do it...

I have written a class in $WHATEVER/Scripts, and I want to use it in a
program that I am writting in $WHATEVER/Control. Since it looks like I
can't use a simple include filename like I would do in C, I would like
to know how should I do it.

=================

A more complicated issue...

The class in $WHATEVER/Scripts reads which devices are connected to the
USB ports of the computer and generates a series of objects with allow
to communicate with those devices.

Now I have to include this class on each java program which wants to
communicate with any of those devices, but I think a much better way of
doing would be to run this communications class once, independently,
and then, when a program needed to communicate with one or several of
these devices, that it could talk to this communications class and
access its objects to talk to the devices... Is there a way of doing
this?

Thank you,

- J.
Andrew Thompson - 28 Aug 2006 15:34 GMT
...
> I have written a class in $WHATEVER/Scripts, and I want to use it in a
> program that I am writting in $WHATEVER/Control. Since it looks like I
> can't use a simple include filename like I would do in C, I would like
> to know how should I do it.

Include the directories containing all necessary classes
on the classpath at runtime.

> Now I have to include this class on each java program which wants to
> communicate with any of those devices,

It needs to be on the *classpath* of each Java program
that uses it, but there only needs to be one copy of it.

>...but I think a much better way of
> doing would be to run this communications class once, independently,
> and then, when a program needed to communicate with one or several of
> these devices, that it could talk to this communications class and
> access its objects to talk to the devices... Is there a way of doing
> this?

The Singleton design pattern would seem to fit this situation.

Andrew T.
poener - 28 Aug 2006 19:47 GMT
Andrew Thompson schrieb:

> ...
> > I have written a class in $WHATEVER/Scripts, and I want to use it in a
[quoted text clipped - 4 lines]
> Include the directories containing all necessary classes
> on the classpath at runtime.

But "javac -classpath ../Scripts *.java" will override all other
classpaths that I have defined in my system...
Andrew Thompson - 28 Aug 2006 23:30 GMT
> Andrew Thompson schrieb:
> > ...
[quoted text clipped - 8 lines]
> But "javac -classpath ../Scripts *.java" will override all other
> classpaths that I have defined in my system...

Which is why you don't type that, but instead consult
the docs. re the separator that allows you to build up classpaths
from more than one location.  (...like - duhhh.)

Andrew T.
poener - 29 Aug 2006 08:24 GMT
> .  (...like - duhhh.)
>
> Andrew T.

Okie dokie...
Andrea Desole - 28 Aug 2006 16:01 GMT
> Now I have to include this class on each java program which wants to
> communicate with any of those devices, but I think a much better way of
[quoted text clipped - 3 lines]
> access its objects to talk to the devices... Is there a way of doing
> this?

are you talking about communication between two virtual machines? Yes,
you can do it, but you have to use something like RMI, or  socket
communication, or something like that. I don't think there is a way to
facilitate the communication between two instances of the JVM running on
the same machine.
You really don't want to do it. If you can use one instance of your
class per virtual machine it's much better.
poener - 28 Aug 2006 16:09 GMT
Ok, thanks for your help, I will use javapath and avoid communication
between virtual machines, since it seems to be too complicated.

- J.

Andrea Desole schrieb:

> > Now I have to include this class on each java program which wants to
> > communicate with any of those devices, but I think a much better way of
[quoted text clipped - 11 lines]
> You really don't want to do it. If you can use one instance of your
> class per virtual machine it's much better.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.