Showing posts with label MAVEN. Show all posts
Showing posts with label MAVEN. Show all posts

Sunday, September 25, 2011

Customization of WSDL using bindings.xml

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="RestaurantService.wsdl"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
        <jaxb:globalBindings choiceContentProperty="true" 
            collectionType="java.util.Set"
            generateIsSetMethod="true"
            enableJavaNamingConventions="true">
            <!--
                <jaxb:javaType name="java.util.Date"
                xmlType="xs:dateTime"
                parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
                printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>
                <jaxb:javaType name="java.util.Date" xmlType="xs:date"
                parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDate"
                printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDate"/>
            -->
        </jaxb:globalBindings>
    </jaxws:bindings>
</jaxws:bindings> 


Reference Link

Monday, August 29, 2011

MULE HTTP Web Service - Step2A. Creating the client jars from the WSDL with Options

This step focuses on creating the client jars from the WSDL created in the previous step. This serves two purposes.
  1. To verify that the WSDL and the XSD was created without any errors.
  2. To get the jars ready so that we will have the class files generated for the objects defined in XSD. These classes will be used in our Mule web service.
This example focuses on using the Maven cxf-codegen-plugin to generate the classes.

Since we are going to develop a Mule Web Service using maven, we can easily import the client jar in your pom.xml

1. Create a simple maven project in Eclipse.



2. Add the cxf-codegen-plugin to your pom.xml

<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>org.hello</groupId>
    <artifactId>HelloServiceClient</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>2.4.0</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>http://hello.services.com=com.services.hello.helloservice</extraarg>
                                        <extraarg>-p</extraarg>
                                        <extraarg>http://ws.hello.services.com=com.services.hello.helloservice.ws</extraarg>
                                    </extraargs>
                                    <wsdl>${basedir}/src/main/resources/Hello.wsdl</wsdl>
                                    <bindingFiles>
                                        <bindingFile>${basedir}/src/main/resources/bindings.xml</bindingFile>
                                    </bindingFiles>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

3. Move the WSDL and XSD created in the previous section under src/main/resources

4. Make sure that you have JDK in your project classpath and not JRE. This plugin needs to compile and generate the class files and it requires a JDK to do it.

5. Right click on the project, go to Run As and select Maven Package.

With the above steps the client jar would get generated successfully and the client jar should contain the following structure.


Thursday, July 28, 2011

HIBERNATE - Hibernate Artifacts from Maven

How can I use Maven to get the latest Hibernate release?

The Maven Repository contains the hibernate jars as separate artifacts. The following dependencies in your pom.xml should be enough to get the hibernate jars in your maven 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mybusiness</groupId>
    <artifactId>HibernateTutorial</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>HibernateTutorial</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.2.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.3.2.GA</version>
            <type>pom</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.1.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project> 

Friday, July 22, 2011

Maven - Installing a jar into local repository

The following command is used to install a jar file to the local maven repository.

>cd MAVEN_HOME

>cd bin

>mvn install:install-file -DgroupId=org.mybusiness -DartifactId=ShippingServiceClient -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file/ShippingServiceClient-1.0.jar

Maven - org.safehaus.jug:jug:jar:asl:2.0.0-osgi Solution

After some struggle I was able to identify the solution for the error Failed to read artifact descriptor for org.safehaus.jug:jug:asl-2.0.0-osgi

These jars were available on the older version of the JBoss Repository and JBoss has stopped providing access to that URL. Hence your pom is unable to find these jars in the JBoss Repository.

To resolve this issue, we need to update the mirrors in maven's settings.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>C:/Vijay/Office/mvn_repo</localRepository>

    <pluginGroups>
        <pluginGroup>org.mule.tools</pluginGroup>
        <pluginGroup>org.jboss.maven.plugins</pluginGroup>
    </pluginGroups>

    <proxies>
    </proxies>

    <servers>
    </servers>

    <mirrors>
        <mirror>
            <id>jboss-public</id>
            <name>JBoss Public Nexus Repository</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <mirrorOf>jboss</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
    </profiles>

</settings>

With the above settings in place, open your Eclipse and go to Windows->Open View->Other->Maven Repositories

In Maven Repositories click on the Refresh button, it would load the new settings.xml to your Eclipse Configuration.

Once the settings are applied, clean your project using Maven Clean and this error should be gone now.

Tuesday, July 12, 2011

MULE & MAVEN - Creating a Mule Project using Maven

After some analysis and struggle I was able to create a Mule Application with Maven and run it on Eclipse. I am providing some version details below and directly moving to the steps to create a Mule Application with Maven.

Mule Version: 2.2.1
Apache Maven Version: 3.0.3

1. The JBoss Maven repository was deprecated and JBoss stopped providing access to http://repository.jboss.org/maven2. So in the Maven Settings.xml which we can find usually under MAVEN_HOME/conf/ location, we need to update the new JBoss repository location. This would indicate Maven to use the new JBoss repository.

<mirror>
            <id>jboss-public</id>
            <name>JBoss Public Nexus Repository</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <mirrorOf>jboss</mirrorOf>
        </mirror>


        <profile>
            <id>jboss-public-repository</id>
            <repositories>
                <repository>
                    <id>jboss-public-repository-group</id>
                    <name>JBoss Public Maven Repository Group</name>
                    <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
                <repository>
                    <id>maven-nuxeo</id>
                    <name>Maven Nuxeo Repository</name>
                    <url>https://maven.nuxeo.org/nexus/content/groups/public/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>jboss-public-repository-group</id>
                    <name>JBoss Public Maven Repository Group</name>
                    <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>

2. For Mule, we need to add the Codehaus repository and the Mule plugin to the settings.xml

    <pluginGroups>
        <pluginGroup>org.mule.tools</pluginGroup>
        <pluginGroup>org.jboss.maven.plugins</pluginGroup>
    </pluginGroups>

      <profile>
            <id>codehaus</id>
            <repositories>
                <repository>
                    <id>codehaus.org</id>
                    <name>CodeHaus Snapshots</name>
                    <url>http://snapshots.repository.codehaus.org</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>codehaus-release-repo</id>
                    <name>Codehaus Release Repo</name>
                    <url>http://repository.codehaus.org</url>
                </repository>
                <repository>
                    <id>codehaus-snapshot-repo</id>
                    <name>Codehaus Snapshot Repo</name>
                    <url>http://snapshots.repository.codehaus.org</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>codehaus.org</id>
                    <name>CodeHaus Plugin Snapshots</name>
                    <url>http://snapshots.repository.codehaus.org</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>

    <activeProfiles>
        <activeProfile>jboss-public-repository</activeProfile>
        <activeProfile>codehaus</activeProfile>
    </activeProfiles>

3. Create a simple Maven Project in Eclipse.

4. Replace the pom.xml with the below contents that contains the basic jar files required for a simple Mule Application.


<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>org.mybusiness</groupId>
    <artifactId>ShippingService</artifactId>
    <version>1.0</version>


    <repositories>
        <repository>
            <id>MuleRepo</id>
            <name>Mule Repository</name>
            <url>http://repository.muleforge.org/</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
        <repository>
            <id>codehaus-repo</id>
            <name>Codehaus Repository</name>
            <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>


    <dependencies>
        <!-- Mule Dependencies Start -->
        <dependency>
            <groupId>org.mule</groupId>
            <artifactId>mule-core</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <!--
            Mule Transports dependency Start We can include the needed
            transports based on the project need
        -->
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-stdio</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-file</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <properties>
        <mule.version>2.2.1</mule.version>
    </properties>
</project>

5. Create a Mule Config file in your project. Since the project do not have the Mule Libraries by default in its classpath, we cannot directly run the application.

Instead Go to Run->Run Configurations
Double click on Java Application.
In the new configuration, provide your project name and in the main class, select the org.mule.MuleServer
In the Arguments tab, provide the input as   -config src/main/resources/mule-config.xml

This will start the Mule Application.

6. To see the Mule logs on the Eclipse console, create a log4j.properties file in the source folder with the following contents.

#------------------------------------------------------------------------------
#
#  The following properties set the logging levels and log appender.  The
#  log4j.rootCategory variable defines the default log level and one or more
#  appenders.  For the console, use 'C'.  For the daily rolling file, use 'R'.
#  For an HTML formatted log, use 'H'.
#
#  To override the default (rootCategory) log level, define a property of the
#  form (see below for available values):
#
#        log4j.logger. =
#
#    Possible Log Levels:
#      FATAL, ERROR, WARN, INFO, DEBUG
#
#------------------------------------------------------------------------------
log4j.rootCategory=INFO, C


#------------------------------------------------------------------------------
#  Also we can define the levels for different packages.
#------------------------------------------------------------------------------
log4j.logger.org.mule=INFO


#------------------------------------------------------------------------------
#
#  The following properties configure the console (stdout) appender.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.C = org.apache.log4j.ConsoleAppender
log4j.appender.C.layout = org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

With this you can see the logs getting displayed on the Eclipse console when the application gets started.

Based on Need: To get the dependencies list for each Mule transport/module refer to the following link.

Friday, July 8, 2011

SPRING SECURITY & MAVEN - How to obtain Spring Security Releases from Maven

The following dependencies provides the artifacts that has to be added to your pom.xml for including the SPRING Framework packages.

<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Portfolio Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>spring.snapshots</id>
<name>Spring snapshot repository</name>
<url>http://maven.springframework.org/snapshot/</url>
</repository>
</repositories>

<!-- Spring Security Dependencies -->

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-security.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring-security.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
<scope>compile</scope>
</dependency>

<properties>
         <spring-security.version>3.0.0.M1</spring-security.version>
</properties>

With these configurations in pom.xml, the Spring Security dependencies will be downloaded to your project.

Wednesday, July 6, 2011

SPRING & MAVEN - Get JSTL and Standard Jars from Maven

In early times, Sun Jars were not available on the central maven repository and people have to go through the tedious process to add the jars manually to their local repository. But the Sun Jar files are now available available in the central maven repository itself and can be referred directly in the pom.xml file.

Samples:

<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>

Tuesday, June 28, 2011

SPRING - How to obtain Spring Releases from Maven

The following dependencies provides the artifacts that has to be added to your pom.xml for including the SPRING Framework packages.


<!--
Core utilities used by other modules. Define this if you use Spring
Utility APIs (org.springframework.core.*/org.springframework.util.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Expression Language (depends on spring-core) Define this if you use
Spring Expression APIs (org.springframework.expression.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Bean Factory and JavaBeans utilities (depends on spring-core) Define
this if you use Spring Bean APIs (org.springframework.beans.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Aspect Oriented Programming (AOP) Framework (depends on spring-core,
spring-beans) Define this if you use Spring AOP APIs
(org.springframework.aop.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Application Context (depends on spring-core, spring-expression,
spring-aop, spring-beans) This is the central artifact for Spring's
Dependency Injection Container and is generally always defined
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Various Application Context utilities, including EhCache, JavaMail,
Quartz, and Freemarker integration Define this if you need any of
these integrations
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Transaction Management Abstraction (depends on spring-core,
spring-beans, spring-aop, spring-context) Define this if you use
Spring Transactions or DAO Exception Hierarchy
(org.springframework.transaction.*/org.springframework.dao.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
JDBC Data Access Library (depends on spring-core, spring-beans,
spring-context, spring-tx) Define this if you use Spring's
JdbcTemplate API (org.springframework.jdbc.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and
iBatis. (depends on spring-core, spring-beans, spring-context,
spring-tx) Define this if you need ORM (org.springframework.orm.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Object-to-XML Mapping (OXM) abstraction and integration with JAXB,
JiBX, Castor, XStream, and XML Beans. (depends on spring-core,
spring-beans, spring-context) Define this if you need OXM
(org.springframework.oxm.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Web application development utilities applicable to both Servlet and
Portlet Environments (depends on spring-core, spring-beans,
spring-context) Define this if you use Spring MVC, or wish to use
Struts, JSF, or another web framework with Spring
(org.springframework.web.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Spring MVC for Servlet Environments (depends on spring-core,
spring-beans, spring-context, spring-web) Define this if you use
Spring MVC with a Servlet Container such as Apache Tomcat
(org.springframework.web.servlet.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Spring MVC for Portlet Environments (depends on spring-core,
spring-beans, spring-context, spring-web) Define this if you use
Spring MVC with a Portlet Container
(org.springframework.web.portlet.*)
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<!--
Support for testing Spring applications with tools such as JUnit and
TestNG This artifact is generally always defined with a 'test' scope
for the integration testing framework and unit testing stubs
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>


<properties>
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
</properties>