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

How to calling a class from another folder

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings all,

I am very new to Java...starting out with basics.
So not using any IDE, just plain Notepad and compiling and running from command line.

I was trying to call a method of a class in another folder. But getting an error.
Placing the codes below.

Folder 1: H:\J\A\
File: Test.java




Compiled this.
H:\J\A>javac Test.java

No errors.


Second Java file which contains 'Main' and calls the 'Test' class.

Folder 2: H:\J\B\
File: UseTest.java



When trying to compile this -
H:\J\B>javac -classpath H:\J\A\; H:\J\B\UseTest.java

compiled fine.

But when trying to run this-
H:\J\B>java -classpath H:\J\A\; H:\J\B\UseTest

got error-
Error: Could not find or load main class H:\J\B\UseTest

Can somebody help me with this?

Thanks in advance.

~DS

edit: added code tags /SL
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

If you keep classes in separate directory trees, then you need to add all of them to the classpath, like java -classpath H:\J\A\;H:\J\B UseTest. You can't specify any directory as part of the class name.

The usual approach to keeping source and class files in separate directories, but still have only a single directory tree, involves packages: http://docs.oracle.com/javase/tutorial/java/package/index.html
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch!

I went and added code tags to your post so the code is easier to read. Please see UseCodeTags to see how.
 
druhy svet
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for clarifying.
It is working fine now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic