• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to use Javac compiler on files from different folders ?

Ranch Hand
Posts: 52
  • 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 //////




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



I am using ubuntu 14.04 and not using any IDE .

Thank You.
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To compile java files you need to specify full path to files:
Saloon Keeper
Posts: 12253
  • 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:

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:
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic