Errors using Maven Mojo sql:execute - postgresql

TL;DR version: I want to be able to use the Maven Mojo SQL Plugin to create/drop any given table in my DB schema (or load data for those tables) at will via the mvn command-line. How?
I'm a long-time Java developer, but for the most part I've been living in an ant-based world. I like the power and explicitness of ant, and the control that it gives me over everything. However, in my new job, there's a push to use maven. So I've decided to learn it using a project I'm working on at home.
One of the things that I have set up on a different personal project is the ability to completely set up and tear down my Postgres database from ant on the command line. I can slice and dice any table, sequence, and integration test data that I please, individually or in concert. Sure, it means that I have about a gajillion ant targets, but it works very well. I like this; it has served me quite well over the years.
In researching how to accomplish this in Maven over the weekend, I found the Mojo SQL Maven Plugin. After looking at the usage page (and I use that term loosely, as it's really just a single semi-example with no explanations) and the example page, I was able to come up with some changes to my pom.xml file. I fixed some obvious typos in the example (postgressql), and referenced the PostgreSQL JDBC page to make sure I had the JDBC connection string correct. I'll paste all of the pom.xml (modified to protect the guilty) below:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>JBoss</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.0.CR7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.3-606.jdbc4</version>
</dependency>
</dependencies>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/myapp</url>
<settingsKey>myapp</settingsKey>
<!--all executions are ignored if -Dmaven.test.skip=true-->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>drop-db-before-test-if-any</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<!-- need another database to drop the targeted one -->
<url>jdbc:postgresql://localhost:5432/template1</url>
<autocommit>true</autocommit>
<sqlCommand>drop database myapp</sqlCommand>
<!-- ignore error when database is not avaiable -->
<onError>continue</onError>
</configuration>
</execution>
<execution>
<id>create-db</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:postgresql://localhost:5432/template1</url>
<!-- no transaction -->
<autocommit>true</autocommit>
<sqlCommand>create database myapp</sqlCommand>
</configuration>
</execution>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/sql/create_person.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>create-data</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<orderFile>ascending</orderFile>
<fileset>
<basedir>${basedir}</basedir>
<includes>
<include>src/test/sql/person_data.sql</include>
</includes>
</fileset>
</configuration>
</execution>
<!-- drop db after test -->
<execution>
<id>drop-db-after-test</id>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:postgresql://localhost:5432/template1</url>
<autocommit>true</autocommit>
<sqlCommand>drop database myapp</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Now, since I haven't created the database, it doesn't show up in a \l on the PG command-line:
[mike#mike myapp]$ psql template1
Welcome to psql 8.3.5, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
template1=# \l
List of databases
Name | Owner | Encoding
-----------+----------+----------
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
(3 rows)
Thus, when I run mvn sql:execute, I expect my database to get created...Or at least not to fail on the drop-db-before-test-if-any task since that is set to continue on error. But of course:
[mike#mike myapp]$ mvn sql:execute
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (default-cli) # myapp ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.667s
[INFO] Finished at: Mon Dec 05 20:22:17 CST 2011
[INFO] Final Memory: 3M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project myapp: FATAL: database "myapp" does not exist -> [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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The error page mentioned on the last line there isn't helpful; it just tells me that a plugin caused the error, not Maven itself.
So let's run it with the -X switch. I'll just post the interesting part of the error:
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project myapp: FATAL: database "myapp" does not exist -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project myapp: FATAL: database "myapp" does not exist
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: FATAL: database "myapp" does not exist
at org.codehaus.mojo.sql.SqlExecMojo.execute(SqlExecMojo.java:618)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: org.postgresql.util.PSQLException: FATAL: database "myapp" does not exist
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:444)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:99)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:29)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:386)
at org.postgresql.Driver.connect(Driver.java:260)
at org.codehaus.mojo.sql.SqlExecMojo.getConnection(SqlExecMojo.java:899)
at org.codehaus.mojo.sql.SqlExecMojo.execute(SqlExecMojo.java:612)
... 21 more
But, but, but...<onError>continue</onError>!
So, to the questions:
What am I doing wrong? Is it my expectations, or my code?
You'll notice that I have a create-person.sql file. I know from the examples that I can have multiple files there, such as create-address.sql. But in ant, I have the ability to create the address table separately from the person table, so long as I perform the ant tasks keeping in mind the order of referential integrity. Is something like that possible with maven? If so, how?
Sorry for the verbosity, and thanks in advance for any assistance.

Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute
(default-cli)
default-cli is the special executionId when the plugin is invoked from command-line. See this.
You have bound all the sql plugin execution to maven lifecycle phases, but you are trying to invoke the plugin directly.
mvn test should work.
Here is a related SO discussion.

Related

Maven pom.xml for MATLAB compiler project

I have a Tomcat servlet project that requires a MATLAB jar generated by mcc. I have implemented a mojo plugin (mcc-maven-plugin) that generates the jar. It simply takes the specifications from a pom and creates a MATLAB command of the form:
cd '/home/jeffemandel/webpropofolmm/matlab/src/main/matlab';mcc -W 'java:webpropofol_java,loadServlet' -d '/home/jeffemandel/webpropofolmm/matlab/target' class{loadServlet:loadServlet.m} class{locServlet:locServlet.m} class{testStruct:testStruct.m}
This generates the file /home/jeffemandel/webpropofolmm/matlab/target/webpropofol_java.jar
Note that target must exist for mcc to work.
I need this file in my main project, but it is resource-intensive to generate the jar every time I make a minor tweak to the UI (which has a small amount of Java and a lot of HTML, css, and javascript). My confusion point is how to generate a jar that doesn't depend on any Java code. Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.jeffmandel.webpropofol</groupId>
<artifactId>optimaltiva</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javabuilder</groupId>
<artifactId>javabuilder</artifactId>
<version>9.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jeffmandel</groupId>
<artifactId>mcc-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>mcc</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<packageName>webpropofol_java</packageName>
<className>loadServlet</className>
<classes>
<loadServlet>loadServlet.m</loadServlet>
<locServlet>locServlet.m</locServlet>
<testStruct>testStruct.m</testStruct>
</classes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<groupId>org.jeffmandel.webpropofol</groupId>
<artifactId>optimaltiva</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${project.build.directory}/webpropofol_java.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run mvn compile, this is what I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< org.jeffmandel.webpropofol:optimaltiva >---------------
[INFO] Building optimaltiva 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # optimaltiva ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jeffemandel/webpropofolmm/matlab/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # optimaltiva ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-antrun-plugin:1.4:run (default) # optimaltiva ---
project.artifactId
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] --- mcc-maven-plugin:0.0.1-SNAPSHOT:mcc (default) # optimaltiva ---
[INFO] cd '/home/jeffemandel/webpropofolmm/matlab/src/main/matlab';mcc -W 'java:webpropofol_java,loadServlet' -d '/home/jeffemandel/webpropofolmm/matlab/target' class{loadServlet:loadServlet.m} class{locServlet:locServlet.m} class{testStruct:testStruct.m}
[INFO] Loading source files for package webpropofol_java...
Constructing Javadoc information...
Standard Doclet version 1.8.0_221
Building tree for all the packages and classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/loadServlet.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/loadServletRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/locServlet.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/locServletRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/testStruct.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/testStructRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/Webpropofol_javaMCRFactory.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-frame.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-summary.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-tree.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/constant-values.html...
Building index for all the packages and classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/overview-tree.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/index-all.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/deprecated-list.html...
Building index for all classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/allclasses-frame.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/allclasses-noframe.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/index.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/help-doc.html...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.215 s
[INFO] Finished at: 2020-12-12T22:26:54-05:00
[INFO] -----
The problem is that every time I run mvn compile it generates the jar, rather than seeing that the source files haven't changed so don't regenerate the jar. My ultimate goal is to have one project that contains the matlab and servlet.
I did some more reading and figured out that it was the responsibility of the mojo plugin to figure out whether recompilation was needed. MATLAB needs to rebuild the entire jar even if only a single file changes, so I added the following code to my mojo plugin:
import org.apache.commons.io.filefilter.AgeFileFilter;
import java.io.FileFilter;
File myJar = new File(outputDirectory + File.separator + packageName + ".jar");
AgeFileFilter myFilter = new AgeFileFilter(myJar, false);
File source = new File(sourceDirectory);
File[] files = source.listFiles((FileFilter) myFilter);
if (files.length==0) {
getLog().info("Project up to date");
} else {
...
}
This does the trick.

Load values from external file into pom.xml

I am trying to read some parameters in a pom.xml from an external file. I am using properties-maven-plugin, but I don't really mind any other solution to read values from an external file as a variable in pom.
Here is my plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>read-project-properties</goal>
</goals>
<phase>initialize</phase>
<configuration>
<!--<files>
<file>${apps.basedir}/apps/flywayvariables.properties</file>
<file>/home/gokul/git/sampleproject/apps/flywayvariables.properties</file>
</files>-->
<urls>
<url>file:///${apps.basedir}/apps/flywayvariables.properties</url>
</urls>
</configuration>
</execution>
</executions>
</plugin>
Here is where I am trying to use it:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>7.0.1</version>
<configuration>
<sqlMigrationSeparator>__</sqlMigrationSeparator>
<locations>
<location>filesystem:${apps.basedir}/apps/flyway</location>
</locations>
<url>jdbc:postgresql://localhost:9000/postgres</url>
<user>${dbuser}</user>
<flyway.user>${dbuser}</flyway.user>
<flyway.password>${dbpassword}</flyway.password>
<password>${dbpassword}</password>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>migrate</id>
<goals>
<goal>migrate</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
</plugin>
And here is my properties file:
<properties>
<dbuser>postgres</dbuser>
<dbpassword>test1234</dbpassword>
</properties>
When I run mvn -X initialize, I get the following error:
[DEBUG] Configuring mojo org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties from plugin realm ClassRealm[plugin>org.codehaus.mojo:properties-maven-plugin:1.0.0, parent: sun.misc.Launcher$AppClassLoader#5c647e05]
[DEBUG] Configuring mojo 'org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties' with basic configurator -->
[DEBUG] (f) project = MavenProject: com.example.company:sampleapplication # /home/gokul/git/sampleproject/apps/pom.xml
[DEBUG] (f) quiet = false
[DEBUG] (s) urls = [file:////home/gokul/git/sampleproject/apps/flywayvariables.properties]
[DEBUG] -- end configuration --
[DEBUG] Loading properties from URL file:////home/gokul/git/sampleproject/apps/flywayvariables.properties
[INFO]
[INFO] --- flyway-maven-plugin:7.0.1:migrate (migrate) # apps ---
...
...
...
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.422 s (Wall Clock)
[INFO] Finished at: 2020-10-13T01:18:40+02:00
[INFO] Final Memory: 33M/1237M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:7.0.1:migrate (migrate) on project apps: org.flywaydb.core.internal.exception.FlywaySqlException:
[ERROR] Unable to obtain connection from database (jdbc:postgresql://localhost:9000/postgres) for user 'null': The server requested password-based authentication, but no password was provided.
[ERROR] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] SQL State : 08004
[ERROR] Error Code : 0
[ERROR] Message : The server requested password-based authentication, but no password was provided.
I can see that the plugins are executed in the order I would want and yet the property is not loaded. The file path and permissions shouldn't be an issue since I created the properties file with the same user account as I am executing the maven project. No password was provided error changes to authentication failed error when I input the password manually and only keep the $dbuser as a variable. I have tried changing the names of the variables too, in vain. In the properties-maven-plugin configuration, I tried supplying files instead of urls, but it did not make any difference to maven.
Unfortunately none of the solutions in this question helps me.
Tried the following maven goals:
initialize
verify
validate
install
properties:read-project-properties initialize
I am pretty sure you need to write the properties file in the traditional fashion like
dbuser=postgres
dbpassword=test1234
I do not know why the properties plugin does not work, but Flyway itself supports multiple methods for storing these settings outside of the pom. See the Flyway maven documentation for more details.
Below is some snippets from the link:
Configuration Files
Flyway will search for and automatically load the <user-home>/flyway.conf config file if present.
It is also possible to point Flyway at one or more additional config files. This is achieved by supplying the System property flyway.configFiles as follows:
mvn -Dflyway.configFiles=path/to/myAlternativeConfig.conf flyway:migrate
See https://flywaydb.org/documentation/maven/#config-files for more information.
Maven Settings
Alternatively for storing the database user and password, Maven settings.xml files can also be used:
<settings>
<servers>
<server>
<!-- By default Flyway will look for the server with the id 'flyway-db' -->
<!-- This can be customized by configuring the 'serverId' property -->
<id>flyway-db</id>
<username>myUser</username>
<password>mySecretPwd</password>
</server>
</servers>
</settings>

Maven-jetty-plugin hot deploy multi module project

I am working on alfresco and I have a multi module project that looks like that :
- parentModule
- alfrescoModule
- shareModule
- ampAlfrescoModule (contains java classes)
- ampShareModule
- runnerModule
I would like to hot redeploy modified classes from the ampAlfrescoModule
Here is the content of runnerModule's pom :
<profiles>
<profile>
<id>run</id>
<activation>
<property>
<name>run</name>
</property>
</activation>
<properties>
<runner.host>127.0.0.1</runner.host>
<runner.port>8080</runner.port>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<executions>
<execution>
<id>run</id>
<goals>
<goal>run</goal>
</goals>
<phase>integration-test</phase>
</execution>
</executions>
<configuration>
//this is what i've tested but it doesn't work
<scanIntervalSeconds>5</scanIntervalSeconds>
<classesDirectory>../ampAlfrescoProject/target/classes</classesDirectory>
<!-- Following 3 properties set an empty ROOT context, which is mandatory
to run jetty:run plugin -->
<contextPath>/</contextPath>
<webAppSourceDirectory>.</webAppSourceDirectory>
<webXml>jetty/root-web.xml</webXml>
<contextHandlers>
<contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
<war>${project.basedir}/../alfrescoProject/target/alfrescoProject.war</war>
<contextPath>/alfresco</contextPath>
</contextHandler>
<contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
<war>${alfresco.solr.dir}/apache-solr-1.4.1-overlay.war</war>
<contextPath>/solr</contextPath>
</contextHandler>
<contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
<war>${project.basedir}/../shareProject/target/shareProject.war</war>
<contextPath>/share</contextPath>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
It deploys 3 wars in jetty. I have to point to ampAlfrescoModule/target/classes with classesDirectory but it doesn't work.
This is the ouptut I get :
[INFO] restarting org.mortbay.jetty.plugin.Jetty6PluginWebAppContext#986d0e{/,C:\Users\..\workspace\AllInOneAdvancedSearch\runnerProject}
[INFO] Webapp source directory = C:\Users\..\workspace\AllInOneAdvancedSearch\runnerProject
[INFO] Reload Mechanic: automatic
[INFO] Classes directory C:\Users\..\workspace\AllInOneAdvancedSearch\ampAlfrescoProject\target\classes
[INFO] Context path = /
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = C:\Users\..\workspace\AllInOneAdvancedSearch\runnerProject\jetty\root-web.xml
[INFO] Webapp directory = C:\Users\..\workspace\AllInOneAdvancedSearch\runnerProject
[INFO] Reconfiguring scanner after change to pom.xml ...
2013-05-27 10:30:51.956:INFO::No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Restart completed at Mon May 27 10:30:51 CEST 2013
When i run mvn compile my classes are not updated on the server, changes are not detected
Any help would be appreciated, thx

Deploying AEM with maven (Error)

I am trying to deploy AEM with maven, so I follow this tutorial. When I run the command mvn clear package, I get the following error:
C:\workspace\myproject\app>mvn clean package
[INFO] Scanning for projects...
[WARNING] The POM for com.day.jcr.vault:maven-vault-plugin:jar:0.0.10 is missing
, no dependency information available
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.uum:app:1-SNAPSHOT (C:\workspace\myproject\app\pom.xml
) has 3 errors
[ERROR] Unresolveable build extension: Plugin com.day.jcr.vault:maven-vault-
plugin:0.0.10 or one of its dependencies could not be resolved: Failure to find
com.day.jcr.vault:maven-vault-plugin:jar:0.0.10 in http://repo.maven.apache.org/
maven2 was cached in the local repository, resolution will not be reattempted un
til the update interval of central has elapsed or updates are forced -> [Help 2]
[ERROR] Unknown packaging: content-package # line 12, column 16
[ERROR] 'dependencies.dependency.groupId' for :core:jar is missing. # line 1
8, column 22
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildin
gException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginResoluti
onException
my myproject/app/pom.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.uum</groupId>
<artifactId>parent</artifactId>
<relativePath>../parent/pom.xml</relativePath>
<version>1-SNAPSHOT</version>
</parent>
<artifactId>app</artifactId>
<packaging>content-package</packaging>
<name>Sample Application package</name>
<dependencies>
<dependency>
<groupId><!-- {groupId} --></groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- add additional dependencies -->
</dependencies>
<build>
<resources>
<resource>
<directory>${basedir}/META-INF</directory>
<targetPath>../vault-work/META-INF</targetPath>
</resource>
<resource>
<directory>${basedir}/jcr_root</directory>
<excludes>
<exclude>**/.vlt</exclude>
<exclude>**/.vltignore</exclude>
<exclude>**/*.iml</exclude>
<exclude>**/.classpath</exclude>
<exclude>**/.project</exclude>
<exclude>**/.DS_Store</exclude>
<exclude>**/target/**</exclude>
<exclude>libs/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>maven-vault-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<group>Sample</group>
<requiresRoot>true</requiresRoot>
<install>true</install>
<verbose>true</verbose>
<packageFile>${project.build.directory}/${project.artifactId}-${project.version}.zip</packageFile>
<version>${project.version}</version>
<properties>
<acHandling>overwrite</acHandling>
</properties>
<embeddeds>
<embedded>
<groupId><!-- {groupId} --></groupId>
<artifactId>core</artifactId>
<target><!-- {install path in the repository (e.g. /apps/myproject/install)} --></target>
</embedded>
</embeddeds>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>installPackages</id>
<activation>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>maven-vault-plugin</artifactId>
<executions>
<execution>
<id>install-package</id>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Any idea how to get the deployment with maven works?
It looks maven does not know where to find the maven-vault-plugin. You will need to add the Adobe repository to your maven POM, see http://repo.adobe.com/.
That will cause the Unresolveable build extension: Plugin com.day.jcr.vault:maven-vault-
plugin:0.0.10 error and the Unknown packaging: content-package # line 12, column 16 errors.
Also, you still have some variable placeholders (<groupId><!-- {groupId} --></groupId>) from the tutorial left in your code that will need replacing. See the error:
[ERROR] 'dependencies.dependency.groupId' for :core:jar is missing. # line 18, column 22
In the <embeddeds> section of the vault plugin configuration, you can specify maven dependencies that you wish to include. An example of this can be seen in this Managing packages with Maven page.
If you don't want to include any external dependencies in your package right now, you could probably remove the<embeddeds> section altogether.
be sure that you have started CQ/AEM before building project. A lot of errors familiar with vault and maven arise because it.

Maven assembly - Error reading assemblies

I have defined a personalized jar-with-dependencies assembly descriptor. However, when I execute it with mvn assembly:assembly, I get :
...
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] javax/ already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] [assembly:assembly {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error reading assemblies: No assembly descriptors found.
My jar-with-dependencies.xml is in src/main/resources/assemblies/.
My assembly descriptor is the following :
<?xml version='1.0' encoding='UTF-8'?>
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>**/LICENSE*</exclude>
<exclude>**/README*</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/resources/META-INF/services</directory>
<outputDirectory>META-INF/services</outputDirectory>
</fileSet>
</fileSets>
</assembly>
And my project pom.xml is :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>jar-with-dependencies.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.my.app.HowTo</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
When mvn assembly:assembly is performed, dependencies are unpacked and I get the previous error when unpack has finished.
Moreover, if I execute mvn -e assembly:assembly it is say that no descriptors has been found, however it try to unpack dependencies and a JAR with dependencies is created but it doesn't contain META-INF/services/* as specified in descriptor :
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error reading assemblies: No assembly descriptors found.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error reading assemblies: No assembly descriptors found.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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:597)
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)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error reading assemblies: No assembly descriptors found.
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:356)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: No assembly descriptors found.
at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.readAssemblies(DefaultAssemblyReader.java:206)
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:352)
... 19 more
I don't see my error. Does someone has a solution ?
There are two problems here. First, when using your own descriptor, you must specify the path to your customized descriptor file (by the way, you can use any location but putting the descriptor in src/main/resources is maybe not the best choice, you don't really want the descriptor to be packaged in your application, I'd use the standard location which is src/main/assembly as mentioned in this page).
<descriptors>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
Second, your configuration element is currently inside an execution block and is thus specific to this execution. In other words, it won't apply if you run assembly:assembly on the command line. So, if you want to call assembly:assembly with a custom descriptor, either use:
mvn assembly:assembly -Ddescriptor=path/to/descriptor.xml
Or move the configuration outside the execution element (to make the configuration global):
<project>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>path/to/descriptor.xml</descriptor>
</descriptors>
...
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
assembly is trying to open /assemblies/${ref}.xml in classpath
check this
http://maven.apache.org/plugins/maven-assembly-plugin/xref/org/apache/maven/plugin/assembly/io/DefaultAssemblyReader.html