• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

packing classpath errors

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked out a lot of different posts on this subject. I just don't get it.

Both of these classes are saved in the directory C:/J24work/com/testing and they both compile fine with

C:\J24work\com\testing>javac Test.java
C:\J24work\com\testing>javac Test2.java

or

C:\J24work>javac com\testing\Test.java
C:\J24work>javac com\testing\Test2.java





this class is saved in directory C:\J24work. When I try and compile with: (classpath= .; C:\J24work)

C:\J24work>javac TestingEvent.java

I get compile errors like bad class file: /Test2.java, but it's okay it i change the import statement to:

import com.testing.*; ---> import com.testing.Test2;

I would like to know why this is, also what if I had to include a bunch of things from the package, I wouldn't want to import everything separately. I have seen some posts about the classpath looking for class definitions but instead it finds Test2.java first and uses that, but I'm thoroughly confused. Any help.

[Edit]Move code tags. CR[/edit]
 
scott matzka
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have moved all the files to C:\J24work and used this compile code:

C:\J24work>javac -d "C:\J24work" Test.java
C:\J24work>javac -d "C:\J24work" Test2.java

which sends only the Test.class and Test2.class files to C:\J24work\com\testing, but still no dice on the compile of TestingEvent.java using the original import statement, which is import com.testing.*;
 
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a file TestingEvent.java and a nested directory called com/testing in the same higher directory.
You have Test.java and Test2.java in com/testing and TestingEvent.java in the higher-level directory. That is what I did, copying your files. And I got this, once I corrected my own errors!

[Campbell@localhost ~]$ cd java
[Campbell@localhost java]$ mkdir com
[Campbell@localhost java]$ cd com
[Campbell@localhost com]$ mkdir testing
[Campbell@localhost com]$ cd ..
[Campbell@localhost java]$ gedit com/testing/Test.java&
[Campbell@localhost java]$ javac com/testing/Test.java com/testing/Test2.java
[Campbell@localhost java]$ javac TestingEvent.java
[Campbell@localhost java]$ java TestingEvent
test
test2
[Campbell@localhost java]$

If you have all the files in the same directory it would be different, but you have two choices if the directories are already set up.
  • Navigate to lower directories and compile with javac MyFile.java
  • Stay in higher directory and compile with javac com/package/MyFile
  • I did the latter. Note you can compile several files in one instruction. If you compile them separately, TestingEvent has a dependency on Test2 and Test2 has a dependency on Test, so Test2 cannot be compiled before Test and TestingEvent cannot be compiled before Test2.
    Although I am using Linux, you can do the same on Windows, but might have to use \ instead of /.

    Did you find this thread when you searched, and its included links? Or this one (that might be one of the links mentioned earlier)? You should find more information there.

    It ought not to be necessary to set up a classpath variable for this simple application.

    Using javac -d . Test.java will work if you have all the files in one folder; the com and testing folders will be set up by the -d command. The . means start in current directory; I don't know whether that instruction works without the .
     
    scott matzka
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the info. I got it "magically" working a little bit ago. I don't think I changed anything. I compiled from the src directory without issues and ran with issues. Thanks again though.
     
    this is supposed to be a surprise, but it smells like a tiny ad:
    New web page for Paul's Rocket Mass Heaters movies
    https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
    reply
      Bookmark Topic Watch Topic
    • New Topic