Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Sunday, 16 August 2009

Stigla majica sa Eclipse Galileo Blogathon-a

I ove godine sam se odazvao pozivu Eclipse fondacije da se napiše blog povodom izlaska nove verzije Eclipse-a pod nazivom "Galileo".

Link na post.

I ove godine sam,naravno, na moju veliku radost dobio od fondacije majicu sa logom Eclipse-a.
Šta reći o majici? Zaista je super!

Evo sličica:


Wednesday, 29 July 2009

Eclipse Galileo and Struts2

I was quite surprised with how many people came to my blog and read my earlier post on how to create a blank Struts2 project and start using this framework in NetBeans 6.5

With a release of new Eclipse, I thought it would be interesting to do the same thing, but now in this IDE.
As you probably already know, Eclipse is one of the famous and certainly one of the best Java IDEs.
Well, about a month ago people from Eclipse foundation released a 3.5 version of Eclipse, called Galileo.

I develop almost all my project using NetBeans, and have never done any Struts2 programming using Eclipse.
That is why I decided to write a post on how to create a Struts2 example in new Eclipse release: Galileo. That's quite fun because that way I (we) get to learn on how to use Struts2 in Eclipse, and get to see Galileo in action a little bit closer…

Note: In this post, I’ll use much of the text , entire source code and application logic from my previous post and concetrate only on the differences between these two IDEs.


So, let’s get started:

First of all we need Eclipse Galileo. Go to the http://www.eclipse.org/downloads/ and download Eclipse IDE for Java EE Developers.

Next thing we need is Struts2 itself. Go to http://struts.apache.org/2.x/index.html and download the latest version of Struts2.
I downloaded struts-2.1.6-all.zip
You won't be needing all the libraries in it. Just 6 of them. Because of this, you can download essential dependencies only.

When you download one of these archives, extract it to some location, for example: c:\Struts2

It is now time to start a new project. Start Eclipse Galileo.


Click file --> new --> Dynamic web project



Let’s call this project GalileoStruts2Example
I’ll use Tomcat 6 . You can use some other server that you have available , it is completely up to you.






Click Finish.

Your project tree will look like this:







Now, in order to use Struts2 libraries, let's add those essential dependencies to project:

Right-click on the project --> properties --> Java Build Path , select Libraries tab and click on the “Add External JARs” button.

Go to folder where you extracted Struts2 libraries and select ( add to project ) following files:

- struts2-core-2.1.6.jar
- freemarker-2.3.13.jar
- ognl-2.6.11.jar
- commons-fileupload-1.2.1.jar
- commons-logging-1.0.4.jar
- xwork-2.1.2.jar


Most of the tutorials on the web are written for older version of struts2, at the time when commons-fileupload-1.2.1.jar was not mandatory, so even when following all the steps in tutorial , you just couldn't get your project to work ( with newer version of Struts2 ) !

Now, your project will look like this:



Now, copy these six JARs into the “lib” folder located in the root of WEB-INF folder.






These files will be uploaded to App Server , and a deployed application will use it.
We could put this files into main lib folder of application server, but it is most probably better this way...

We need to create one more folder in the root of the WEB-INF , and name it "classes".
This is where you will create struts.xml, and if needed - a struts.properties file.

I'll put all my JSP's into new folder, "jsp" , which I will create in the root of "WebContent" folder.

All Java code that we write, we will place into some package in the "Java Resources: src" folder.
I'll create one now, called "struts2Example" and a "Hello" Class in it.
If you use validaton, put all Validation XMLs inside class's package too...






This is how, at minimum, your Struts2 project structure should look like.


I'll create one small Struts2 application now. Nothing complicated.
User will enter his name, and press "submit" and other page will open , saying Hello to this user.

So, let's first create a Java class extending ActionSupport class , named Hello, inside Struts2Example package.
Let's make it to look something like this:

package struts2Example;
import com.opensymphony.xwork2.ActionSupport;


public class Hello extends ActionSupport
{
private String name, message;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return "Hello " + getName();
}
public void setMessage(String message) {
this.message = message;
}
}

We now need two JSPs, for example "nameinput.jsp" and a "response.jsp"
Each JSP needs to contain this line, in order to use struts2 custom tags in it:

<%@ taglib prefix="s" uri="/struts-tags" %>

nameinput.jsp:


response.jsp:



Let's create an XML validation file for Hello class, and make a name property mandatory.

Hello-validation.xml:

<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter name</message>
</field-validator>
</field>
</validators>


Let’s see how our project tree looks at this stage:



There's only 2 things left for us to do:

Edit struts.xml, and web.xml:

struts.xml must be located in “classes” folder located in the root of WEB-INF folder:






This is where place a file struts.properties if we need to use it, as well…

web.xml:






And if we press “Run” button, and choose a server on which it is supposed to run




we’ll get something looking like this:




But don't worry. Everything is OK, we just didin't handle default page...
If we append entername.action on the URL , our new application will open:


If we do not enter name and press “submit”:



but if we do enter name and press “Submit”:



So, I hope I helped you to understand how to create an empty struts2 project in Eclipse Galileo.

At the end, our project looked like this:





A small conclusion of mine: great thing about Eclipse is that you can do just about everything with it , with just a little few extra settings and installations...
Unfortunately, for me - many things and options remained a little bit more complicated and unintuitive regarding to some other IDEs. That is such a shame!
Nevertheless , for me , Eclipse continues to be one of the best choices!.

Enjoy Struts2 and Galileo!


Friday, 29 August 2008

Ganymede around the world contest shirt received!





This summer ended great!
When I returned yesterday from Greece, where I was on summer vacation , I found a package on my desk.




I received  my Ganymede around the world contest shirt!
I thought it’s going to be the white one, but this one is much better!
It’s great!
Here are some pictures:


 

 



Monday, 21 July 2008

Izašao je Eclipse 3.4 - Ganymede

25.Juna 2008 najveći Jupiterov satelit zatresao je planetu Zemlju.
Rečenica kao iz knjiga nau
čne fantastike zapravo znači nešto sasvim drugačije.
Nova verzija Eclipse-a, nazvana po najvećem Jupiterovom satelitu ugledala je svijetlost dana Juna ove godine.

Ganymede nam dolazi kao skup od 23, dok neki od tvoraca u svojim blogovima pišu 24, zasebna projekta. Koga interesuje da sazna više o kojim se projektima radi, može pogledati na sajtu http://www.eclipse.org/ganymede/learn.php
Šta reći o Ganymede-u i Eclipe-u inače? Lično, veliki sam fan Eclipse-a i radujem se svakom izlasku nove verzije.
U njemu mi je jako lijepo za raditi. Brz je, ima dosta lijepih opcija koje ubrzavaju rad , lako se nalaze i instaliraju plug-in-ovi, i nekako, čini mi se da programeri koji prave eclipse vrlo lijepo prenose svoja isustva koje opcije bi trebale postojati u nekom IDE-u i na kojem bi se mjestu trebale nalaziti.
Smatram ga SKORO savršenim IDE-om, ali skoro!
U pitanju su par stvari koje su učinile da ga u razvoju koristim samo kada pravim java binove za Oracle Forms Builder jer jako lako mogu podesiti compiler complience level na 1.4 verziju jave ( više o kreiranju java binova za oracle forms builder koristeći Eclipse ovdje). S druge strane, sa nestrpljenjem sam čekao da ove stvari budu popravljene pa da Eclipse takođe mogu uzeti u obzir pri razvoju velikih projekata. Ostaje da vidimo da li je put do toga cilja dug i trnovit ili je sa ganymedeom već riješen…

Nego, da krenemo od početka
... Da vidimo koji projekti čine ganymede:

Dakle, radi se o veoma lijepom spisku stvari koje trebaju programerima. Projekti su , očigledno pažljivo odabrani, ali ne bi marilo da se spisak proširio za još nekoliko korisnih stvari potrebnih pri radu...
A ako pričamo o onim sitnim stvarima, detaljima koji nam čine da nam neki IDE bude omiljeni, Ganymed ih je pun. Počevši sa brzinom samog IDE-a, lakim podešavanjem compiler compliance level-a, sa jednostavnim wizardom za kreiranje .jar fajlova, sa funkcijama koje su na , po meni , dobrim mjestima, kao npr. stavke padajućeg menija za generisanje koda ili dugme za kreiranje nove klase,paketa ili slično, odličan debuger , velika radna površina u odnosu na npr. neke druge IDE-e , jednostavni update bilo koje komponenete IDE-a, plug-in-ovi za skoro sve, izuzetno je prilagodljiv željama korisnika…
Posebno bih pohvalio novi sistem update-a koji će sam za vas odabrati i downloadovati sve dependencies-e, i novi način pregleda stabla klasa nazvan Breadcrumbs .

Međutim, sta je sa onim
“Ali…”
Šta je to zbog čega je ovaj IDE SKORO savršen, a ne savršen ( po meni )? Zašto i pored toga što obožavam pisati kod u eclipse-u ( u njemu mi čak ljepše i vizuelno izgleda nego u drugim IDE-ima) njega ne koristim pri pisanju većih projekata, već samo pojedinih modula istih...?
Koje su to stvari koje bi trebalo popraviti, dopuniti i dodati ?
Prva stvar je ne postojanje aplikativnog servera koji dolazi zajedno sa IDE-om ( u instalaciji ), i koji se bez dodatnih podešavanja i instalacija lako pokreće klikom na dugme u razvojnom okruženju. Naravno, sve se može dodatno instalirati i podesiti, ali ne vidim razlog zašto bi neki programer gubio vrijeme na to, ako postoji drugo, takođe sjajno, razvojno okruženje sa kojim dolazi odličan aplikativni server „in the box”, sa sjajnim alatima za editovanje konfiguracionih XML-ova istog servera.
Druga stvar, koliko god se činila malom i beznačajnom, takođe ima veliku ulogu na mene a to je sam način kreiranja .jar fajla. Ako radimo na nekom projektu koji u sebi sadrži neke eksterne jarove, i od tog projekta exportujemo .jar fajl, Eclipse neće uz njega exportovati i potrebne eksterne jarove , niti će u manifest fajl kreiranog .jar-a dopisati relativnu ili apsolutnu putanju ka eksternim jarovima, već sve ovo moramo ručno raditi. Kažem, mala stvar , ali kada imate posla preko glave, onda očekujete da bar male stvari IDE sam odradi. U ganymede-u je ovo dopunjeno, ali u tom smislu da u jedan .jar fajl integriše sve dodatne .jar fajlove koje vaš projekat koristi.
Po meni, ova stvar je najbolje riješena u NetBeans-u, koji će eksportovati vaš .jar , a u root-u tog foldera kreirati i folder “lib” u koji će smjestiti sve dodatne .jar fajlove importovane u projekat, a manifest fajl će dopuniti putanjom do njih...
Оnо što bih u narednom periodu u ganymed-u volio vidjeti je alat s kojim možemo raditi sa bazom podataka. Pregledati njene objekte, pisati stored procedure i slično... Dakle, nešto što podsjeća na Toad, jer ipak se vrlo često radi sa bazama podataka, i ovakav alat unutar eclipse-a bi zaista bio pravi pogodak!
Ganymede je tek izašao. Sada predstoji malo duži rad u njemu i tek tada možemo dati prave impresije, ali u svakom slučaju hvala Eclipse fondaciji na lijepom iznenađenju...
Do sljedećeg javljanja... Zivjeli!