[program-java] Re: Eclipse Tutorial: Adding Libraries....

  • From: "Giller, Anna" <Anna.Giller@xxxxxxxxxxxxxxx>
  • To: "program-java@xxxxxxxxxxxxx" <program-java@xxxxxxxxxxxxx>
  • Date: Fri, 8 Jul 2011 10:45:44 -0400

Jim, you are the best!

Guys, please, whoever has an access, add this paragraph to our tutorial.

Anna

________________________________
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, July 08, 2011 10:33 AM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Eclipse Tutorial: Adding Libraries....

Adding Jars / Libraries to Eclipse

I'm using Eclipse 3.3 in this example and it may differ from version to version 
so keep that in mind. These notes pertain to only the Eclipse IDE and may or 
may not work for other editors. If you are using MS Notepad or Textpad you will 
have to include these libraries with your commands.

Generally speaking, an IDE will by default have several libraries embedded into 
it's own run time, and example of this is the Java Core Runtime that allows the 
developer the means of using key words in an editor.

E.g. The "if", "do and do while", primitive variables are all provided by the 
Java Core Runtime and are essentially just there with out any special 
considerations.

You can see this in Eclipse by:

I. Opening a code editor or creating a class.

II. With in the class body type

private String myString;
Private static int myInt;

III. With in the default constructor type:

myString = "Hello there";
myInt = 1;

...for all intentional purposes we never really have to worry about such things 
but let's look under the hood.

...from Eclipse:

I. Open the Project Explorer....

II. Select a given project and make sure to expand it.

III. Right click the project.... If you don't have a project you can right 
click on any area of the view.

IV. A pop up menu should appear and select the "Properties" menu option.

You should be placed on the  "Properties for Project XXX" dialog.

V. Select from the Tree View "Java Build Path". And press the TAB key twice. 
This should place you on the Source TAB control.

V. Navigate to the "Libraries" TAB.

VI. With in this TAB you should see a list of all libraries that are part of 
that project whether internal or external.

...by default if everything is correctly configured, the current JRE should be 
visible.

VII. TAB through the controls until you locate the "Add External Jars" button 
and press enter.

A typical "File Dialog" should appear.

VIII. Next navigate to the list of directories.

...for this example I navigate to "C:\APPS\Eclipse_JEE_Europa_CRA_110\plugins", 
your folder / directory may differ.

IX. Locate the following entry: org.eclipse.swt.win32.win32.x86_3.jar.

X. Follow the respective prompts and there you go.

In this example I focused on the SWT plugin but the same methodology applies if 
you were to add let's say Struts or Jasper or any other Jar.

I should say that you can add a single jar in this fashion but you also can 
create your own personal library that contains the jars you commonly use.

Ok, we have added a jar or library to our project. In order to use it though, 
you still have to import it into your class.

At the top of a class you could write:

Import org.eclipse.swt.widgets.Button:

In the body of the class you could add:

Private Button myButton;

In the default constructor:

myButton = new Button(shell, SWT_TOGGLE);

However, if you added the line above with out importing it you could use CTRL + 
SHIFT + O to organize your imports and Eclipse will add the import for the 
Button class automatically.

So, there you go.

Jim

James M. Corbett

Programmer / Analyst |
Canada Revenue Agency | Agence du revenue du Canada
875 Heron Rd.
Ottawa, On.
K1A0L5

James.Corbett@xxxxxxxxxxxxx
Telephone | Téléphone: (613) 941-1338
Facsimile | Télécopieur: (613) 941-2261

Government of Canada | Gouvernement du Canada

"Due to the highly confidential nature of my job, I'm not allowed to know what 
I'm doing."


Other related posts: