How do I add an additional directory based context to a tomcat:run configuration?
I have the following jetty plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextHandlers>
<contextHandler implementation="org.mortbay.jetty.handler.ContextHandler">
<contextPath>/media/data</contextPath>
<resourceBase>/somedir/media/data</resourceBase>
<handler implementation="org.mortbay.jetty.handler.ResourceHandler" />
</contextHandler>
</contextHandlers>
<contextPath>/</contextPath>
<webAppSourceDirectory>foo-project/target/foo-webapp</webAppSourceDirectory>
...
</configuration>
</plugin>
</plugins>
...
</build>
How do I do this with tomcat:run?
I have a context.xml file in the tomcatconf dir
<?xml version='1.0' encoding='utf-8'?>
<Context path="/media" docBase="/somedir/media"/>
but this seems to get ignored.
I've also tried to explicitly set the contextFile parameter in the plugin configuration, but to no avail.
Reference:
http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html
have a look at the deployment description of the tomcat plugin.
Place the context.xml file to the default location
src/main/webapp/META-INF/context.xml
or use tomcat:run with a contextFile property on the commandline
mvn tomcat:run -DcontextFile="<path-to-your-context.xml-file>"
Related
I want to read Liquibase change log properties from an external property file. I do not want to define them in the databasechangelog.xml in property tag as I want different parameters for different environments. My external property file will be chosen according to the profile I chose for the maven plugin.
E.g. CREATE OR REPLACE SYNONYM ${schema1}.myTable FOR ${schema2}.myTable;
I want these parameters ${schema1} and ${schema2} to picked from an property file. Is this possible
Edit: According to #bilak comment I tried this
pom.xml:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<propertyFile>${basedir}/../environments/${build.profile.id}/liquibase.properties</propertyFile>
<changeLogFile>${basedir}/src/main/resources/sql/db-changelog-master.xml</changeLogFile>
</configuration>
</plugin>
liquibase.properties:
driver=oracle.jdbc.OracleDriver<br>
url=xxxxx<br>
username=xxxxxx<br>
password=xxxxxx<br>
parameter.testcolumn=test_column
db config parameters are read correctly but parameter.testcolumn is not used
mvn liquibase:update -Pprofile
You can use file liquibase.properties (default name) and put there variables like:
parameter.schema1=yourSchema1
parameter.schema2=yourSchema2
edit:
That option doesn't work with liquibase-maven-plugin but there could be workaround with maven-exec-plugin:
<profiles>
<profile>
<id>liquibase</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>liquibase.integration.commandline.Main</argument>
<argument>--defaultsFile=src/main/resources/database/liquibase.properties</argument>
<argument>updateSQL</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
if you execute then mvn exec:exec -Pliquibase it should replace your placeholders with parameters from liquibase.properties.
edit 2019/07 Now you can use property file to load properties from
I am using jbosscc-seam-archtype 1.2 and I am putting the application.xml in EAR project, under /src/main/application/META-INF/ but the maven-ear-plugin is not picking it up. any suggestion?
Here is the snippet of my maven EAR plugin:
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>5</version>
<modules>
<webModule>
<groupId>com.***</groupId>
<artifactId>***-war</artifactId>
<contextRoot>***</contextRoot>
<unpack>${exploded.war.file}</unpack>
</webModule>
<jarModule>
<groupId>com.***</groupId>
<artifactId>***-datamodel</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
</jarModule>
<ejbModule>
<groupId>com.***</groupId>
<artifactId>***-bootstrap</artifactId>
<excluded>${exclude.bootstrap}</excluded>
</ejbModule>
<ejbModule>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
</ejbModule>
<jarModule>
<groupId>org.jboss.el</groupId>
<artifactId>jboss-el</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
</modules>
<jboss>
<version>${version.jboss.app}</version>
<loader-repository>***:app=ejb3</loader-repository>
</jboss>
</configuration>
</plugin>
What am I doing wrong?
By default, your application.xml will not be picked even if you include it in src/main/application/META-INF/application.xml in your maven ear project that's because it will be autogenerated by the configuration specified at <configuration> of the maven-ear-plugin. If you want yours to be included you need to change generateApplicationXml to false (defaults to true).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<version>6</version>
<displayName>MyEAR</displayName>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>com.test</groupId>
<artifactId>my-web</artifactId>
<bundleFileName>my-web.war</bundleFileName>
<contextRoot>/MyWeb</contextRoot>
</webModule>
</modules>
<generateApplicationXml>false</generateApplicationXml>
</configuration>
</plugin>
You can use <applicationXml>/your/location/</applicationXml> in <configuration> element to specify location of your custom application.xml file.
Please check if you really need custom application.xml file, otherwise use <generateApplicationXml>true</generateApplicationXml>.
i am learning tomcat basics and while i tried to deploy my web-application on tomcat i am getting the following error
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project struts2-demoapp: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/html/deploy?path=%2FmkyWebApp&war= -> [Help 1]
[ERROR]
as per this it seems war file location is not being passed to the tomcat manager.i have the following entries in my tomcat-user.xml
tomcat-users>
<user name="admin" password="admin" roles="admin,manager" /><!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>
here are the details of the pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
<url>http://localhost:8080/manager/html</url>
<server>myserver</server>
<path>/mkyWebApp</path>
</configuration>
</plugin>
</plugins>
</build>
in my setting.xml there are the entries
<server>
<id>Tomcat6.x</id>
<username>admin</username>
<password>admin</password>
</server>
i am not sure what exactly is going wrong here.any help in this regard will be helpful.
Change
<server>
<id>Tomcat6.x</id>
<username>admin</username>
<password>admin</password>
</server>
to
<server>
<id>myserver</id>
<username>admin</username>
<password>admin</password>
</server>
If you are using tomcat 7 use
<url>http://localhost:8080/manager/html</url>
If tomcat 6
<url>http://localhost:8080/manager</url>
start tomcat run tomcat7:deploy or tomcat6:deploy
You need to map the credentials from your settings.xml to the server configuration at your pom.xml.
In your case, this is done but setting the <id> element of your server, to match the server's host name from the pom.xml.
Since you are pointing localhost, the id must be also localhost.
When you change the hostname, you must also update settings.xml.
It's in the plugin configuration docs: the server/id tag in Maven settings must match the configuration/server value in your POM file, i.e. put <server>Tomcat6.x</server> in POM file.
There are some other minor issues with your tomcat-maven-plugin entry in the POM file:
you are missing the <version>1.1</version> tag,
the /html suffix in the Tomcat manager URL is unnecessary (cf. the default value for <url> tag).
When I was also running into this problem. My issue was using the older
<groupId>org.codehaus.mojo</groupId>
instead of using
<groupId>org.apache.tomcat.maven</groupId>
My setup is as follows
~/.m2/settings.xml
<settings>
<servers>
<server>
<id>localhost</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
pom.xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager</url>
<server>localhost</server>
<path>/myapppath</path>
</configuration>
</plugin>
tomcat/conf/tomcat-users.xml
<tomcat-users>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-script,tomcat,manager"/>
</tomcat-users>
I Advise you to use this plugin :
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.1.2</version>
It's very helpful with Tomcat7. I Have the same issue with mojo <groupId>org.codehaus.mojo</groupId>
but now, using Cargo plugin, the deploy run smooth as silk.
How can I specify the outputDirectory only for packaging a jar?
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html this shows all parameters, but how can I set them in the commandline or pom.xml?
on command line
-DoutputDirectory=<path>
and in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>/my/path</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
Parameter Expressions
About command line usage:
The parameter documentation specifies that the parameter is initialized to the value of the property ${project.build.directory} (which is the property referring to the target folder)
Here's what this means:
For mojos that are intended to be
executed directly from the CLI, their
parameters usually provide a means to
be configured via system properties
instead of a <configuration/> section
in the POM. The plugin documentation
for those parameters will list an
expression that denotes the system
properties for the configuration. In
the mojo above, the parameter url is
associated with the expression
${query.url}, meaning its value can be
specified by the system property
query.url as shown below:
mvn myquery:query -Dquery.url=http://maven.apache.org
Reference:
Guide to Configuring Plug-ins > Generic Configuration
Configuring ${project.build.directory}
However, ${project.build.directory} is not a system property, it's a property of the Project's Build object.
You can't set maven's internal properties directly on the command line, but you can get there with a little trick by adding placeholders in your pom.xml:
<build>
<directory>${dir}</directory>
</build>
Now, the output directory is set via the property from the command line (using -Ddir=somedirectory). Downside: now you always have to use the -Ddir parameter on the command line.
Using Profiles
But there's help here, too. Just use a profile when you want to configure the directory:
<profiles>
<profile>
<id>conf</id>
<build>
<directory>${dir}</directory>
</build>
</profile>
</profiles>
Now you can either do
# everything goes in someOtherDir instead of target
mvn clean install -Pconf -Ddir=someOtherDir
or plain old
# everything goes in target
mvn clean install
Configuring the Jar Plugin
Now if you just want to change the jar outputDirectory from the command line without redirecting everything from target, we'll modify the profile to configure the plugin from a command line property:
<profiles>
<profile>
<id>conf</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The usage is identical to above:
# everything goes in someOtherDir instead of target
mvn clean install -Pconf -Ddir=someOtherDir
Thanks #Sean Patrick Floyd for the excellent explanation.
Instead of creating a profile and using mvn always by -P switch, I'd like to use another way that making a default value of property ${dir}.
Just define ${dir}'s default value as ${project.build.directory}
<properties>
<dir>${project.build.directory}</dir>
</properties>
and same as #Sean Patrick Floyd, set outputDirectory.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}</outputDirectory>
</configuration>
</plugin>
</plugins>
Now you can either do
# everything goes in someOtherDir instead of target
mvn clean install -Ddir=someOtherDir
or plain old
# everything goes in target
mvn clean install
If you wish copy dependency jars as well to a target folder, use maven-dependency-plugin.
<project>
...
...
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I'm want to have the war file deployed in the server deploy directory (or any directory of my choice) along with the one deployed in the repository. Also, can I control the name of the war file deployed like, I don't want the war file to be projectname-1.0.war I just want the name of the war file be projectname.war.
Thanks,
Ravi
Thanks guys,
I got it working. here is what I did.
I added this in my pom.xml file
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>mavenproject1</warName>
<outputDirectory>C:\jboss-5.1.0.GA\server\default\deploy</outputDirectory>
</configuration>
</plugin>
</plugins>
This solved both my naming and placing the war file.
Ravi
A first option would be to use the JBoss Maven Plugin that allows to start/stop JBoss and deploy/undeploy applications via JMX.
Your configuration must set the location to your JBoss Home directory. This can be done by setting the home directory with the jbossHome tag in the plugin configuration:
<project>
...
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<configuration>
<jbossHome>C:/jboss-5.1.0.GA</jbossHome>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
Then, just use one of the goal defined here, like:
$ mvn jboss:deploy
Another option would be to use the Cargo Maven Plugin. Below an example of plugin configuration that you could add to your war project:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>jboss5x</containerId>
<home>C:/jboss-5.1.0.GA</home>
</container>
<configuration>
<type>existing</type>
<properties>
...
</properties>
</configuration>
</configuration>
<plugin>
Then, to deploy a "deployable" (here, your war) to a running container:
$ mvn cargo:deploy
'Deployment' may sound very technical but its just copying file to the deployment directory. In some cases you may have to restart the server.
To change what it deploys the file as, use the tag in the build section of your pom.xml to specify the package name.
http://maven.apache.org/plugins/maven-jar-plugin/sign-mojo.html