
Oleh : Reza Ervani
بسم الله الرحمن الرحيم
Keberadaan Maven akan sangat mempermudah kita membangun berbagai aplikasi java di Eclipse. Karena itu kita akan melihat bagaimana cara mengintentegrasikan Eclipse dengan Maven, terutama untuk membuat proyek Spring.
Secara default Eclipse JEE sudah menyertakan maven, hanya saja kita perlu melengkapi archetype yang ada sehingga bisa digunakan untuk membuat proyek Spring.
Untuk membuat sebuah proyek Maven kita dapat memilih menu File –> New –> Maven Project seperti tampak pada gambar :
Maka kita akan mendapatkan tampilan seperti berikut :
Klik Next. Maka kita kita akan melihat tampilan seperti tampak pada gambar berikut :
Karena archetype spring mvc belum disertakan, maka kita akan menambahkannnya terlebih dahulu. Klik tombol Add Archetype
Akan muncul tampilan seperti berikut untuk kita lengkapi :
Repository Maven untuk Spring MVC dapat ditemukan di : http://maven-repository.com/artifact/co.ntier/spring-mvc-archetype
Isi selengkapnya kolom diatas seperti berikut :
- Group ID: co.ntier
- Version: 1.0.2
- Artifact ID: spring-mvc-archetype
- Repository: repo.maven.apache.org/maven2/
Jika berhasil kita tambahkan maka kita akan dapatkan artifact spring-mvc-archetype ada di daftar seperti tampak pada gambar berikut :
Pilih Next, maka di jendela berikutnya kita diminta untuk memberikan informasi tentang proyek pertama kita tersebut seperti tampak pada gambar berikut :
Klik Finish, maka kita akan memperoleh halaman Eclipse kita menampilkan seperti tampak pada gambar berikut :
Kode pom.xml tampak seperti berikut :
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 | <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >com.eclipseprogramming</ groupId > < artifactId >LatihanSpringmaven</ artifactId > < version >0.0.1-SNAPSHOT</ version > < packaging >war</ packaging > < name >LatihanSpringmaven</ name > < properties > < java.version >1.6</ java.version > < spring.version >3.1.0.RELEASE</ spring.version > < cglib.version >2.2.2</ cglib.version > </ properties > < dependencies > <!-- Spring core & mvc --> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-context</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-webmvc</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-orm</ artifactId > < version >${spring.version}</ version > < type >jar</ type > < scope >compile</ scope > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-test</ artifactId > < version >${spring.version}</ version > < type >jar</ type > < scope >test</ scope > </ dependency > <!-- CGLib for @Configuration --> < dependency > < groupId >cglib</ groupId > < artifactId >cglib-nodep</ artifactId > < version >${cglib.version}</ version > < scope >runtime</ scope > </ dependency > <!-- Servlet Spec --> < dependency > < groupId >javax.servlet</ groupId > < artifactId >servlet-api</ artifactId > < version >2.4</ version > < scope >provided</ scope > </ dependency > < dependency > < groupId >javax.servlet.jsp</ groupId > < artifactId >jsp-api</ artifactId > < version >2.1</ version > < scope >provided</ scope > </ dependency > < dependency > < groupId >org.codehaus.plexus</ groupId > < artifactId >plexus-io</ artifactId > < version >1.0.1</ version > </ dependency > </ dependencies > < repositories > < repository > < id >springsource-milestones</ id > < name >SpringSource Milestones Proxy</ name > </ repository > </ repositories > < build > < finalName >LatihanSpringmaven</ finalName > < plugins > < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-compiler-plugin</ artifactId > < version >2.0.2</ version > < configuration > < source >${java.version}</ source > < target >${java.version}</ target > </ configuration > </ plugin > < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-resources-plugin</ artifactId > < version >2.6</ version > </ plugin > </ plugins > </ build > </ project > |
Selanjutnya kita jalankan program ini di tomcat maka kita akan mendapatkan hasil tampilan seperti berikut :
Selamat mencoba (reza@rumahilmu.or.id)
Leave a Reply