Quick post – hibernate.cfg.xml with Hibernate 4.0.0

Hello, everyone! Yesterday I spent many hours trying to make Hibernate 4.0 (hibernate-core-4.0.0) work with a hibernate.cfg.xml file. I just could not obtain a Session Factory from a file similar to this one:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/noob</property>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- DB schema will be updated if needed -->
<property name="hbm2ddl.auto">create-drop</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>

</session-factory>
</hibernate-configuration>

Besides, I was trying to obtain a SessionFactory with a code like this:

public class HibernateUtil {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

private static SessionFactory configureSessionFactory() throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}

public static SessionFactory getSessionFactory() {
return configureSessionFactory();
}

}

And no, it was not working. So I made some changes:
Into my hibernate.cfg.properties, I did something like this:

<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
>

<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/noob</property>
<property name="hibernate.connection.username">root</property>

<property name="hibernate.connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="hibernate.connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider
</property>

<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>

</hibernate-configuration>

Notice the “hibernate.” in front of the properties. It was very very helpful, without it things did not work.

Also, for my SessionFactory, I did a code like this:

ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
SessionFactory factory = metadataSources.buildMetadata().buildSessionFactory();

And win!!! Things started working!

March 21, 2012 at 11:55 am 2 comments

EJB Lookup w/ JNDI on Jboss AS 7

Hello everyone!

I was kinda busy last months, so I did not have time to publish more posts here :/

Anyway, some weeks ago i have noticed a little (big) issue on JBoss AS 7 – I couldn’t make EJB lookup using JNDI!

I had to Google a lot to find a concrete answer.

So I’d like to share a way to do it.

First of all, you must have AS 7.1.x, even if it is not at the final version yet. You can download it here.

Then, create a file named jboss-ejb-client.properties into your src folder, and add this content

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.two.host=localhost
remote.connection.two.port = 4447
remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

Now the disgusting part. You’ll need to make a big workaround here.
Your class is going to have lots of information. And one BIG important thing – this first example only works for Stateful EJBs. I’ll show an example for Stateless EJBs later. So remember – STATEFUL EJBs:

public class ClientMyStatefulBean {

static {
Security.addProvider(new JBossSaslProvider());
}

//STATIC BLOCK - YOU MUST HAVE THIS

public static void main(String[] args) throws NamingException {

final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

final String appName = "";

final String moduleName = "myBeans";
// THIS IS THE NAME OF THE JAR WITH YOUR EJBs. Write its name here, without the .jar.

final String distinctName = "";
//    AS7 allows deployments to have an distinct name. If you don't use this feature, let this field empty.

final String beanName = MyBean.class.getSimpleName();
//EJB CLASS WITH THE IMPLEMENTATION (simple name)

final String viewClassName = Bean.class.getName();
// FULLY QUALIFIED NAME OF THE REMOTE CLASS (interface).

Bean bean = (Bean) context.lookup("ejb:" + appName + "/"
+ moduleName + "/" + distinctName + "/" + beanName + "!"
+ viewClassName + "?stateful");

}

}

Now for STATELESS BEANS, do this:

public class ClientMyStatelessBean {

static {
Security.addProvider(new JBossSaslProvider());
}

//STATIC BLOCK - YOU MUST HAVE THIS

public static void main(String[] args) throws NamingException {

final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

final String appName = "";

final String moduleName = "myBeans";
// THIS IS THE NAME OF THE JAR WITH YOUR EJBs. Write its name here, without the .jar.

final String distinctName = "";
//    AS7 allows deployments to have an distinct name. If you don't use this feature, let this field empty.

final String beanName = MyBean.class.getSimpleName();
//EJB CLASS WITH THE IMPLEMENTATION (simple name)

final String viewClassName = Bean.class.getName();
// FULLY QUALIFIED NAME OF THE REMOTE CLASS (interface).

Bean bean = (Bean) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName)

//NOTICE THAT DOING LOOKUP FOR STATELESS EJBs IS DIFFERENT FROM  STATEFUL EJBs!!!

}

}

It is not over yet!
Now you must add some jars to your classpath!
You’ll need these jars:

  • jboss-transaction-api_1.1_spec-1.0.0.Final.jar
  • jboss-ejb-api_3.1_spec-1.0.1.Final.jar
  • jboss-ejb-client-1.0.0.Beta10.jar
  • jboss-marshalling-1.3.0.GA.jar
  • xnio-api-3.0.0.CR5.jar
  • jboss-remoting-3.2.0.CR6.jar
  • jboss-logging-3.1.0.Beta3.jar
  • xnio-nio-3.0.0.CR5.jar
  • jboss-sasl-1.0.0.Beta9.jar
  • jboss-marshalling-river-1.3.0.GA.jar

You can find all these jars into your Jboss AS 7 folder inside “modules” folder.
Or, to make things more simple, I’ve created this project at github ->https://github.com/hannelita/jboss-as-libs-ejb-lookup

All necessary libs are there, just include them into your classpath and things should work 🙂

Need more references? You can find the here:

Docs -> https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Issue discussion -> https://issues.jboss.org/browse/AS7-1338

Project example -> https://github.com/jaikiran/quickstart/tree/master/ejb-remote

I’d like to thank a guy called Jaikiran Pai for publishing this information into JBoss Docs! 🙂

Well, just to finish the topic – I think its still an ugly way to do ejb lookup. For xample, that static block and all those strings are disgusting. Hope to have a better solution for further versions! 🙂

December 30, 2011 at 8:40 pm 3 comments

Instalando a gem do PostgreSQL no Rails 3

Recentemente, após instalar o dmg do PostgreSQL 9.1, fui usar a gem pg (gem do Postgres) e tomei uns erros estranhos:

checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/hannelitavante/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config


Gem files will remain installed in /Users/hannelitavante/.rvm/gems/ruby-1.9.2-p180/gems/pg-0.11.0 for inspection.

Bizarramente, no MacOSX 10.6+, ele dá uns paus muito loucos. para resolver, basta fazer isso:


export PATH=PATH_DO_SEU_POSTGRES/bin:$PATH
export ARCHFLAGS='-arch x86_64'
gem install pg

October 26, 2011 at 8:52 pm 1 comment

JBoss in Bossa 2011 – Sucesso total!

Olá!

Neste último sábado, 08 de outubro, ocorreu mais uma edição do Jboss In Bossa, dessa vez em Brasília. O evento foi sensacional e tive a honra de participar como palestrante!

Além do lugar ser muito bacana, o público estava extremamente interessado e com uma vontade imensa de obter novos conhecimentos das tecnologias da JBoss! Foi uma troca de experiência e networking muito bons!

O keynote foi realizado pelo @salaboy (Mauricio Salatino), famoso por manjar absurdamente de jbpm, Drools e recentemente ele está desenvolvendo uma projeto de Human tasks, o Smart Tasks. (slides aqui)

Em seguida, @jedgarsilva (Edgar Silva) apresentou uma divertida palestra sobre KVM e Cloud (com demos sobre Openshift). Ele já publicou o conteúdo, você pode acessa-lo aqui.

Logo após, o @rimolive (Ricardo Martinelli), o cara de CDI, fez sua apresentação falando sobre Seam 3 e o futuro de JEE 6 com o advento do CDI. Também, na trilha paralela na sala 105, @claudio4j (Claudio Miranda) e @brunorst (Bruno Rossetto) fizeram uma apresentaão sensacional com dicas para tunar seu JBoss AS.

Chegou a hora do almoço e aproveitei para visitar a #Caelum BSB graças ao @lacerdaph (Raphael Lacerda) que me levou até lá! 🙂

Voltando ao evento, apresentei minha palestra sobre Seam 3, contando um pouco da trajetória do Seam, dos adventos do Seam 3, falei do Seam Forge com uma pequena demo e expus algumas recentes decisões que foram tomadas a respeito do futuro do Seam 3. Espero que o pessoal tenha curtido 🙂 (slides aqui)

Infelizmente, conflitando horário com minha apresentação, o @porcelli falou sobre NoSQL! Não pude assistir à apresentação, mas os slides estão aqui! E só ouvi comentários extremamentes positivos a respeito 🙂

Logo após, @rafabene (Rafael Benevides) e @osmanlira (Osman Lira – sim, ele fez uma conta no Twitter após o evento!) falaram sobre Guvnor (os fontes estão aqui) e, na trilha paralela, @vtcorrea (Vitor Correa) e @g_luszczynski (Gustavo Luszczynski) arrebentaram em sua apresentação repleta de demos sobre jGroups e mod_cluster.

Depois, Pedro Igor falou sobre Infinispan e paralelamente, Rafael Soares falou sobre RHQ (infelizmente não pude assistir a essa palestra).

Na hora do coffee break, todos estavam repletos de idéias, dúvidas e rolou um networking muito bacana entre o pessoal que assistiu as palestras e os palestrantes! Além do mais, o coffee estava de primeira! Abundância e variedade de coisas deliciosas!

Em seguida, @jpviragine (João Paulo Viragine) falou sobre data federation com Teiid, e sua demo e precisão na hora das demos deixaram o público fascinado! Na outra sala, @rafaelliu falou sobre JBoss Portlet Bridge.

Fechando com chave de ouro, Flávia Rainone, core developer da JBoss, falou sobre o JBoss AS 7, grande sucesso entre os servidores de aplicação, especialmente devido a sua velocidade de strat de aproximadamente 2s.

Comunidade

Algo que curti muito no evento foi o espaço para palestras da comunidade! Isso foi bem bacana, houve palestras de pessoas da Red hat e de pessoas que contribuem para o mundo Open Source, mostrando a força e participação da comunidade! Show!

Para finalizar, parabenizo toda a organização do Jboss in Bossa e gostaria de agradecer todo o esforço que vocês tiveram para fazer um evento tão bacana quanto este! Parabéns! Espero estar com vocês na próxima edição! 🙂

October 10, 2011 at 8:28 pm 2 comments

Seam 3 – What’s going on

Hi all!

I’ve been blogging about Seam and specially Seam 3 since a few months ago. Recently, new [and big] changes were proposed and commented at IRC channels and at this post (by Shane).

Well, I really didn’t have time to absorb everything, but I’m writing this post to report some thoughts from Seam user’s community who have showed me their opinions.

Contextualizing

Seam 3 – The Good points

Seam 3 is pretty different from Seam 2. First, the idea of MODULE is pretty awesome, it allows flexibility, freedom for developing new ideas, Maven integration (yes, was pretty hard with Seam 2); also allows new contributors have more space for implementing their ideas and so on.

Seam 3 – the main problems

I’ve been saying this since I started using Seam 3 – it has several problems. There are few examples (and the existing ones are too simple – and part of that is my fault, I really should have published more posts and tutorials), there are no books about it. Another big problem – Seam is not that simple to use – you need a big skill set to start (JEE – CDI, JSF; Maven; controlling an app server and so on); it’s not like Rails (even if you don’t know Ruby or Active record pattern, or MVC, it IS possible to get something working with Rails, even if your code gets really bad). This not happens to Seam.

Another problem reported by community – what’s Seam goal? I mean, look at Hibernate – it has a main propose – ORM. And Seam 3? Is it CDI? People ask me “Ok, I like Seam 3 modules, but what’s the main goal? For example, I use Seam Social module, but is it really related to CDI?”

These problems have created an awkward situation for developers. Lots of ppl don’t feel comfortable to adopt Seam 3 for production; this scenery  prints an image of unstable or immature framework, which I can say that is completely FALSE. Seam 3 has lots of nice features and solves several problems in an easy way. Unfortunately, I think it’s pretty hard to use; so it scares new JEE users.

Seam 3 – the new proposals

In Shane’s words, due to Seam 3 focus problem – “instead of Seam trying to capture all of the CDI extensions in one place, like Pokemon, we should be trying to propagate them throughout the greater developer community instead.” – and them were presented some changes, like moving Seam persistence, REST and faces modules to other Jboss projects.

Well, community showed their concerns about it (sending me some emails and tweets). Next, a little summary about what ppl said: (ATTENTION – THIS IS NOT MY PERSONAL OPINION)
1. Why did the guys decided it? It was a big change from Seam 2 to 3, and community is not ready for a change like that yet.
2. Ppl don’t believe in compatibility. Some developers already have Seam 3 in production systems and they are really worried about it.
3. “WHY RICHFACES?? I USE PRIMEFACES! SEAM FACES SHOULD NOT BE WITH RICHFACES” (this guy was screaming)
4. “HIBERNATE??” – same guy above
5. “bad shot. The impression that I get is that you are tired of Seam, module leaders are disperse and you are giving up of the project, fitting it into other JBos products”
6. “Seam is gonna die. ok, I’ll start my new project with PlayFMK”
7. “Come on, Red hat should hire more ppl to work with Seam and to write more docs for it, instead killing the project” .
8. “F2F == RIP Seam”
9. Modules created in a not centralized environment, so this generates communication problems and it gets difficult for creating documentation and examples.
10. “WTF??” – Seam new users and ppl that are not directly involved with community contributors or IRC channels.

In my opinion, Seam 3 has some problems (that deserve their own post), but I see good and bad things with the new changes. First, I just think that this approach caused wrong impressions, leading ppl to think the project will die or everyone lost the interest for keeping the project.
I really don’t think Shane, Dan, Pmuir (Pete), Lightguard (Jason), Gastaldi or Lincoln would abort Seam, I mean, I see these guys at IRC channels and I see their passion for the project.
But be careful – how many Open Source projects have you seen that died suddenly? There are lots of dead projects, specially at Ruby Community. Death reasons – LOST their focus, got too complex, few documentation, absence of new features. Unfortunately, Seam 3 has some common problems.
Maybe these new proposed changes help to change this situation, focusing on CDI implementations and joining some correlated modules. But IMHO, it would also weaken Seam identity by merging some parts of it with other projects. I really don’t have a clear idea about the final effects – as I said, there are good and bad parts.

Summary

– Seam is not gonna die.
– Everyone who talked to me got a bad impression about these changes. It clearly wasn’t a good approach.
– These changes have good and bad points.
– Seam 3 need more focus and solid examples.

Seam 3 has an absurd potential and more, wonderful contributors building the framework. The only thing I’d like to ask – no panic. Community, keep using Seam 3! It IS nice and powerful. Contributors – that was not the best approach, but move on and keep showing your passion and tech skills by taking care of the framework.

I feel responsible too, I’ll try to do my best to help with examples and tutorials.

I’ll keep blogging about Seam 🙂

Feel free to contact me if you have doubts 🙂

 

UPDATE

Due to the all this misunderstood, feeling hurts, opposite opinions, doubts and so on, there’s a new post from Shane trying to explain the situation in a better way. As you can see, there’s a thread at Jboss Foum where you can show your opinion about it. Would be nice if you take a few minutes to read, understand the situation and write what you think.

Also, @antoine_sd blogged about it here – very nice post.

 

September 28, 2011 at 9:07 pm 5 comments

Seam Hack Night – September 8

Hi all!

On the next August 11 at 22:00 UTC * there will be another round of Seam Hack Night! This time for Seam Faces module!
Fork the code and join #seam-dev channel at irc.freenode.net !
This is a great opportunity to help a community project to improve its code! There’s a lot of work to do, so instead of just using the framework, why you don’t help to fix some bugs? Let’s go OSS spirit 🙂
If you don’t know much about Seam 3 project, a good way to start is to take a look here, and do some forks of the modules following these instructions.
If you are not familiar with git or have some questions about how to obtain the source code, or about Maven, you can leave a comment here or send me an email 🙂
So, don’t forget!

September 8, 22:00 UTC

#seam-dev  irc.freenode.net

Faces module – github page

*You can check your timezone here

September 7, 2011 at 6:34 pm 2 comments

The call4all app – Call 4 papers app – Seam 3 example

[Note – Before reading this tutorial, would be nice if you read this post before – It tells you that these Seam posts are under incremental builds and are modified everyday]

Henry is a Computer Science student and he is also an Open Source enthusiastic. He decided to share his knowledge by speaking into some conferences.

Henry checks the Confbuzz app to see the dates of the conferences, and he finds out that there are lots of conferences he would like to speak at. All of them have their our own Call4Papers/talk submission process.

“Crap! I have to copy-paste lots of information…. Bio, email, phone number, Twitter, Facebook… And wth, some of these sites are horrible…. All these technical conferences should have a unified submission process…. would save me lots of time and would ensure that the talk submission process is friendly…. Wait a minute…”

So probably you and Henry got a perfect idea. Create a Call4Papers website example.

But Henry decided he would like to do more. “I’ll talk about it into a conference!”.

Henry started studying Seam 3 few weeks ago and he thinks he’s able to create de Call4All app using it. He starts to fill the form:

So let’s help Henry to create his app. He is a Maven lover, so he prefers to create the app without using Seam Forge. *(check this post for more information about creating a Seam 3 project, with or without Seam Forge)

Creating the project

Henry opens his Eclipse Indigo and install JBoss Tools *. Also he decided to use JBoss AS 7 as it is his favorite Application Server (in fact Henry is in love with that, he still cannot believe AS7 starts in less than 3 seconds). He creates a new Maven project, fills artifactId, groupId, version and package info about the project. Then, he just adds Seam dependencies, getting a pom.xml like this.

So let’s take an overview about these Maven dependencies: [Note: If you are a Maven beginner, you might skip this session and just truste me that this pom.xml really works. Otherwise, if you are ok with maven, take a look at this brief explanation]

< properties >  stuff helps us to control some dependencies version.

< dependencyManagement >  is used to import Seam and RichFaces dependencies.

Then, we add Seam modules (the ones whose groupId is org.jboss.seam ), joda time, prettyfaces (required dependencies for some modules) , richfaces, and adjust some other dependencies (like hibernate validator, we must exclude it from seam-validation and add another version for that, otherwise we will have some trouble with AS 7.

Then Henry runs a mvn clean install – and TA-DA! BUILD SUCCESSFUL!

Maybe you have some questions like “WTH is…. Arquillian?” Take a look here. [I’m also writing a short tutorial about it].

*current version for Indigo – 3.3.0 M2

So what’s next? Henry thinks about the Call4All app… “When i access this webpage, I want to login, auto-fill my personal data and just type the talk title and a brief description. I will forget about page layout for while, and just live h:”.

Good way to start. “But also” – thinks Henry – “I want that conferences may be able to register and access the call4all app via Rest… and then get the proposals, reports and statistics about submission themes, speakers profiles… And oh, would be nice integrate it to Twitter, so as soon as you submit a proposal you can tweet about it…. Or share into facebook… Or even more crazy, go to a voting page for community choose the best keynothes that will be presented….” And then Henry starts to have crazy ideas.

Now let’s see how to implement them using Seam 3 modules. In the next posts Henry will show:

  • Faces module – the base
  • Seam Security and the login page
  • The Brazilian speaker and the international module

August 6, 2011 at 3:23 pm Leave a comment

Seam 3 – creating a new project – with and without Seam Forge

Hi all!

[Note – Before reading this tutorial, would be nice if you read this post before – It tells you that these Seam posts are under incremental builds and are modified everyday]

This is the first post about Seam 3 examples!

The main point here is not to show a simple ‘Hello World’ app, but a more complex example, showing resources from 2 or more more modules.

So, let me tell you a short story…

Ben is a computer science student and he’s having some java classes. The subject now is web apps using Java.

– So – the teacher starts to talk – creating a java web app is pretty simple. As you can see, the only thing you have to do is open Eclipse, select ‘Dynamic web module’….. – and then he starts to say lots of things that should be done BEFORE start writing code.

[After 15 min talking, the teacher still explaining how to create a project] – And this is web.xml. And this one is faces-config.xml, and this is context.xml. Using Jboss AS 5 has some more extra confs, and with JEE 5, you just have to…

Ben thinks “OMG, NO WAY, THIS IS NOT SIMPLE!!!! HOW CAN YOU LIVE WITH THAT??”

And Ben is right, developing apps in that way is pretty boring, painful, and creates a false idea that “Java is a DSL for taking large XML files and converting them to stack traces“.

“I will never use this thing called ‘Java’ to develop my web apps. Ruby on Rails is much more simple and fast”, Ben says leaving the classroom after the class.

“The problem is that the teacher did not mention anything about JEE 6” – replied his classmate Susan.

– JEE 6? What does it do, take large JSON files and convert then to stack traces? haha.

– No, JEE gives you the power of CDI! – says Susan.

– I’ll just consider using it if you tell me that I can build Java web apps in a way as simple as Rails. Otherwise…

– Yes, YOU CAN DO IT! Let me introduce you to Seam Forge!

Ben still thinks that Susan is mocking him, but then she takes her MacBook and starts a little and fast class about Seam Forge.

– Let me introduce you to Seam Forge. Believe me, the only sad part of Java story is Maven downloading the internet for you if your .m2/repository is empty. There’s any other boring thing.

*****************************************

Seam Forge – Fast tutorial

“Ok”, you might be thinking after reading this story. “Show me what do I need to have Seam Forge up and running here on my computer.

Obviously you need JDK (6+). You can download Seam Forge here – go to the “artifact information” and download the zip file. After that, unzip it, and add $FORGE_HOME/bin to your path.

If you are into a UNIX based system (Linux or Mac), basically just add this to your .bash_profile or .basrc:

export FORGE_HOME=/{YOUR_LOCATION}/forge-1.0.0-SNAPSHOT
export FORGE=$FORGE_HOME/bin
export PATH=$PATH:$FORGE

change {YOUR_LOCATION} to the right path of seam-forge directory.

So now type forge into your terminal. You might see Seam Forge up and running, like this:

Explore some commands by typing list-commands -all. Remember that TAB key works pretty fine here 🙂

So now what about some ‘rails style’ development? Let’s do some scaffolding.

Be sure to have JBoss AS 6 or JBoss AS 7 downloaded. You should also have Maven and Git installed.

  1. Let’s create new sample project. Type new-project –named damnPonies –topLevelPackage com.ponies.damn –projectFolder /{YOUR_PATH_HERE/  
  2. Now let’s do scaffold setup. type scaffold setup. Forge will ask you some questions, answer yes.
  3. Choose the last version of Metawidget, and also choose the latest version of Seam persistence. Done!
  4. Now create an index – scaffold indexes –overwrite
  5. Setup your persistence – type  – You can change provider and container – Just use TAB to see other options 🙂
  6. Now let’s create an entity. Type entity –named Pony. Check that Forge creates an Entity called Pony for you (Very similar to Rails =] )
  7. Let’s add some fields – type field string –named color
  8. Type ls and examine the class Pony.java 
  9. Type scaffold from-entity to generate a scaffold for Pony entity.
  10. Then, type build to make maven build the project for you. 
  11. Done! Take a look at the project structure 

If you ever used Seam 2, maybe Forge reminds you a seam-gen enhanced version.

[Break time – You might be wondering why did I call this project ‘DamnPonies. Its related to a Brazilian tv commercial which has an annoying song that involves ‘Damn Ponies’. You can check it  here  – CAUTION – Really annoying song]

More information about Seam Forge:

http://seamframework.org/Seam3/Tooling

https://docs.jboss.org/author/display/SEAMFORGE/Home

*****************************************

Now let’s go back to our story. While Ben is learning about Seam Forge, his classmate Henry is at the library doing some research work. Henry is a Java enthusiastic boy, who really likes Maven world. He gets mad when people make fun of Maven saying it downloads the whole internet. Last week he read a tweet from Susan saying “Maaaaavvveeennn IIIII hhhaaaattteee yyyooouuuuu!”, and then he tweeted back – “go back to Ant then!”. Susan provoked back – “You keep saying you love Maven, but I never see you configure a new project from the beginning. You always use a tool or a stable Maven Archetype. Loser”.

Henry got really disappointed by hearing this from a girl, so he decided to turn the tide. He wants to prove her that HE CAN CREATE A SEAM 3 PROJECT WITHOUT SEAM FORGE. “I’ll curse her with Maven. She’ll see that I am the Maven guy.”

So let’s help Henry on his adventure to create a Seam 3 project without using Seam Forge.

[TODO – write about seam 3 architecture + module brief]

I will assume that you already know about Seam 3 modular architecture. If not, take a look here. Also, you will need Maven 3 and JDK 6+.

So, first step – start with weld archetype – Open your Terminal and type

mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central

[TODO – write a better tutorial for this]

August 6, 2011 at 3:19 pm 14 comments

Seam 3 tutorials and examples – up and running

Hi all!

I know that you have been looking for Seam 3 tutorials, examples, and it’s a little hard to find it yet. But Seam 3 team is working hard and soon there will be lots of thing for the community. I will help them with some tutorials and exmaples.

I am going to publish lots of posts and update them [almost] everyday. So, if Google shows you a page of this blog one day, probably in the next 2 or 3 days there will be new content at the same page. Be sure to remember that, otherwise you will think “OMG, its missing lots of things in this post. It’s a crap”. It’s Aug 06 today – I really expect to finish solid information and very cool tutorials until the end of the month.

I also would like to thank all of you who send me feedbacks about this blog – it’s very important to me to always try to write better and useful things. So, if you get a free time, write a little review and send it to hannelita @ gmail, or just leave a comment here 🙂 Believe me, it’s very important to me.

Also, I’d like to ask you to be patient. I know all of you want information, tutorials, easy-to-read and lots of other things. But be aware this is community work – I also have to do lots of other things. I’m really glad to help and share knowledge, but sometimes its really hard to create content in one night. I sleep (sometimes). 🙂 Not only me, but Red Hat guys and all of the other Seam contributors have tons of things to do! Think about that before saying bad things. But we really welcome to suggestions, questions, and specially new contributors! Remember – you can access the forum anytime and post your questions, or join us at IRC – irc.freenode.net – #seam and #seam-dev channel. There’s [almost] always someone online there that might help you!

Feel free to email me anytime – hannelita @ gmail, or send me a Tweet @hannelita. Thanks for reading!

August 6, 2011 at 2:42 pm 1 comment

Seam Hack Night – August 11!

Hi all!

On the next August 11 at 22:00 UTC * there will be another round of Seam Hack Night! This time for Seam Security module!
Fork the code and join #seam-dev channel at irc.freenode.net !
This is a great opportunity to help a community project to improve its code! There’s a lot of work to do, so instead of just using the framework, why you don’t help to fix some bugs? Let’s go OSS spirit 🙂
If you don’t know much about Seam 3 project, a good way to start is to take a look here, and do some forks of the modules following these instructions.
If you are not familiar with git or have some questions about how to obtain the source code, or about Maven, you can leave a comment here or send me an email 🙂
So, don’t forget!

August 11

#seam-dev  irc.freenode.net

Security module – github page

*You can check your timezone here

July 28, 2011 at 3:57 am Leave a comment

Older Posts


Categories

  • Blogroll

  • Feeds