Posts Tagged ‘Maven’
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:
[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
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:<module> <source path=""> <include name="**/MyEntity.java"/> </source> </module>
- 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 thepom.xml
:<resources> <resource> <directory>${basedir}/src/java</directory> <includes> <include>**/MyEntity.java</include> </includes> </resource> </resources>
- Add an
<include>**/*.gwt.xml</include>
so that to have toMyDependedProject.gwt.xml
file in the built jar.
In GWT project
In your
*.gwt.xml
file, add the dependency:<inherits name='com.lalou.jonathan.MyDependedProject' />
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. - Add the source
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:
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"
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:
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)
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 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>
In the same folder, I created a property file, gathering the properties hinted at in Ant build.xml
.
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
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:
<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>
At last, my target was OK: I can build and deploy with a simple mvn package -Pdeploy
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
Could not initialize class net.sf.cglib.proxy.Enhancer
Error
Compiling with Maven 2, you have:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [businessApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
Turning Spring logging level to DEBUG, you find:
DEBUG main org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver - Ignoring handler [org.springframework.scripting.config.LangNamespaceHandler]: problem with class file or dependent class
java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
Fix
Add dependencies to Groovy, BSH and JRuby in your pom.xml
:
<dependency> <groupId>groovy</groupId> <artifactId>groovy</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.beanshell</groupId> <artifactId>bsh</artifactId> <version>2.0b4</version> </dependency> <dependency> <groupId>org.jruby</groupId> <artifactId>jruby</artifactId> <version>0.9.8</version> </dependency>
Try of Explanation
Spring depends on the three jars above. But Maven does not link your project to them.
How to test a single class in Maven?
Use the command:
maven test:single -Dtestcase=com.mypath.(...).MyUnitTest