Load values from external file into pom.xml - postgresql

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>

Related

my configuration of scala-maven-plugin with multi-module project doesn't let me do 'mvn compile' in a sub directory

We are using the scala-maven-plugin for our mixed Java/Scala project. Works nicely in general, but we have found that with a multi-module project we can't figure out how to do a'mvn compile' in a subdirectory.
I am unable to post my full source code to IP restrictions, but in my search for other projects that might
have solved this issue I only managed to come up with other projects with the exact same problem. Here is one
for example: https://github.com/buildlackey/scala-multimodule-sample-project.git
The above project has three submodules beneath the directory that holds the root pom.xml: cats, dogs and web-application.
If you git clone the above url, then cd to 'scala-multimodule-sample-project', you will see it build.
Now if I cd into the sub-module 'dogs' and do a 'mvn compile', I see the message:
[INFO] No sources to compile
But there are sources to compile ! The plugin is just not finding them.
This is the same thing that happens on my multi-module project. I can't post the whole source for our stuff.. But here
is the relevant configuration from our top level pom.xml :
<build>
<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
<!-- Compiling scala code -->
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
According to the documentation for the plug-in (http://davidb.github.io/scala-maven-plugin/add-source-mojo.html)
there are are optional parameters that can be passed to the add-source goal: namely, sourceDir and testSourceDir
However, I could not figure out how to pass these. Maybe those parameters are the key to success here ?
Finally, one kind of silly work-around that proved successful is to copy the same configuration for scala-maven-plugin into each submodule directory where I want to do a compile restricted to that submodule. Obviously this is a non-DRY, undesirable approach.
I'd be most grateful if anyone could suggest a good solution.
Thanks !
I uploaded a working sample at https://github.com/davidB/scala-maven-plugin/tree/master/samples/prj_multi_modules
The duplicate solution is the common usage.
The DRY alternative is to declare the configuration of the plugin in the <pluginManagement> section, then add under <build><plugins><plugin> the groupId + artifactId for project(s) where you want to enable the plugin. You can add it into modules'pom.xml or into parent's pom.xml inherited by every modules.
You could also use <dependencyManagement> to avoid duplicate dependency's version.
The addSource is to register additional source directory and expose it for IDE and other plugins.
I think you have wrong value for sourceDir in your scala-multimodule-sample-project pom.xml file.
I change sourceDir to the src/main/scala and after mvn compile I have the following output:
...
[INFO] skip non existing resourceDirectory /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # cats ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-scala-plugin:2.15.2:compile (default) # cats ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.java,**/*.scala,]
[INFO] excludes = []
[INFO] /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/src/main/scala:-1: info: compiling
[INFO] Compiling 1 source files to /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/target/classes at 1453711735781
...

Trouble when importing a maven project into eclipse kepler (swagger for jersey rest)

I have created a rest webservice with jersey. I like to add swagger to my project to create documentation for the rest interface. As an example i downloaded a rest project with swagger. It is a maven project.
I installed maven on ubuntu & installed maven plugin into eclipse,
After a Maven clean, maven install & maven build on the project.
i get a few errors in console:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
In stackoverflow i see that someone has added manually this jar file?
Is it not a job for maven, because the dependency is in the pom?
--------------------------------------
...
2013-12-25 20:32:55.209:INFO:oejs.Server:jetty-8.1.11.v20130520
2013-12-25 20:32:56.168:WARN:oejw.WebAppContext:Failed startup of context o.m.j.p.JettyWebAppContext{/api,file:/home/scorpio/Downloads/swagger-core-swagger-project_2.9.1-1.3.0-RC1/samples/java-jaxrs/target/swagger-java-sample-app_2.9.1-1.3.0-RC1/},file:/home/scorpio/Downloads/swagger-core-swagger-project_2.9.1-1.3.0-RC1/samples/java-jaxrs/target/swagger-java-sample-app_2.9.1-1.3.0-RC1/
java.util.zip.ZipException: invalid entry size (expected 6164 but got 4968 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:386)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:156)
at java.util.jar.JarInputStream.read(JarInputStream.java:195)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:100)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:78)
at java.util.jar.JarInputStream.getNextEntry(JarInputStream.java:130)
at java.util.jar.JarInputStream.getNextJarEntry(JarInputStream.java:167)
at org.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:162)
at org.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:100)
at org.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:82)
at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:84)
.....
INFO] Started Jetty Server
[INFO]
[INFO] --- maven-failsafe-plugin:2.6:integration-test (default) # swagger-java-sample-app_2.9.1 ---
[INFO] No tests to run.
[INFO]
[INFO] --- jetty-maven-plugin:8.1.11.v20130520:stop (stop-jetty) # swagger-java-sample-app_2.9.1 ---
[INFO]
[INFO] --- maven-source-plugin:2.1.2:jar-no-fork (attach-sources) # swagger-java-sample-app_2.9.1 ---
[INFO]
[INFO] --- maven-javadoc-plugin:2.7:jar (attach-javadocs) # swagger-java-sample-app_2.9.1 ---
2013-12-25 20:32:56.778:INFO:oejsh.ContextHandler:stopped o.m.j.p.JettyWebAppContext{/api,file:/home/scorpio/Downloads/swagger-core-swagger-project_2.9.1-1.3.0-RC1/samples
....
I get also this errors in Problems tab:
'/home/scorpio/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-java-sample-app_2.9.1' cannot be read or is not a valid ZIP file swagger-java-sample-app_2.9.1 Build path Build Path Problem
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.1.0:add-source (execution: default, phase: initialize) pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.1.0:testCompile (execution: default, phase: test-compile) pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
-------
pom file:
<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">
<parent>
<groupId>com.wordnik</groupId>
<artifactId>swagger-project_2.9.1</artifactId>
<version>1.3.0-RC1</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>swagger-java-sample-app_2.9.1</artifactId>
<packaging>war</packaging>
<name>swagger-java-jaxrs-app</name>
<version>1.3.0-RC1</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<webAppConfig>
<contextPath>/api</contextPath>
</webAppConfig>
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8002</port>
<maxIdleTime>60000</maxIdleTime>
<confidentialPort>8443</confidentialPort>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.9.1</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.1</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
</dependencies>
</project>
Could someone give some extra info so that i can go on?
Thx
There are multiple issues according to your logs
2013-12-25 20:32:56.168:WARN:oejw.WebAppContext:Failed startup of context o.m.j.p.JettyWebAppContext{/api,file:/home/scorpio/Downloads/swagger-core-swagger-project_2.9.1-1.3.0-RC1/samples/java-jaxrs/target/swagger-java-sample-app_2.9.1-1.3.0-RC1/},file:/home/scorpio/Downloads/swagger-core-swagger-project_2.9.1-1.3.0-RC1/samples/java-jaxrs/target/swagger-java-sample-app_2.9.1-1.3.0-RC1/
java.util.zip.ZipException: invalid entry size (expected 6164 but got 4968 bytes)
This simply means that th ZIP file is invalid/improper. Either it was not creates properly or an inturrupt occured during download. I would recommend deleting the file and re-creating/re-donwloading it
'/home/scorpio/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-java-sample-app_2.9.1' cannot be read or is not a valid ZIP file swagger-java-sample-app_2.9.1 Build path Build Path Problem
Delete this file and re-acquire it
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.1.0:add-source (execution: default, phase: initialize) pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.1.0:testCompile (execution: default, phase: test-compile) pom.xml /swagger-java-sample-app_2.9.1 line 2 Maven Project Build Lifecycle Mapping Problem
All these errors points to one things, the limitation of the m2e eclipse plugin. There are certain plugin goals that are not covered by m2e plugin. THeres nothing much that you can do about it except make sure to verify that the wars are made properly with each build.

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

The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found

I hit into deployment error for Jboss AS 7.1.1 Final deployment as mentioned at Could not connect to remote://localhost:9999. The connection timed out Jboss 7.1.1 Final. I am trying to use latest version of Jboss Maven plugin '7.4.Final' from '7.1.1.Final'. When I made change in POM configuration I am getting following error for both versions of plug-in. I have confirmed that my .m2 has both of these plug-in versions available.
Is POM meta data corrupt in my case, if so how do I clean it up to get it working?
[INFO] Searching repository for plugin with prefix: 'jboss-as'.
[DEBUG] Loading plugin prefixes from group: org.apache.maven.plugins
[DEBUG] Loading plugin prefixes from group: org.codehaus.mojo
[DEBUG] maven-jboss-as-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the latest version
org.apache.maven.plugins:maven-jboss-as-plugin:pom:LATEST
[DEBUG] Using defaults for missing POM org.apache.maven.plugins:maven-jboss-as-plugin:pom:LATEST
[DEBUG] maven-jboss-as-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the release version
org.apache.maven.plugins:maven-jboss-as-plugin:pom:RELEASE
[DEBUG] Using defaults for missing POM org.apache.maven.plugins:maven-jboss-as-plugin:pom:RELEASE
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1851)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
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.version.PluginVersionNotFoundException: The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid version could be found
at org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePluginVersion(DefaultPluginVersionManager.java:229)
at org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePluginVersion(DefaultPluginVersionManager.java:91)
at org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPluginManager.java:179)
at org.apache.maven.plugin.DefaultPluginManager.loadPluginDescriptor(DefaultPluginManager.java:1642)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1540)
... 15 more
UPDATE
POM.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- continue build even test fails -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<configuration>
<filename>${project.build.finalName}.jar</filename>
<username>${userName}</username>
<password>${password}</password>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
The stack trace show us as
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin'
does not exist or no valid version could be found
[INFO] ------------------------------------------------------------------------
It should be org.jboss.as.plugins:jboss-as-maven-plugin instead.
The JBoss Application Server 7: Plugin Documentation told us to configure as the following: -
<project>
...
<build>
<!-- To define the plugin version in your parent POM -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
...
</plugins>
</pluginManagement>
<!-- To use the plugin goals in your POM or parent POM -->
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
...
</plugins>
</build>
...
</project>
Please review and ensure that the plugin org.jboss.as.plugins:boss-as-maven-plugin is under the <build> in your pom.xml.
I hope this may help.
I was facing similar issue. This issue was due to older version of maven2.2.1.
When moved to newer version3.x of maven it worked.

Errors using Maven Mojo sql:execute

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.