Tagged: maven Toggle Comment Threads | Keyboard Shortcuts

  • hardikmehta 12:15 pm on April 30, 2010 Permalink | Reply
    Tags: , , maven, , ,   

    Mavenising seam projects [ part 2 ]. 

    This part will continue the discussion started in part 1 [1].

    We now come to the model and action modules which are of type ejb. Particularly in this example (Open18) they are just seam components i.e. pojos  annotated with @Name, but they could also have been ejbs.

    Bellow is the pom.xml for model module. It contains all the entities (JPA)  and some helper classes. It shows jboss-seam as provided dependency which will be provided by the ear module which packages the artifact which will be deployed. This modules takes all the hibernate dependencies from the parent project.

    <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/maven-v4_0_0.xsd">
      <parent>
        <groupId>com.hardik.seaminaction</groupId>
        <artifactId>Open18</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hardik.seaminaction</groupId>
      <artifactId>model</artifactId>
      <packaging>ejb</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>model</name>
      <url>http://maven.apache.org</url>
      <dependencies>
          <dependency>
                <groupId>org.jboss.seam</groupId>
                <artifactId>jboss-seam</artifactId>
                <version>2.2.0.GA</version>
                <type>ejb</type>
                <scope>provided</scope>
            </dependency>
      </dependencies>
      <build>
      	<plugins>
      		<plugin>
      			<groupId>org.apache.maven.plugins</groupId>
      			<artifactId>maven-ejb-plugin</artifactId>
      			<configuration>
      				<ejbVersion>3.0</ejbVersion>
      			</configuration>
      		</plugin>
      	</plugins>
      </build>
    </project>
    

    Here the action module which is also of type ejb. It contains all the action classes which are in turn pojos annotated with @Name. The JSF dependency which we see is for the JSF message classes.

    <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/maven-v4_0_0.xsd">
      <parent>
        <groupId>com.hardik.seaminaction</groupId>
        <artifactId>Open18</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hardik.seaminaction</groupId>
      <artifactId>action</artifactId>
      <packaging>ejb</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>action</name>
      <url>http://maven.apache.org</url>
      <dependencies>
          <dependency>
              <groupId>com.hardik.seaminaction</groupId>
              <artifactId>model</artifactId>
              <version>1.0-SNAPSHOT</version>
          </dependency>
    
          <dependency>
                <groupId>org.jboss.seam</groupId>
                <artifactId>jboss-seam</artifactId>
                <version>2.2.0.GA</version>
                <type>ejb</type>
                <scope>provided</scope>
            </dependency>
          <dependency>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>1.2_02</version>
                <scope>provided</scope>
            </dependency>
    
      </dependencies>
      <build>
      	<plugins>
      		<plugin>
      			<groupId>org.apache.maven.plugins</groupId>
      			<artifactId>maven-ejb-plugin</artifactId>
      			<configuration>
      				<ejbVersion>3.0</ejbVersion>
      			</configuration>
      		</plugin>
      	</plugins>
      </build>
    </project>
    

    Links:

    1. Mavenising seam projects [ part 1 ].
    Advertisements
     
  • hardikmehta 3:51 pm on March 7, 2010 Permalink | Reply
    Tags: cdi, , , , jsr 299, jsr299, maven, , ,   

    Mavenising seam projects [ part 1 ]. 

    Seam [1] is a  very powerful framework for developing java EE web-based applications. It is the only java framework which glues all the tiers of a typical java EE web application together. It is no surprise that many seam features like using EJB 3.0  (for seam any pojo which is a seam component) directly as JSF backing beans, declarative scoping and conversation scope  has been included in the new Contexts and Dependency Injection for Java EE 6 (CDI) also known as JSR 299 [2].  JSR 299 combines best features of seam, Google Guice [3] and Spring [4]. Seam also has tons of other features which make it a very useful framework to learn for any Java developer. Seam by default uses ant. The seam-gen tool creates an ant project and itself is a wrapper to different ant targets.

    Maven on the other hand is emerging as the de-facto building tool for java. As I have already mentioned before, maven gives you a very good overview of your project and you are not lost in minor details. Those details are automatically taken care of. With seam projects, maven is especially useful because you know which dependencies are needed.

    When I started learning seam, by reading the very popular book Seam in Action by Dan Allan [5], I had already switched to maven for all my projects. I decided to mavenise the examples of the book. There are many such projects. The seam documentation also points to the seam-maven-refimpl project [6] which provides a nice template for any seam project. As I wanted to find out how the maven implementation a seam project differs from that of a standard java EE project first hand, I didn’t use the template provided by this project. I just started with a standard java EE project and started adding seam dependencies to it, until I had a working example.

    The implementation  can be found here. Please feel free to point out any mistakes or suggest improvements to th code.

    I have also tried to convert the first examples of the book Seam 2.x Web Development by David Salter [7]. These examples are very simple i.e. without persistence, richfaces etc, although they use state less session beans.

    Here I will discuss the Open18 example from the Seam In Action book in detail.

    Here is the pom file of the main parent project which is no different from an ordinary Java EE project. The only seam specific thing is the jboss repository entry at the end.

    <?xml version="1.0" encoding="UTF-8"?>
    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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hardik.seaminaction</groupId>
      <artifactId>Open18</artifactId>
      <packaging>pom</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>Open18</name>
      <url>http://maven.apache.org</url>
      <modules>
      	<module>action</module>
      	<module>model</module>
        <module>war</module>
        <module>ear</module>
      </modules>
      <build>
      	<plugins>
      		<plugin>
      			<groupId>org.apache.maven.plugins</groupId>
      			<artifactId>maven-compiler-plugin</artifactId>
      			<configuration>
      				<source>1.6</source>
      				<target>1.6</target>
      			</configuration>
      		</plugin>
      	</plugins>
      </build>
      <dependencyManagement>
      	<dependencies>
      		<dependency>
      			<groupId>com.hardik.seaminaction</groupId>
      			<artifactId>ear</artifactId>
      			<version>1.0-SNAPSHOT</version>
      		</dependency>
      		<dependency>
      			<groupId>com.hardik.seaminaction</groupId>
      			<artifactId>war</artifactId>
      			<version>1.0-SNAPSHOT</version>
      		</dependency>
      		<dependency>
      			<groupId>com.hardik.seaminaction</groupId>
      			<artifactId>action</artifactId>
      			<version>1.0-SNAPSHOT</version>
      		</dependency>
            <dependency>
      			<groupId>com.hardik.seaminaction</groupId>
      			<artifactId>model</artifactId>
      			<version>1.0-SNAPSHOT</version>
            </dependency>
      	</dependencies>
      </dependencyManagement>
        <dependencies>
            <!-- hibernate dependencies with provided scope -->
        </dependencies>
    
       <repositories>
      	<repository>
      		<id>jboss</id>
      		JBoss Repository
            <url>http://repository.jboss.org/maven2/</url>
      	</repository>
      </repositories>
    </project>
    

    Links:

    1. Seam
    2. Contexts and Dependency Injection in Java EE 6 (JSR 299)
    3. Google Guice
    4. Spring framework
    5. Seam in action
    6. Seam maven reference implementation
    7. Seam 2.x Web Development

     
  • hardikmehta 8:52 am on September 12, 2009 Permalink | Reply
    Tags: , java-server-faces, , jsf, maven,   

    Maven dependencies for a basic JSF project 

    With some search and experiments, I figured out the following maven dependencies for a basic JSF project. These dependencies also allow autocompletion of JSF tags in the IDEs like eclipse and intellij idea. I post this for my own reference and may be someone searching for it.

    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hardik.jsfinaction</groupId>
      <artifactId>HelloJsf</artifactId>
    <packaging>war</packaging>
      <version>1.0</version>
      <name>HelloJsf Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.0</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>1.2_02</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>1.2-b19</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>
      </dependencies>
      <build>
        <finalName>HelloJsf</finalName>
    <plugins>
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
    <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <server>tomcat</server>
                </configuration>
            </plugin>
        </plugins>
      </build>
    </project>
    
     
  • hardikmehta 8:03 pm on July 9, 2009 Permalink | Reply
    Tags: ant, apache-maven, build-tools, ejb, ejb3, , , , maven,   

    Maven quirk ( archetype-j2ee-simple ) 

    Update:

    The issue has been fixed. There were two points.

    1. I was using the wrong (deprecated) goal archetype:create instead of archetype:generate.

    2. With the plugin archetype-j2ee-simple there is a bug which is already reported here.

    I got my answer from Antony Stubbs on Stackoverflow.

    At last I also decided to join the maven[1] bandwagon, I will start using maven for managing my projects. Convention over configuration  sounds  indeed a nice idea.  When I first heard about maven  I didn’t have a good “feeling” about it, may be because I was too comfortable with ant and believe to be able to achieve any task with it. But now after reading some documentation and articles about maven, I came to realise it is completely new paradigm than ant. In my opinion the best aspect of maven is that you always have the big picture of your project in mind instead of a small task or operation to be done.  I started liking maven and  also started learning it.  For reference I have started following  Maven: The Definitive Guide[2]. Another great advantage could be that if you know maven and a join a new team which also uses maven for project management, you don’t have to spend hours or may be days trying to figure out the structure of their project and being able to build it.

    Although I started liking maven, sometimes it feels like a strange tool, where you have to configure a lot to achieve your goal. if you want some custom stuff in your project. I also find it annoying that by default the compiler-plugin assumes you want to build for java 1.4 or java 1.3.  Moreover, because there are always so called sensible or obvious defaults assumed, in maven world, not all the obvious defaults are obvious to you and you have to know the documentation well to be able to know what those defaults are. and how you can achieve something different. It feels somewhat like javadocs, until you get used to the apis you need frequently, you have to rely on auto-completion of your IDE or have the javadoc always open. There is no wonder that the second part of the book, I mentioned contains only the maven reference.

    But, yes, I am here to talk about the quirk of maven which I encountered during my learning process. I am just a maven beginner, so may be this is normal behavior, but I don’t think so.

    So, while starting to learn maven, I started with a contrived JavaEE application (brave huh), which is taken as example in the very good book EJB 3 in Action[3]. I searched the net and found out about the maven archetype j2ee-simple here. I used following commandline to generate the stubs of a simple JavaEE project, actually I was interested in the standard directory structure.

    mvn archetype:create -DgroupId=com.hardik -DartifactId=ActionBazaar -DarchetypeArtifactId=maven-archetype-j2ee-simple

    The project was created perfectly, but by default it was not compiling. When I executed mvn intall I had following errors.

    $ mvn install
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [ERROR] FATAL ERROR
    [INFO] ————————————————————————
    [INFO] Error building POM (may not be this project’s POM).

    Project ID: unknown

    Reason: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown

    [INFO] ————————————————————————
    [INFO] Trace
    org.apache.maven.reactor.MavenExecutionException: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown
        at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:432)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:300)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: org.apache.maven.project.ProjectBuildingException: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown
        at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1575)
        at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:506)
        at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
        at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:632)
        at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:515)
        at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:588)
        at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:419)
        … 12 more
    Caused by: java.io.FileNotFoundException: /home/hardik/projects/ActionBazaar/site (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.(FileInputStream.java:106)
        at hidden.org.codehaus.plexus.util.xml.XmlReader.(XmlReader.java:124)
        at hidden.org.codehaus.plexus.util.xml.XmlStreamReader.(XmlStreamReader.java:67)
        at hidden.org.codehaus.plexus.util.ReaderFactory.newXmlReader(ReaderFactory.java:118)
        at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1570)
        … 18 more
    [INFO] ————————————————————————
    [INFO] Total time: < 1 second [INFO] Finished at: Thu Jul 09 18:44:31 CEST 2009 [INFO] Final Memory: 1M/4M [INFO] ------------------------------------------------------------------------[/sourcecode]

    It is talking about some model file for the site module. The site module is generally the “website” of your project that maven generates just by looking at your pom.xml file. I removed the site module from the module list of the pom file and it started working. But I still wonder why the default project structure doesn’t build. I am sure this is incorrect behavior.

    If someone has had the same problem, and was able to fix, please let me know.

    References:

    1. Apache-maven
    2. Maven: The Definitive Guide
    3. EJB 3 in Action

    $ mvn install
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [ERROR] FATAL ERROR
    [INFO] ————————————————————————
    [INFO] Error building POM (may not be this project’s POM).Project ID: unknown

    Reason: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown

    [INFO] ————————————————————————
    [INFO] Trace
    org.apache.maven.reactor.MavenExecutionException: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown
    at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:432)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:300)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: org.apache.maven.project.ProjectBuildingException: Could not find the model file ‘/home/hardik/projects/ActionBazaar/site’. for project unknown
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1575)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:506)
    at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
    at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:632)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:515)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:588)
    at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:419)
    … 12 more
    Caused by: java.io.FileNotFoundException: /home/hardik/projects/ActionBazaar/site (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.&lt;init>(FileInputStream.java:106)
    at hidden.org.codehaus.plexus.util.xml.XmlReader.&lt;init>(XmlReader.java:124)
    at hidden.org.codehaus.plexus.util.xml.XmlStreamReader.&lt;init>(XmlStreamReader.java:67)
    at hidden.org.codehaus.plexus.util.ReaderFactory.newXmlReader(ReaderFactory.java:118)
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1570)
    … 18 more
    [INFO] ————————————————————————
    [INFO] Total time: < 1 second
    [INFO] Finished at: Thu Jul 09 18:44:31 CEST 2009
    [INFO] Final Memory: 1M/4M
    [INFO] ————————————————————————

     
    • Eduardo 6:50 pm on August 2, 2010 Permalink | Reply

      Precisa executar o Maven 2 Eclipse (M2Eclipse) para fazer o maven apontar corretamente para os jars

    • Eduardo 6:51 pm on August 2, 2010 Permalink | Reply

      Need to run the Maven 2 Eclipse (M2Eclipse) to make the point maven correctly for the jars.

    • Jijo 9:32 pm on April 17, 2011 Permalink | Reply

      In every module or project in the workspace make sure the and the element in the pom.xml contain the same entries. In this example below it is ad-common. With this it should work.

      ad-common
      jar
      0.0.1-SNAPSHOT
      ad-common

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
%d bloggers like this: