aspose file tools*
The moose likes Beginning Java and the fly likes How to calling a class from another folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to calling a class from another folder" Watch "How to calling a class from another folder" New topic
Author

How to calling a class from another folder

druhy svet
Greenhorn

Joined: Dec 07, 2013
Posts: 2
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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


Ping & DNS - updated with new look and Ping home screen widget
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3946
    
  17

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.


Steve
druhy svet
Greenhorn

Joined: Dec 07, 2013
Posts: 2
Thank you for clarifying.
It is working fine now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to calling a class from another folder
 
Similar Threads
Problem with packages
sip[mple problem any help appreciated
how to get the java code path in RunTime.
Complie time using custom classloader for decryption.
basic packages question