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

August 6, 2011 at 3:19 pm 14 comments

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]

About these ads

Entry filed under: Uncategorized. Tags: .

Seam 3 tutorials and examples – up and running The call4all app – Call 4 papers app – Seam 3 example

14 Comments Add your own

  • [...] 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) [...]

    Reply
  • 2. Gabriel Rodrigues  |  October 22, 2011 at 10:46 am

    The Forge didn’t ask me for the metawidget or jpa version.

    Reply
    • 3. hannelita  |  October 23, 2011 at 12:01 am

      Hey! When you type “scaffold setup”, after creating your project, forge will ask you this: “No scaffold type was selected, use default (Metawidget & JSF)? [Y/n]“. You should type “Y”. This did not appear to you?

      Reply
      • 4. Gabriel Siqueira Rodrigues  |  October 24, 2011 at 1:44 pm

        Yes. It appeared. But it didn’t show up in step 3: “Choose the last version of Metawidget, and also choose the latest version of Seam persistence. Done!”

  • 5. Gabriel Rodrigues  |  October 22, 2011 at 10:46 am

    Parabéns!
    Porque não tem como criar um projeto Seam com Forge no tutorial oficial do Seam?

    Reply
    • 6. hannelita  |  October 22, 2011 at 11:59 pm

      Olá! O site oficial está um pouco carente de tutoriais :) O próprio pessoal do Seam admitiu isso.
      Entretanto, se vc quiser a documentacao oficial, existe um link na área do Seam 3 para o forge sim! Aqui está! De uma olhada, tem bastante coisa aí :)

      Reply
  • 7. Gabriel Rodrigues  |  October 22, 2011 at 10:49 am

    I have been getting many “The encoding ‘UTF-8′ is not supported by the Java runtime.” Do you know why?

    Reply
    • 8. hannelita  |  October 23, 2011 at 12:04 am

      Do you mean this? “Warning: The encoding ‘UTF-8′ is not supported by the Java runtime.” This is just a warning, probably because your environment contains some UTF-8 stuff. This will not affect the project or development.

      Reply
  • 10. alepuzio  |  January 3, 2012 at 11:40 am

    Thank you for this article. This is very useful for starting with Seam!

    Reply
  • 11. alepuzio  |  January 4, 2012 at 1:49 pm

    Hi,I forgot :)
    I followed this tutorial: it’s alla well, but I have some errors of compilation because some class is’nt importable (for example: javax.enterprise.context.ConversationScope, javax.enterprise.inject.Disposes and other).

    Is it normal or I have to import some jar? In this case, what are the jars?

    Reply
  • Helpful info. Lucky me I discovered your site accidentally, and I am surprised why this accident did not happened in advance! I bookmarked it.

    Reply
  • 13. Claudia K.  |  September 25, 2012 at 8:02 am

    As I observed, the forge new-project command not work properly (Forge 1.0.5, 1.1.0)
    The command regularly return a dialog window with a following content:
    “Invalid project description. OK c:\ws\foo”

    Anybody has a same issue?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

August 2011
M T W T F S S
« Jul   Sep »
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: