Difference between revisions of "Eclipse: Tutorial Penggunaan"

From OnnoWiki
Jump to navigation Jump to search
Line 105: Line 105:
  
 
Switch to your output directory, e.g. by typing cd path, e.g. if you jar is located in "c:\temp" type "cd c
 
Switch to your output directory, e.g. by typing cd path, e.g. if you jar is located in "c:\temp" type "cd c
 +
 +
 +
 +
==Referensi==
 +
 +
 +
==Pranala Menarik==
 +
 +
* [[Pemrogramman Android]]

Revision as of 10:57, 3 September 2011

Tutorial ini menjelaskan penggunaan Eclipse sebagai IDE Java. Tutorial ini menjelaskan cara instalasi Eclipse, pembuatan program Java dan tip penggunaan Eclipse. Tutorial ini berbasis pada Eclipse 3.7 (Indigo)

Eclipse Secara Umum

Umumnya kita mengetahui Eclipse sebagai Integrated Development Environment (IDE) untuk Java. Eclipse dibuat oleh komunitas Open Source dan digunakan di beberapa hal, seperti, development environment untuk Java atau Android atau platform untuk aplikasi RCP Eclipse.

Penggunaan Eclipse sebagai Java Development Environment akan di terangkan di tutorial ini.


Memulai

Instalasi Eclipse

Instalasi Eclipse sangat mudah

apt-get install eclipse

Lumayan besar hampir 400Mbyte :) ...

Start Eclipse

Untuk menjalankan Eclipse ketik / double klik pada

eclipse

di shell. System akan menanyakan dimana lokasi workspace. Workspace adalah tempat dimana kita dapat menyimpan project Java. Pilih directory kosong dan tekan OK.

Eclipse akan jalan dan akan memperlihatkan Welcome page. Tutup welcome page dengan menekan "X" sebelah "Welcome".


UI Eclipse Secara Umum

Eclipse memberikan perspectie, view dan editor. View dan editor di group dalam perspective. Semua project akan tersimpan di workspace.

Workspace

Workspace adalah lokasi fisik (folder) tempat kita bekerja. Kita dapat memilih workspace saat menjalankan eclipse atau melalui menu (File-> Switch Workspace-> Others). Semua projects, file source, image dan berbagai file akan di simpan di workspace tersebut.

Kita dapat mendefinisikan workspace melalui startup parameter -data pathworkspace, misalnya, "/home/user/workspace" sehingga "eclipse -data "/home/user/workspace" Perhatikan bahwa kita harus menulis nama path dalam bracket. Untuk melihat directory workspace di judul Eclipse gunakan parameter -showLocation saat menjalankan eclipse.

Perspective

Sebuah perspective adalah sebuah visual container untuk sekumpulan view dan editor. Kita dapat mengubah layout dalam perspective (close / open view, editor, ubah size, change posisi, dll). Eclipse memungkinkan kita untuk switch ke perspective lain melalui menu Window->Open Perspective -> Other. Untuk Java development kita biasanya menggunakan "Java Perspective".

Tip

Masalah umum jika kita menutup sebuah view dan tidak tahu bagaimana cara membuka kembali view.
Kita dapat mereset sebuah perspective ke kondisi original melalui menu "Window" -> "Reset Perspective".

View dan Editor

View biasanya digunakan untuk melakukan navigasi dalam sebuah hirarki informasi atau membuka sebuah editor. Perubahan di view akan berpengaruh pada struktur data di bawahnya. Editor digunakan untuk memodifikasi elemen. Editor dapat melakukan compile code, undo, redo dll. Untuk melakukan perubahan di editor ke sumber daya di bawahnya, seperti, source file java, kita biasanya perlu men-save.


Membuat Program Java Pertama

The following will describe how to create a minimal Java program using Eclipse. It will be the classical "Hello World" program. Our program will write "Hello Eclipse!" to the console. 4.1. Create project

Select from the menu File -> New-> Java project. Maintain "de.vogella.eclipse.ide.first" as the project name. Select "Create separate source and output folders".

Press finish to create the project. A new project is created and displayed as a folder. Open the folder "de.vogella.eclipse.ide.first" 4.2. Create package

Create now a package. A good convention is to use the same name for the top package as the project. Create therefore the package "de.vogella.eclipse.ide.first".

Select the folder src, right mouse click on it and select New -> Package.

4.3. Create Java class

Right click on your package and select New -> Class

Create MyFirstClass, select the flag "public static void main (String[] args)"

Maintain the following code.


package de.vogella.eclipse.ide.first;

public class MyFirstClass {

public static void main(String[] args) { System.out.println("Hello Eclipse!"); }

}


4.4. Run your project in Eclipse

Now run your code. Right click on your Java class and select Run-as-> Java application

Finished! You should see the output in the console.

4.5. Run your Java program outside Eclipse (create jar file)

To run your Java program outside of Eclipse you need to export it as a jar file. Select your project, right click on it and select "Export".

Select JAR file, select next. Select your project and maintain the export destination and a name for the jar file. I named it "myprogram.jar".

Press finish. This will create a jar file in your select output directory. 4.6. Run your program outside Eclipse

Open a command shell, e.g. under Microsoft Windows select Start -> Run and type in cmd. This should open a consle.

Switch to your output directory, e.g. by typing cd path, e.g. if you jar is located in "c:\temp" type "cd c


Referensi

Pranala Menarik