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 / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

If . is in classpath doesn't that pull in classes in the current folder?

Thread view: 
George Hester - 02 Apr 2004 00:38 GMT
This compiles without issue:

package standalone;
/**
* MIMEType.java
*/
public class MIMEType
{
/**A MIME type is made up of 2 parts
 * contentType/subtype
 */
protected String contentType;
protected String subtype;

public MIMEType(String type)
{
 int slash = type.indexOf('/');
 contentType = type.substring(0, slash - 1);
 subtype = type.substring(slash + 1, type.length());
}

public MIMEType(String contentType, String subtype)
{
 this.contentType = contentType;
 this.subtype = subtype;
}

public String toString()
{
 return contentType + "/" + subtype;
}
} // MIMEType

But this doesn't:

package standalone;

/**
* FileClassifier.java
*/

public class FileClassifier
{
static MIMEType getMIMEType(String fileName)
{
 if (fileName.endsWith(".gif")){
  return new MIMEType("image", "gif");
 } else if (fileName.endsWith(".jpeg")) {
  return new MIMEType("image", "jpeg");
 } else if (fileName.endsWith(".mpg")) {
  return new MIMEType("video", "mpeg");
 } else if (fileName.endsWith(".txt")) {
  return new MIMEType("text", "plain");
 } else if (fileName.endsWith("html")) {
  return new MIMEType("text", "html");
 } else
  // fill in lots of other types,
  // but eventually give up and
  return null;
}
} // FileClassifier

The MIMEType.class exists in the same folder as FileChooser.java.  But FileChooser.java won't compile with this error:

C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\MIME
Class>javac FileClassifier.java
FileClassifier.java:9: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
       static MIMEType getMIMEType(String fileName)
              ^
FileClassifier.java:12: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
                       return new MIMEType("image", "gif");
                                  ^
FileClassifier.java:14: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
                       return new MIMEType("image", "jpeg");
                                  ^
FileClassifier.java:16: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
                       return new MIMEType("video", "mpeg");
                                  ^
FileClassifier.java:18: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
                       return new MIMEType("text", "plain");
                                  ^
FileClassifier.java:20: cannot resolve symbol
symbol  : class MIMEType
location: class standalone.FileClassifier
                       return new MIMEType("text", "html");
                                  ^
6 errors

Any suggestions?

Signature

George Hester
__________________________________

Roedy Green - 02 Apr 2004 00:51 GMT
See http://mindprod.com/jgloss/classpath.html

Not quite. What it does is look in the directory tree of pathnames
ROOTED in the current directory for classes.  

If for example you had a class called com.mindprod.bulk.Resend
e.g. class Resend in package com.mindprod.bulk,

and you did cd \
and had classpath .
then it would find the class file in:
com/mindprod/bulk/Resend.class

If you did cd \com\mindprod\bulk\
and had classpath .
then it would expect to find the class file in:
com/mindprod/bulk/com/mindprod/bulk/Resend.class

If you did cd \com\mindprod\bulk\
and had classpath C:\
then it would expect to find the class file in:
com/mindprod/bulk/Resend.class

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
George Hester - 02 Apr 2004 02:08 GMT
OK I understood what you are are talking about here.  
But my package is standalone so I assume that means there is no hierarchy here.
The class is just in the folder that the java is in that it was compiled from.  So in this case the ROOT is the folder.  Right?  Do my error messages look like "class not found?"  Any idea how to fix the example I posted?  Thanks.

Signature

George Hester
__________________________________

> See http://mindprod.com/jgloss/classpath.html
>
[quoted text clipped - 23 lines]
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
George Hester - 02 Apr 2004 02:14 GMT
Hi again Roedy.  You kniow what?  That fixed it.  I was surprised when I compiled MIMEType.java that a folder standalone was not made.  I assumed that standalone meant "standalone" and so assumed that the class apearing in the current folder was what "standalone" meant.  I guess I was wrong.  Because following what you said I made a subfolder off the current folder called standalone and put MIMEType.class in there.  Then in the ROOT (the current folder) I javac FileChoose.java.  It worked.  Thanks.

Signature

George Hester
__________________________________

> See http://mindprod.com/jgloss/classpath.html
>
[quoted text clipped - 23 lines]
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Chris Smith - 02 Apr 2004 15:05 GMT
> Hi again Roedy.  You kniow what?  That fixed it.  I was surprised when I
> compiled MIMEType.java that a folder standalone was not made.  I assumed
[quoted text clipped - 3 lines]
> current folder called standalone and put MIMEType.class in there.  Then
> in the ROOT (the current folder) I javac FileChoose.java.  It worked.

George,

Since FileChoose was also in the standalone package in your code, you'd
be better off moving both of those source files to a directory called
stand-alone, and then issuing (from the PARENT of that directory) the
command:

  javac standalone/Whatever.java

Also, the -d option to javac will tell the compiler where to put the
compiled class files *and* tell it to automatically create the required
subdirectories for packages.  I would never recommend using javac
without the -d option.  Specifying '-d .' will probably get the behavior
you expected; but I'd strongly recommend creating a separate directory
called something like 'bin' or 'build' to contain these build files.  
Makes it much easier to separate source from binary in the future.

So, your complete command:

   cd src
   javac -d ../bin standalone/Whatever.java

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

George Hester - 03 Apr 2004 05:57 GMT
Thanks I will be looking into what you describe.  I have seen the package stuff in action in a different example from "Thining in Java" so I understand it a little better now.

Signature

George Hester
__________________________________

> > Hi again Roedy.  You kniow what?  That fixed it.  I was surprised when I
> > compiled MIMEType.java that a folder standalone was not made.  I assumed
[quoted text clipped - 25 lines]
>     cd src
>     javac -d ../bin standalone/Whatever.java
Andrew Thompson - 04 Apr 2004 08:31 GMT
> Thanks I will be looking into what you describe.  

Could you also look into various other
things George?

a) Not top-post.  The combination of your t-p,
your sig-delimiter ('-- ') and what news readers
are supposed to do (trim earlier sigs) means
everything written by Chris was _automatically_
deleted from this reply, wherea it is usually relevant

b) Trim the earlier comments, so you only
quote what you are responding to.  Otherwise
posts get very big..

Would be appreciated..

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

George Hester - 04 Apr 2004 20:39 GMT
Basically you are telling me to get a different Newsreader.  I don't think I'll be doing that.
But I will try to make my posts less irritating.  As for the top posting issue.  That again
is a result of my newsreader and the fact that I don't like bottom posting.  Note that
if top posting irritates you remember bottom posting irrritates me.

I understand that bottom posting is the Way of the World.  This world anyway.

George Hester
__________________________________

> > Thanks I will be looking into what you describe.  
>
> Could you also look into various other
> things George?
>
> a) Not top-post.  The combination of your t-p,

> b) Trim the earlier comments, so you only
posts get very big..

> Would be appreciated..


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.