• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to use Javac compiler on files from different folders ?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To compile java files you need to specify full path to files:
 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic