Using Eclipse: an Introduction
STARTING ECLIPSE
- Start eclipse by directly Biologydouble clicking the file "eclipse"
inside the extracted folder (Eg.
/home/
/Desktop/software/eclipse. This could be different and depends on where you have extracted the eclipse archive). - Select the working directory to save your current project. The default directory will be /home/
/workspace
Start A New Project
- Click File->New
- Choose "Dynamic Web Project"
- Provide a name for the project
- Choose the option "New Runtime" and a New runtime window opens
- Choose "Apache Tomcat v7.0" and say Next.
- In the "Tomcat installation directory", browse and select "/home/
/Desktop/software/apache-tomcat-7.0.2" - Click Finish
- Click Finish
- Click File-> New -> Java project -> give project name -> finish
- Right click on project name -> new -> class
- Select "Class" and say Next.
- Give a class name, say "HelloWorld" and say Finish.
- Write a main method inside the class as follows:
- public static void main(String[] args){
System.out.println("Hello world");
} - Save the file(Ctrl+S) and Right-click anywhere in the editor window and select Run As > Run as Java Application
- It runs and prints Hello world in the Console window.
Including the JDBC - PostgreSQL driver in the project build path
- Make sure you have the postgresql JDBC jar file. It can be downloaded from here. After downloading, copy it (Right-click, select copy).
- For normal Java project(simple JDBC) follow these instructions: right click on project name -> Build Path -> configure build path-> libraries (tab) -> Add external Jars -> browse postgresql JDBC jar file-> OK
- For Dynamic Web project (Servlets) follow these instructions: In Eclipse, open Project Explorer, select the current project and browse to WebContent > WEB-INF > lib, and paste(Right-click, select paste) the copied postgresql JDBC jar file 'lib' folder.
- Now, create a new class and copy the contents of the sample JDBC program from here.
- Start your postgresql server before running this program.
- Update the source code with the database name, username, password etc. as described in comments in the sample program.
- Run as Java application(Right-Click, select Run As > Java Application). The sample program takes in a department name and prints out all its student details. Enter a valid dept_name and hit enter. It should print the output successfully.
Comments