• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Compiling multiple java classes in the dame directory in Windows XP command line

I have two classes one that uses the oher. The first file compiles without any problem, the second gives a compiler error that it doesn't not recognize the object type which has been defined in the first file.

The two files are in the same folder/directory, what am I doing wrong?


something like this

file 1:
------
public class boo
{
   public boo(int x)
...

}

file 2:
------
class usesboo
{
    boo x;
    public usesboo(int y)
...

}
0
polkadot
Asked:
polkadot
  • 6
  • 6
  • 3
  • +3
1 Solution
 
CEHJCommented:
usesboo needs to be public
0
 
polkadotAuthor Commented:
yes it is public, that was a typo
0
 
polkadotAuthor Commented:
** correction

file 2:
------
public class usesboo
{
    boo x;
    public usesboo(int y)
...

}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Try

javac *.java
0
 
polkadotAuthor Commented:
still getting "cannot find symbol" ... I've checked and rechecked spelling of the classes and made sure everything is public
0
 
CEHJCommented:
Can you post your *actual* code?
0
 
objectsCommented:
> still getting "cannot find symbol" ... I've checked and rechecked spelling of the classes and made sure everything is public

which line are you getting that
and what is the compete error
0
 
polkadotAuthor Commented:
getting "cannot find symbol" in file 2 on  statement boo x;

Sorry, I was wrong it does comiple with javac *.java with no problems... but is there any way to get the files to compile independently?

Id like to compile file1 first, then file2 ..
0
 
CEHJCommented:
>>Id like to compile file1 first, then file2 ..

Why so? You'd have to calculate their dependencies yourself and compile them in order (more effort than it's worth ;-))
0
 
objectsCommented:
should work:

javac -classpath . boo.java
javac -classpath . usesboo.java

(shouldn't actuially need the classpath)
0
 
polkadotAuthor Commented:
Okay, everything compiled and I got classes from all my java files now. There is one class with a main method MainProg.java and I'm trying to run it with the command ...

c:\java MainProg

Exception in thread main ... no classdef found error : MainProg


MainProg.class is in the same directory as the other java files and classes ... does this need a classpath too?

0
 
CEHJCommented:
try

java -cp MainProg
0
 
CEHJCommented:
Sorry -typo there:


java -cp . MainProg
0
 
polkadotAuthor Commented:
Okay it worked, but I don't remeber ever having to do this before on another system, why is it so differnt now?
0
 
objectsCommented:
If you clear yuor classpath it will work without that
if you have no classpath then . it used by default
0
 
Manikandan ThiagarajanSenior consultantCommented:
>>If you clear yuor classpath it will work without that.

set classpath=

this command is used to unset the classpath

0
 
hoomanvCommented:
if YourClass is in a package for example package test and you are already in C:\test
you'll be able to compile your code with "javac YourClass"
but you'll get a NoClassDefFoundError if you try "C:\test>java YourClass" within test folder
you need to get out of test (you are then in C:\) and then "C:\>javac test.YourClass"
or if you a were in D:\ you would use "D:\>java -cp D:\ test.A"
0
 
hoomanvCommented:
typo last line should be "D:\>java -cp C:\ test.YourClass "
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW, have you heard of Ant?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 6
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now