Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

20 Feb 2013

How to run Maven with switch

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test (default-test) on project lucky-number-ws: There are test failures. [ERROR] [ERROR] Please refer to D:\workspaces\SpringTest\lucky-number-ws\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.

Solution: Add the switches after the goal, e.g. test -e -X.

Figure 1: Run Configuration with switch

19 Feb 2013

Unable to access binding information for class. Make sure the binding has been compiled

Problem: Unable to access binding information for class. Make sure the binding has been compiled.

HTTP ERROR 500 Problem accessing /lucky-number-ws/LuckyRequest.wsdl. Reason: Error creating bean with name 'payloadMapping' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'luckyServiceEndpoint' while setting bean property 'endpointMap' with key [TypedStringValue: value [{http://localhost:8080/luckyservice/services/}/LuckyRequest], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'luckyServiceEndpoint' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'marshaller' while setting bean property 'marshaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marshaller' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.jibx.JibxSystemException: Unable to access binding information for class com.blogspot.adaprognotebook.message.LuckyResponse Make sure the binding has been compiled; nested exception is org.jibx.runtime.JiBXException: Unable to access binding information for class com.blogspot.adaprognotebook.message.LuckyResponse Make sure the binding has been compiled

Solution: Run "jibx:bind" goal to compile the binding.

[INFO] Scanning for projects... [INFO] [INFO] ---------------------------------------------------------------- [INFO] Building Lucky Number Web Service 0.0.1-SNAPSHOT [INFO] ---------------------------------------------------------------- [INFO] [INFO] --- jibx-maven-plugin:1.2.4.5:bind (default-cli) @ lucky-number-ws --- [INFO] Running JiBX binding compiler (single-module mode) on 1 binding file(s) [INFO] ---------------------------------------------------------------- [INFO] BUILD SUCCESS [INFO] ---------------------------------------------------------------- [INFO] Total time: 1.772s [INFO] Finished at: Tue Feb 19 18:01:43 CST 2013 [INFO] Final Memory: 11M/24M [INFO] ----------------------------------------------------------------

Plugin or one of its dependencies could not be resolved: Failed to read artifact descriptor: Could not find artifact

Problem: Plugin {plugin name} or one of its dependencies could not be resolved: Failed to read artifact descriptor for {plugin name}: Could not find artifact {plugin name}

[INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 0.079s [INFO] Finished at: Tue Feb 05 12:14:23 CST 2013 [INFO] Final Memory: 5M/8M [INFO] ----------------------------------------------------------- [ERROR] Plugin org.jibx:maven-jibx-plugin:1.2.4-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.jibx:maven-jibx-plugin:jar:1.2.4-SNAPSHOT: Could not find artifact org.jibx:maven-jibx-plugin:pom:1.2.4-SNAPSHOT -> [Help 1]

Cause: The repository does not contain the plugin.

Solution: Add the <pluginRepositories> sections in the pom.xml file.

pom.xml

<pluginRepositories> <pluginRepository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://repository.sonatype.org/content/groups/public/</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>

Error assembling WAR: webxml attribute is required.

Problem: Error assembling WAR: webxml attribute is required.

[INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 1.694s [INFO] Finished at: Tue Feb 05 15:21:46 CST 2013 [INFO] Final Memory: 10M/21M [INFO] ----------------------------------------------------------- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project {project name}: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

Cause: The maven-war-plugin plugin is not configured.

Solution:Add the following section in the pom.xml.

pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>

class org.jibx.runtime.JodaConvert not found in classpath.

Problem: class org.jibx.runtime.JodaConvert not found in classpath.

[INFO] --- jibx-maven-plugin:1.2.4.5:bind (default-cli) @ memberservice --- [INFO] Running JiBX binding compiler (single-module mode) on 1 binding file(s) Running binding compiler version jibx_1_2_5-SNAPSHOT [INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 0.640s [INFO] Finished at: Tue Feb 05 16:53:07 CST 2013 [INFO] Final Memory: 5M/14M [INFO] ----------------------------------------------------------- [ERROR] Failed to execute goal org.jibx:jibx-maven-plugin:1.2.4.5:bind (default-cli) on project memberservice: Internal error - class org.jibx.runtime.JodaConvert not found in classpath -> [Help 1]

Cause: Wrong version of JiBX is used.

Solution:Update the version of JiBX dependencies in the pom.xml.

pom.xml

<dependency> <groupId>org.jibx</groupId> <artifactId>jibx-run</artifactId> <version>1.2.4.5</version> </dependency> <dependency> <groupId>org.jibx</groupId> <artifactId>jibx-extras</artifactId> <version>1.2.4.5</version> </dependency>

'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing.

Problem: 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing.

[WARNING] Some problems were encountered while building the effective model for {project name}:war:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 83, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

Cause: Version number is not set for the maven-compiler-plugin plugin.

Solution:Set the version number under the <artifactId>

pom.xml

<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>

File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!

Problem: File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!

[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent

Cause: Encoding of the source files is not set.

Solution: Set the encoding of the source files.

pom.xml

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

The project uses or overrides a deprecated API.

Problem: The project uses or overrides a deprecated API.

[WARNING] Note: D:\workspaces\Test\LuckyNumberWebService\src\test\java\com\blogspot\adaprognotebook\client\TestLuckyServiceClient.java uses or overrides a deprecated API. [WARNING] Note: Recompile with -Xlint:deprecation for details.

Cause: The project uses or overrides a deprecated API.

Solution: Set "-Xlint:deprecation" as compiler argument during compilation.

pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerArgument>-Xlint:deprecation</compilerArgument> </configuration> </plugin>

Can't resolve Archetype when trying to add one in STS.

Problem: Can't resolve Archetype when trying to add one in STS.
Figure 1: Add Archetype.
Figure 2: Can't resolve Archetype.
Cause: STS cannot resolve the repository even though the Repository URL is specified.
Solution: Set the repository in .m2/settings.xml.
pom.xml
<profiles> <profile> <repositories> <repository> <id>mvn-repository</id> <name>MvnRepository.com</name> <url>http://mvnrepository/</url> </repository> </repositories> </profile> </profiles>

Java.Lang.ClassNotFoundException: Org.Objectweb.Asm.Type

Problem: Java.Lang.ClassNotFoundException: Org.Objectweb.Asm.Type
Caused by: java.lang.NoClassDefFoundError: org.objectweb.asm.Type

WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext java.lang.reflect.InvocationTargetException Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type

Cause: asm.jar is missing.

Solution: Add the dependency in the project's pom.xml.

<dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency>

Project configuration is not up-to-date with pom.xml. Run project configuration update.

Problem: Project configuration is not up-to-date with pom.xml. Run project configuration update.

Description Resource Path Location Type Project configuration is not up-to-date with pom.xml. Run project configuration update {Project Name} line 1 Maven Configuration Problem

Cause: Project configuration is not up-to-date.

Solution: Run "Maven" -> "Update Project Configuration...".

Figure 1: Update Project Configuration

15 Feb 2013

Setup Maven/Jetty plugins in Eclipse

Installation

  1. Install Maven in Eclipse.

Implementation

It is assumed that there is already a web application project on-hand. You may reference to another article "First Hello World Web Application using Maven" to create one.

  1. Configure the project's pom.xml.
    • In order to stop Jetty, <stopPort> and <stopKey> are configured in pom.xml.
    • <scanIntervalSeconds> defines the pause in seconds between sweeps of the webapp to check for changes and automatically hot redeploy if any are detected. By default this is 0, which disables hot deployment scanning. A number greater than 0 enables it.
    • Note that starting from Jetty 7, the Jetty/Maven plugin has been renamed to jetty-maven-plugin in order to fulfill the naming convention of Maven 2. Therefore, the configurations are different.
      • Add the following in the project's pom.xml for Jetty 6 or below.
        <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>${jetty.version}</version> <configuration> <scanIntervalSeconds>60</scanIntervalSeconds> <stopPort>7788</stopPort> <stopKey>foo</stopKey> <webApp> <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> </webApp> </configuration> </plugin> </plugins> </build> <properties> <jetty.version>6.1.26</jetty.version> </properties>
      • Add the following in the project's pom.xml for Jetty 7 or above.
        <repositories> <repository> <id>central-repo-browser</id> <name>The Central Repository Browser</name> <url>http://search.maven.org</url> </repository> </repositories> <build> <plugins> <plugin> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty.version}</version> <configuration> <scanIntervalSeconds>60</scanIntervalSeconds> <stopPort>7788</stopPort> <stopKey>foo</stopKey> <webApp> <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> </webApp> </configuration> </plugin> </plugins> </build> <properties> <jetty.version>8.1.9.v20130131</jetty.version> </properties>
  2. Setup the Debug/Run Configurations in Eclipse.
    1. Select "Debug Configurations.."/"Run Configurations.." from the menu in Eclipse.
    2. In the dialog showed up, create a new configuration and set the goals as "jetty:run". Click the "Apply" button to save.
      Figure 1: New Configuration for starting Jetty.

    3. Create a new configuration and set the goals as "jetty:stop". Click the "Apply" button to save.
      Figure 2: New Configuration for stopping Jetty.

    4. Figure 3: New Configuration for compilation.
    5. Create a new configuration and set the goals as "compile". Click the "Apply" button to save.
  3. Run the configurations.
    • To start Jetty, run the "Start" configuration (created as in Figure 1).
    • To stop Jetty, run the "Stop" configuration (created as in Figure 2).
    • To compile Jetty, run the "Compile" configuration (created as in Figure 3). When <scanIntervalSeconds> is defined, run this configuration for hot deployment.

5 Feb 2013

ConnectException: UnresolvedAddressException

Problem: Plugin {plugin name} or one of its dependencies could not be resolved: ConnectException: UnresolvedAddressException
[INFO] ----------------------------------------------------------- [INFO] Building Hello Maven Webapp 1.0-SNAPSHOT [INFO] ----------------------------------------------------------- Downloading: http://repo1.maven.org/maven2/org/jibx/maven-jibx-plugin/1.2.1/maven-jibx-plugin-1.2.1.pom [INFO] -------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 2.656s [INFO] Finished at: Tue Feb 05 11:22:30 CST 2013 [INFO] Final Memory: 5M/9M [INFO] ----------------------------------------------------------- [ERROR] Plugin org.jibx:maven-jibx-plugin:1.2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.jibx:maven-jibx-plugin:jar:1.2.1: Could not transfer artifact org.jibx:maven-jibx-plugin:pom:1.2.1 from/to central (http://repo1.maven.org/maven2): ConnectException: UnresolvedAddressException -> [Help 1]
Cause: There may be a proxy server or a firewall that restricts which websites one can connect to.
Solution: Configure a proxy to use for some or all of your HTTP requests (available in Maven 2.0) in the settings.xml file.
There are two locations where a settings.xml file may live:
  • The Maven install: $M2_HOME/conf/settings.xml
  • A user's install: ${user.home}/.m2/settings.xml
settings.xml
<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/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <proxy> <active>true</active> <protocol>http</protocol> <host>proxy.somewhere.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>www.google.com</nonProxyHosts> </proxy> </proxies> <profiles/> <activeProfiles/> </settings/&gt

29 Jan 2013

Enable Maven in Existing Eclipse Projects

A hands-on guide to enable Maven in existing Java projects in Eclipse.

In order to facilitate the build process in the software development life cycle, Maven can be used as a software project management and comprehension tool.

Projects are first configured as Maven-enabled. The POM (Project Object Model) file, which is an XML file (pom.xml), contains information about the project and configuration details used by Maven to build project. Configuration includes project dependencies, the plugins or goals that can be executed, the build profiles and so on.

Figure 1: Architecture of the Development Environment

Installation

  1. Install and Configure Maven.

Design

Suppose that three projects are created: myapp-common, myapp-web and myapp-admin.  As shown in Figure 4, myapp-web and myapp-admin have dependency on myapp-common, and this is configured in the POM file.

Figure 4: Projects Dependancies

Implementation

  1. Enable Maven for an existing Eclipse Project.
    1. Execute the following goal to create a maven project:
      mvn archetype:generate -DgroupId=com.blogspot.adaprognotebook-DartifactId=myapp-common -DarchetypeArtifactId=maven-archetype-quickstart mvn archetype:generate -DgroupId=com.blogspot.adaprognotebook-DartifactId=myapp-web -DarchetypeArtifactId=maven-archetype-webapp -Dpackage=war mvn archetype:generate -DgroupId=com.blogspot.adaprognotebook-DartifactId=myapp-admin -DarchetypeArtifactId=maven-archetype-webapp -Dpackage=war
    2. A directory with following structure is created for archetypes maven-archetype-quickstart:
      myapp-common |-- pom.xml |-- src |-- main |-- java |-- resources |-- test |-- java
    3. A directory with following structure is created for archetypes maven-archetype-webapp:
      myapp-web |-- pom.xml |-- src |-- main |-- resources |-- webapp |-- WEB-INF |-- web.xml |-- index.jsp myapp-admin |-- pom.xml |-- src |-- main |-- resources |-- webapp |-- WEB-INF |-- web.xml |-- index.jsp
    4. Create a /src/main/java directory in the myapp-web and myapp-admin projects.  Put the java source files into the /src/main/java directory of the myapp-common, myapp-web and myapp-admin projects appropriately.
    5. Put all the web content files into the /src/main/webapp directory of the myapp-web and myapp-admin projects appropriately.
    6. Generate the eclipse configuration files such that the project is eclipse-enabled:
      mvn eclipse:clean eclipse:eclipse -Dwtpversion=2.0
      The following eclipse configuration files will be generated:
      • .project and .classpath files
      • .setting/org.eclipse.jdt.core.prefs with project specific compiler settings
      • various configuration files for WTP (Web Tools Project), if the parameter wtpversion is set to a valid version (WTP configuration is not generated by default)
    7. Import the existing eclipse project from the File System (see Figure 5).
      Figure 5: Import existing projects into Workspace

    8. Configure eclipse to use the JRE of JDK (see Figure 6).
      Figure 6: Configure Installed JRE
    9. Add the following libraries in Proejct -> Preference -> Java Build Path:
      • Server Runtime
      • Web App Libraries
  2. Configure the connection to the DEV Nexus Server
    1. In the development client PC, open ${USER_HOME}\.m2\settings.xml using a text editor. If it does not exist, copy one from ${MAVEN_HOME}\conf\settings.xml.
    2. Add the following lines in the <servers> section:
      <servers> <server> <id>nexus-releases</id> <username>deployment</username> <password>test123</password> </server> <server> <id>nexus-snapshots</id> <username>deployment</username> <password>test123</password> </server> </servers>
    3. Add the following lines in the section:
      <mirror> <id>nexus</id> <name>nexus public mirror</name> <url>http://{Host of the Nexus server}/nexus/content/groups/public/</url> <mirrorOf>*</mirrorOf> </mirror>
    4. In the POM file, where deployment to Nexus Server is required, add the following lines under the section:
      <distributionManagement> <repository> <id>nexus-snapshots</id> <name>Samvo Repository for Maven</name> <url>http://{Host of the Nexus server}/nexus/content/repositories/snapshots/</url> </repository> </distributionManagement>
  3. Configure the connection from Maven of the Build Server to the Development Tomcat Server
    1. In Build Server, open ${USER_HOME}\.m2\settings.xml using a text editor. If it does not exist, copy one from ${MAVEN_HOME}\conf\settings.xml.
    2. Add the following lines in the section:
      <server> <id>tomcat</id> <username>ad</username> <password>test123</password> </server>
References
  1. Maven, http://maven.apache.org/
  2. Introduction to Archetypes, http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
  3. Hudson, http://hudson-ci.org/
  4. Maven Central Repository Browser, http://search.maven.org/
  5. MVN Repository, http://mvnrepository.com/
  6. MVN Browser, http://www.mvnbrowser.com/
  7. Using Maven profiles and resource filtering, http://www.manydesigns.com/documentation/tutorials/using-maven-profiles-and-resource-filtering.html