We help IT Professionals succeed at work.

Question about inserting a package

Peter Kiers
Peter Kiers asked
Dear Experts,

How can I insert a package in Eclipse?

Watch Question

Awarded 2011
Awarded 2011


If you are talking about adding .jar class library to Eclipse java project - this is the instruction:

Method 3  in that link is the most straightforward one
Peter KiersOperator


Btw what is a package?

And I have a sample called GPSDEMO and I want to reconstruct this sample from scratch
in my project. The only thing that I don't understand is how to use the package from
another example.

Awarded 2011
Awarded 2011

Java classes come in packages - you may design your own application made up of classes belonging to several packages

say, you may some classes in package:



some in pacakge


That means that in you ClassA in frist package

you'll have on the top of your file ClassA.java:

package com.myPackage1;

import com.myPackage2.*;

public class ClassA {////


and your file ClassA.java will have to sit in the folder

in file ClassB in package com.myPackage2

you'll have in filr ClassB.java

package com.myPackage2;

import com.myPackage1.*;

public  class ClassB {


and your file ClassB.java shold be in the folder


then when you are sitting in the folder parent of com folder

you can compile your ClassA with this command

javac com/myPackage1/ClassA.java

and when compiler ecnounters the mentipon of ClassB
it will check the imports declared on top
discover there import com.myPackage2.*

so it will go into this cfolder com/myPackage2/

and will try to locate there file ClassB

All this describes how you'd compile your code if it is in two different packages
Most probably that has nothing directly to do with your situation, but I hoped this will give you some idea
of what is a package.

It is similar if sme of your packages come from other people

So now the question - do you have the java code of "another example".

Or you have just .jar file - and .jar fle is uusually the archive of already compiled classes
Peter KiersOperator


Oke thanks.

Awarded 2011
Awarded 2011


>and when compiler ecnounters the mentipon of ClassB
>it will check the imports declared on top
>discover there import com.myPackage2.*

in this oppassage I meant that when compiler is compiling you ClassA
and in your java code of ClassA it encounters reference of ClassB  (say you create and instance ClassB b = new ClassB() - inside c ode of ClassA)
then it needs to find this ClassB