• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Compiling Question

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let's say I am writing a JAva Application.
I have 2 classes:
1. Class A
2. Class B
Class A contains main() and inside main I instantiate Class B. ClassB cb = new ClassB();
Now let's say that I am ready to compile my code. Is there a way that you can force the compiler to check for dependencies and compile those classes first instead of compiling each class individually? That way I can Compile Class A which will force Class B to get compiled first?
Hope that makes sense.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My compilers (1.3.1_02 and 1.4) from Sun do this without any switch settings. Does yours not?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using 1.4 and it does not. However, I am compiling through an IDE (JCreator). I will compile outside of the IDE and see what happens.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might need to specify the sourcepath location.
Sun's documentation on javac explains the switches available.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JCreator also failed for me.
Update - This does work fine for me with JCreator without setting the sourcepath or making any other changes. Previously, I had a problem with the classpath setting - ".;" had been omitted.
B.java is even automatically compiled when in a different package.
[ May 13, 2002: Message edited by: Dirk Schreckmann ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here are my two files.

-----------------------------------

Now, classB has not been compiled yet. And when I try and compile Class A, the compiler tells me it doesn know Class B. "Cannot Resolve Symbol".
Here is how I am compiling.
javac ClassA.java
Any suggestions?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this is a directory/package structure issue. What is your (relevant) directory structure? Where are the source code files? What is your working directory (what directory are you in) when you compile?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, here is how it is
c:\Test - contains Source files
c:\Test\classes - Will contain my class files.
I am in this dirctory when I compile.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far, the only way I can get it to work when both classes are part of the same specified package, is to compile from the parent directory (from c:\Test) with:
javac c:\Test\classes\ClassA.java
and then both files are compiled.
[ May 13, 2002: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I can get it to work from the classes directory if I specify the parent directory in my classpath.
So, from c:\test\classes:
javac -classpath "c:\Test;%classpath%" ClassA.java
Does this work for you? Has any of this helped yet?
 
Honk if you love justice! And honk twice for tiny ads!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic