Recent Posts
Archives

Posts Tagged ‘Maven 2’

PostHeaderIcon Embedded error: Could not create task or type of type: apt.

Case:

In your Maven2’s pom.xml, you call Java’s APT (Annotation Processing Tool) via maven-antrun-plugin, to generate additional sources based on annotations in your java code.

[xml]<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>…</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<apt
srcdir="src/main/java/com/lalou/jonathan/"
destdir="classes" debug="on"
compile="false" factory="com.lalou.jonathan.Factory preprocessdir="generated-sources/javacc"
classpathref="cpannot" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>[/xml]

You get the following error:
Embedded error: Could not create task or type of type: apt.

Complete stacktrace:

[java]Embedded error: Could not create task or type of type: apt.

Ant could not find the task or a class this task relies upon.

This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
– You have misspelt ‘apt’.
Fix: check your spelling.
– The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
– The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the ‘ant-‘ JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
– The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
– The task is not an Ant core or optional task
and needs to be declared using <taskdef>.
– You are attempting to use a task defined using
<presetdef> or <macrodef> but have spelt wrong or not
defined it at the point of use

Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath

Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.[/java]

Fix:

At least in my case, the error is not related at all to Ant. Therefore, no use searching for any ant-apt.jar and placing in in Ant’s lib folder…
Indeed, the error is known and was fixed with Maven 2.0.10 release. You simply have to upgrade your Maven2 installation, and environment variables (M2_HOME).

PostHeaderIcon No source code is available for type org.junit.Assert; did you forget to inherit a required module?

Case

You run a GWT application, with a a service layer. Those services are tested through unit tests, which may use EasyMock, among other frameworks. Of course, you hinted at related jars, such us JUnit, by a <scope>test</scope> in your pom.xml.

Yet, when you run the GWT application with a Jetty light container, you get the following message:

Compiling module lalou.jonathan.gwt.client.MyModule

Validating newly compiled units

[java][ERROR] Errors in ‘file:/C:/eclipse/workspace/…/test/unit/lalou/jonathan/gwt/client//MyServiceUnitTest.java’
[ERROR] Line 26: No source code is available for type org.easymock.MockControl; did you forget to inherit a required module?
[ERROR] Line 76: No source code is available for type org.junit.Assert; did you forget to inherit a required module?[/java]

Fix

Since Maven2 and GWT scopes are fully independant, you have to modify you *.gwt.xml. Replace:

[xml] &lt;source path=’client’/&gt;[/xml]

with:

[xml]&lt;source path=’client’ excludes=&quot;**/*UnitTest.java,**/*RuntimeTest.java&quot;/&gt;[/xml]

NB: Never forget that Google teams work with Ant, and not with Maven!

PostHeaderIcon Error 403 with Maven 2 deployment

Case

This morning, I tried to redeploy an EAR on a WebLogic 9.2, using Maven 2 and a classical deployment profile. I got this issue:
[java][ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Error executing ant tasks

Embedded error: The following error occurred while executing this line:
(…)
weblogic.deploy.api.internal.utils.DeployerHelperException: The source ‘C:\DOCUME~1\myLogin\LOCALS~1\Temp\myApplication-ear.ear’ for the application ‘my-application-ear’ could not be loaded to the server ‘http://myServer:1234/bea_wls_deployment_internal/DeploymentService’.
Response: ‘403: Forbidden’ for url: ‘http://myServer:1234/bea_wls_deployment_internal/DeploymentService'[/java]

Yesterday, I got a similar error when I launched a mvn tomcat:deploy to deploy a WAR on a Tomcat 6.0 server:
[java][ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Cannot invoke Tomcat manager

Embedded error: Server returned HTTP response code: 403 for URL: http://myServer:3210/manager/deploy?path=%2FmyWebArchive&war=&update=true[/java]

Quick Fix

Running Maven2 in offline line, ie adding the option "-o", allows me to redeploy both the EAR on WebLogic and the WAR on Tomcat.
eg: mvn tomcat:deploy -o
I keep on investigating on this matter. I think there is an issue on the DNS. Indeed, when I deploy locally to my own machine myServer (ie with its network name), this error is raised, but when I deploy to localhost the build is successful.

PostHeaderIcon No source code is available for type … ; did you forget to inherit a required module?

Context

In a GWT application, you have to use RPC calls, using entities which are package in external jar archives. With Eclipse, no error appears ; yet when you build the project with Maven2, you get this message:

[java][INFO] [ERROR] Errors in ‘file:/C:/eclipse/workspace/myGwtProject/src/java/com/lalou/jonathan/web/gwt/client/component/JonathanPanel.java’
(…)
[INFO] [ERROR] Line 24: No source code is available for type com.lalou.jonathan.domain.MyEntity; did you forget to inherit a required module?
(…)
[INFO] Finding entry point classes[/java]

Fix

In related jar

In the project to which MyEntity belongs to (here: my/depended/project):

  • create a file com/lalou/jonathan/MyDependedProject.gwt.xml, with as content:

    [xml]<module>
    <source path="">
    <include name="**/MyEntity.java"/>
    </source>
    </module>[/xml]

  • In the pom.xml:
    • Add the source MyEntity.java in built jar. This way, the Java file itself will be considered as a resource, like an XML or property file. To perform this, the quickest manner is to add the following block in the pom.xml:
      [xml]<resources>
      <resource>
      <directory>${basedir}/src/java</directory>
      <includes>
      <include>**/MyEntity.java</include>
      </includes>
      </resource>
      </resources>[/xml]
    • Add an <include>**/*.gwt.xml</include> so that to have to MyDependedProject.gwt.xml file in the built jar.

    In GWT project

    In your *.gwt.xml file, add the dependency:

    [xml]<inherits name=’com.lalou.jonathan.MyDependedProject’ />[/xml]

    Caution!

    All these operations need be done on all dependencies -either direct or indirect-. Therefore, possibly you may have a huge amount of code to be got.
    Another issue appears when you use a jar of which you do not have the source code, such as in the case of tiers API for instance.

PostHeaderIcon WebLogic deployment automatization with Maven and/or Ant

Case

I had to automatize the deployment of a basic GWT application, packaged as a WAR archive, on a WebLogic 9.2 server.

Maven 2

Mojo Plugin

Firstly, I tried to use Mojo’s maven plugin for Weblogic. I had to add some lines in my pom.xml, almost identical to those available in Mojo’s documentation.

The main issue I encountered was to retrieve the jars mandatory to the plugin, and install them in my local Maven repository. Since the missing jars names given by Maven are not so obvious, here are the paths to retrieve these jars, all included with WebLogic 9.2 installation:

[java]mvn install:install-file -DgroupId=weblogic -DartifactId=xbean -Dversion=9.2 -Dpackaging=jar -Dfile=%BEA_HOME%\server\lib\wlxbean.jar
mvn install:install-file -DgroupId=weblogic -DartifactId=wlw-langx -Dversion=9.2 -Dpackaging=jar -Dfile=%BEA_HOME%\server\lib\wlw-langx.jar
mvn install:install-file -DgroupId=weblogic -DartifactId=wlw-util -Dversion=9.2 -Dpackaging=jar -Dfile="%BEA_HOME%\common\lib\wlw-util.jar"
mvn install:install-file -DgroupId=weblogic -DartifactId=bcel -Dversion=5.1 -Dpackaging=jar -Dfile="%BEA_HOME%\javelin\lib\bcel-5.1.jar"
mvn install:install-file -DgroupId=weblogic -DartifactId=javelinx -Dversion=9.2 -Dpackaging=jar -Dfile="%BEA_HOME%\javelin\lib\javelinx.jar"
mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic-container-binding -Dversion=9.2 -Dpackaging=jar -Dfile="%BEA_HOME%\server\lib\schema\weblogic-container-binding.jar"[/java]

Issues

Once this issue fixed, I tried to launch the deployment (with mvn weblogic:deploy). But I encountered the following error:
Response: '404: Not Found' for url: 'http://localhost:7070/bea_wls_deployment_internal/DeploymentService'
Complete stacktrace in debug and verbose mode:

[java]weblogic.deploy.api.internal.utils.DeployerHelperException: The source ‘C:\LOCALS~1\Temp\appliGWT-1.0-SNAPSHOT.war’ for the application ‘iVarGwt’ could not be loaded to the server ‘http://localhost:7070/bea_wls_deployment_internal/DeploymentService’.
Response: ‘404: Not Found’ for url: ‘http://localhost:7070/bea_wls_deployment_internal/DeploymentService’
at weblogic.deploy.api.internal.utils.JMXDeployerHelper.uploadSource(JMXDeployerHelper.java:658)
at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.upload(ServerConnectionImpl.java:653)
at weblogic.deploy.api.spi.deploy.internal.BasicOperation.uploadFiles(BasicOperation.java:319)
at weblogic.deploy.api.spi.deploy.internal.BasicOperation.execute(BasicOperation.java:411)
at weblogic.deploy.api.spi.deploy.internal.BasicOperation.run(BasicOperation.java:169)
at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.deploy(WebLogicDeploymentManagerImpl.java:369)
at weblogic.deploy.api.tools.deployer.DeployOperation.execute(DeployOperation.java:47)
at weblogic.deploy.api.tools.deployer.Deployer.perform(Deployer.java:139)
at weblogic.deploy.api.tools.deployer.Deployer.runBody(Deployer.java:88)
at weblogic.utils.compiler.Tool.run(Tool.java:158)
at weblogic.utils.compiler.Tool.run(Tool.java:115)
at weblogic.Deployer.run(Deployer.java:70)
at org.codehaus.mojo.weblogic.DeployMojoBase.executeDeployer(DeployMojoBase.java:510)
at org.codehaus.mojo.weblogic.DeployMojo.execute(DeployMojo.java:49)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
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:585)
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)[/java]

Deploying another application worked, deploying my application using WebLogic console worked too… After many hours of search, I gave up Maven2 way.

Ant

After retiring from using Mojo’s plugin, I used a way I feared would be less elegant: Ant.

Indeed, Ant script is very short and efficient:

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

<project name="redeploy" basedir="." default="deploy">
<property file="redeploy.properties" />

<target name="init-weblogic-task">
<available file="${env.WL_HOME}/server/lib/weblogic.jar"
property="weblogic-jar.present" />
<fail unless="weblogic-jar.present">${env.WL_HOME}/server/lib/weblogic.jar does not
exist</fail>

<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"
classpath="${env.WL_HOME}/server/lib/weblogic.jar" />
</target>

<target name="deploy" depends="init-weblogic-task">
<wldeploy action="deploy" source="${source}"
name="${name}" user="${user}" password="${password}" verbose="true"
adminurl="${adminurl}" debug="true" targets="${targets}" upload="true"
securitymodel="${securitymodel}" stage="stage" />
</target>

</project>[/xml]

In the same folder, I created a property file, gathering the properties hinted at in Ant build.xml.

[java]env.WL_HOME=C:/bea/weblogic_9_2
adminurl=t3://localhost:7070
name=appliGWT
user=weblogic
password=myPassword
targets=myTarget
securitymodel=Advanced
source=../../../target/appliGWT-1.0-SNAPSHOT.war
[/java]

I launched Ant and the deployment was successful.

Maven anyway, but with Ant

Yet, since I build with Maven, I do not want to have to build, change folder, and then deploy: I want a unique command line to package and deploy. To perform that, I added a profile in my pom.xml, using a Maven plugin to call Ant tasks:

[xml] <profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile="./src/resources/ant/build.xml"
target="deploy"
inheritall="false" inheritrefs="false"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>[/xml]

At last, my target was OK: I can build and deploy with a simple mvn package -Pdeploy

PostHeaderIcon Maven: resume build from a module

Case

Your have a multi-module project. For any reason, the build fails on your 32nd project (out of 70).
You indentify the issue, fix it, and need rebuild your project. Yet, you don’t want to rebuild the 31 first projects. Rather, you prefer to start on the 32nd one.
On older version of Maven, you had to edit your pom.xml, comment the 31 projects, launch the build and uncomment the projects.

Fix

From Maven 2.1, a new option is available: -rf or —resume-from. Thanks to this option, you can hint to Maven to restart the build at any point you like.

PostHeaderIcon Unit Test output redirection onto the console, with Maven 2

Case

You have to build your project. All tests are OK when you run them in your IDE, but one or more unit tests fail when you launch the build with Maven 2. When this happens, you have to open the SureFire tests reports to read the failures details.

But you’d rather read the failure in the standard output. In other terms, you would like the output to be redirected onto the console, and not in log files.

Fix

When you launch the build, specify the following option:

-Dsurefire.useFile=false

PostHeaderIcon Change settings.xml location

Case

You have to use a custom-set settings.xml file, rather the default one.

By default, settings.xml is assumed to be in one the two following folders:

$M2_HOME/conf/settings.xml
$HOME/.m2/settings.xml

Fix

Use the -s option, for instance:

mvn install -s /path/to/file/otherSettings.xml

PostHeaderIcon Create a new project from Maven2 under Eclipse

Yeah, I know this must be widely known, yet I needed a short while before successing ;-).
Case: I must mount a Java projet from a Maven2 file, under Eclipse (I am back to my prefered IDE).

Fix:

  • Checkout the sources from version control tool
  • Open a console window
  • Go to the project home
  • (possibly: mvn install)
  • mvn eclipse:eclipse
  • Open Eclipse
  • File > New Project > add the name > check "create project from existing tool" > Finish

And it’s over!

PostHeaderIcon Multi-profiles with Maven 2

Case: you work on two different projects, which use different repositories. How to search, find and download needed jars owing to the project?

Maven2 allows you to define different profiles.
For that, edit your Maven2 config file, available at $HOME/.m2/settings.xml.

Define your first profile:
[xml]
<profile>
<properties>
<maven.user>jlalou</maven.user>
<myProject.version>12.3</myProject.version>
</properties>
<repositories><repository>
<id>FirstProjectID</id>
<name>My First Project</name>
<url>http://blabla.bla.bla</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository></repositories>
</profile>[/xml]

Define your first profile:
[xml]
<profile>
<properties>
<maven.user>genericUser</maven.user>
<myProject.version>45.6</myProject.version>
</properties>
<repositories><repository>
<id>SecondProjectID</id>
<name>My Personnal Project</name>
<url>http://foo.foo.foo</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository></repositories>
</profile>[/xml]

At the end of the file, add following tags:
[xml]
<activeProfiles>
<activeProfile>FirstProjectID</activeProfile>
<activeProfile>SecondProjectID</activeProfile>
</activeProfiles>[/xml]

Now, on compiling, use the option -P to hint which project/profile you want to use:
maven clean install -PFirstProjectID