Search code examples
javamulti-project

Calling Various Package From Different Projects


Okay , I am not sure if this is possible or not , Might sound dumb too , Forgive me for that , But is it possible say for example i am using netbeans and i have created various project and they have one package in each which contains certain programs, is it possible that i make a new project and and new package and call them all the above package in one file and run it ?

say for example i have one hexadecimal to decimal converter and another project i have is decminal to hexadecimal and i have created a new project named convertors and have if and else functions in them

i said sout("1)Hexadecimal to decimal convertor 2)Deciminal to hexadecimal , Type number to use the convertor");

  if(userinput=='1')
   {
  call the hexadecimal to decimal convertor
  }
  elseif(userinput=='2')
  {
  call the deciminal to hexadecimal convertor
  }
   else 
  sout("invaild")
   }; 

is the calling of external project or package in one project possible ?

Thanks.


Solution

  • First: It is possible.

    Personally I have never used Netbeans but only Eclipse, however this should work (see original article):

    [...] go to properties of the main project (right-click on the project and choose properties). Go to the Libraries section and choose Add Project. Now you need to find the project folder on your disk and by selecting it, the project's jar is added to the compile classpath

    You of course still have to import the packages in your .java source file to use the corresponding classes that do the conversion. This might look as follows:

    import com.test.converter.hex.*;
    import com.test.converter.dec.*;
    
    class YourClass {
        // your code here
    }
    

    Second: Why do you want to split your work up into separate projects? Isn't it enough to have it in different packages or even different classes? Usually splitting it up into different projects would make sense if you wanted to distribute them differently which seems not to be the case here.