• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use Javac compiler on files from different folders ?  RSS feed

 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello , I encountered a problem using javac compiler on the terminal , which is as follows.

I have a folder on my desktop named "JPro".

Inside the folder I have two folders named "One" and "two".

Inside folder "One" I have two java files containing a  simple class and a class containing the main method , both of them compiles fine.

Inside folder "two" I have another java file which too compile fine.

But when I try to import the file inside folder "two" from folder "one" , cannot compile because it do not recognize the file inside folder "two"

So , how can i compile java filed located in different folders from another folder.

My program is like this

/////// Inside Folder JPro //////////

//// Inside Folder One //////

Launcher.java



HelperOne.java



///////////////////////////////


//// Inside Folder Two //////

HelperTwo.java



///////////////////////////////

I am using ubuntu 14.04 and not using any IDE .

Thank You.
 
Mark Spencers
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To compile java files you need to specify full path to files:
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, don't name packages after locations on your computer. The recommended scheme is to use the components of your company's website hostname in reverse order, followed by a component identifying your application, and finally the names of subpackages:
com.example.application.subpackage.

If you don't have a website, pretend you do and make up a hostname.

Package names use dots to separate the components, not slashes.

Finally, your application can have multiple source folders, each acting as a root for your packages. For instance, if your application contains a folder for regular source files and one for test source files, its directory structure might look something like this:

You can compile the test files by specifying all the source folders with the -sourcepath switch:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!