martes, 6 de mayo de 2008

Subir un war con Maven (II)

Si al realizar un deploy con maven, nos da un NullPointerException como el siguiente:

[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - com.viavansi:entidadesSancionador:war:SNAPSHOT
[INFO] task-segment: [clean, compile, package]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory D:\cvs\EntidadesSancionador_V1_0_4\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] artifact com.viavansi.framework:viavansi-core: checking for updates from Viavansi
[INFO] artifact commons-beanutils:commons-beanutils: checking for updates from Viavansi
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '7ae54a9ef4953334f7a4d44781bade0e737dec9e'; remote = 'c4ecbc1642ca37c2b39cf49e917c9fd76f1c8874' - RETRYING
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '7ae54a9ef4953334f7a4d44781bade0e737dec9e'; remote = 'c4ecbc1642ca37c2b39cf49e917c9fd76f1c8874' - IGNORING
[INFO] artifact com.viavansi.framework:viavansi-juntaandalucia: checking for updates from Viavansi
Downloading: http://repositorio.viavansi.com/repo/axis/axis-jaxrpc/1.4/axis-jaxrpc-1.4.pom
Downloading: http://repo1.maven.org/maven2/axis/axis-jaxrpc/1.4/axis-jaxrpc-1.4.pom
Downloading: http://repositorio.viavansi.com/repo/axis/axis-saaj/1.4/axis-saaj-1.4.pom
Downloading: http://repo1.maven.org/maven2/axis/axis-saaj/1.4/axis-saaj-1.4.pom
[INFO] artifact com.viavansi.framework:viavansi-jpa: checking for updates from Viavansi
[INFO] artifact com.viavansi.framework:viavansi-jsftools: checking for updates from Viavansi
[INFO] artifact com.viavansi:plantilla-client: checking for updates from Viavansi
[INFO] artifact com.viavansi.tramitacion:tramitacionTrewa: checking for updates from Viavansi
[INFO] [compiler:compile]
[INFO] Compiling 234 source files to D:\cvs\EntidadesSancionador_V1_0_4\target\classes
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Not compiling test sources
[INFO] [surefire:test]
[INFO] Tests are skipped.
[INFO] [war:war]
[INFO] Packaging webapp
[INFO] Assembling webapp[entidadesSancionador] in [D:\cvs\EntidadesSancionador_V1_0_4\target\entidadesSancionador-SNAPSHOT]
[INFO] Processing war project
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at java.io.File.(File.java:194)
at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.handleWebResources(WarProjectPackagingTask.java:88)
at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.performPackaging(WarProjectPackagingTask.java:64)
at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:364)
at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:317)
at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:166)
at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:130)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:280)
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)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16 seconds
[INFO] Finished at: Mon May 05 17:33:33 CEST 2008
[INFO] Final Memory: 10M/34M
[INFO] ------------------------------------------------------------------------


Es debido a que está intentando buscar un profile y al no indicarle ninguno da un nullPointer, o sea que no hemos incluido en los parámetros de llamada a maven el -Dproduccion por ejemplo. En cualquier caso, no debería ser -Dproduccion, sino -Pproduccion, ya que la -P le indica que active los perfiles indicados y que buscará en el fichero 'profiles.xml' (el parámetro -D realmente define una propiedad del sistema y anteriormente nos la encontraba al tener definida una propiedad así en dicho fichero).

En cualquier caso, para evitar que este error se de más por olvidarnos incluir dicho parámetro en la llamada a maven, lo mejor es indicarle en el fichero 'profiles.xml' un profile por defecto. Para ello, basta con incluir lo siguiente después de los profiles:

< !-- Indicamos el profile por defecto -->
< activeProfiles>
< activeProfile>produccion
< /activeProfiles>

La llamada correcta para hacer el deploy con el profile de producción por ejemplo sería:

mvn -Pproduccion -Dxmx512m -Dmaven.test.skip=true clean package

Pero en cualquier caso, si hiciésemos la llamada sin el parámetro de producción:

mvn -Dxmx512m -Dmaven.test.skip=true clean package

no nos daría error ya que cogería ese por defecto.