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>.
Related
I have a selenium project separated from the web project.
I would like to use the Failsafe Maven plugin, but I am not sure if I can point in suiteXmlFiles label to the testng.xml file from another project. I would appreciate if anyone could help me.
<?xml version="1.0" encoding="UTF-8"?>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
</plugins>
I have a multimodule maven project, and I want to use it with tomcat7 maven plugin and start it with:
mvn tomcat7:run
But I can't figure out how to configure a jndi datasource.
I've tried to put in my pom.xml:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
</plugin>
and in the context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/AppealDS" url="jdbc:hsqldb:file:database/appeal"
driverClassName="org.hsqldb.jdbcDriver" username="appeal"
password="appeal" auth="Container" type="javax.sql.DataSource"
maxActive="3" maxIdle="2" maxWait="10000" />
</Context>
But it doesn't work...How can I register the jndi datasource?
What is the error message?
Use:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
</plugin>
Maybe your jdbc driver is not available in the classpath?
Try adding him in the plugin dependency
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
<dependencies>
<dependency>
here your hsql version
</dependency>
</dependencies>
</plugin>
I need to produce a simple app for my customer configure and run at their site. I am using the Spring framework, so I have a number of config files that must be on the class path. I am using Maven2 with Netbeans as my IDE.
I am able to create and run my app using Netbeans/Maven and I am using the Application Assembler Maven plugin to generate the runnable application. All this works fine except that my Spring config files have to be placed in src/main/resources which means that they get packaged into the resulting JAR file.
I need my customer to be able to modify the config files to do their testing, but it's not reasonable to ask them to modify the copies that are packaged in the JAR.
There are perhaps a number of solutions, but it seems to me that the simplest would be to get Maven to not package the app and the config files into a JAR at all, just leaving them in something like a classes directory from which they can be run. This would allow the user to modify the config files easily. Unfortunately I can't figure out how to get Maven to "package" the app in this manner, or how to get the AppAssembler to generate the resulting runnable.
Here is an extract of my pom.xml that may help illustrate what I am trying to do:
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
... stuff deleted ...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<!-- Set the target configuration directory to be used in the bin scripts -->
<configurationDirectory>conf</configurationDirectory>
<!-- Copy the contents from "/src/main/config" to the target
configuration directory in the assembled application -->
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<!-- Include the target configuration directory in the beginning of
the classpath declaration in the bin scripts -->
<includeConfigurationDirectoryInClasspath>
true
</includeConfigurationDirectoryInClasspath>
<platforms>
<platform>windows</platform>
</platforms>
<programs>
<program>
<mainClass>org.my.path.App</mainClass>
<name>app</name>
</program>
</programs>
</configuration>
</plugin>
</plugins>
</build>
...
Neither single packed jar file or bunch of unpacked classes files are good format for professional client delivery. Look at those brilliant apache apps like tomcat, ant and maven, they are shipped as a tar.gz or zip file, after download, simply extract them and you will get a nice and clean directory structure:
conf --> put config file like *.properties, logback.xml here
doc --> readme.txt, userguide.doc etc
lib --> put you core.jar with dependency jar file here
run.bat --> run script for Windows
run.sh --> run script for Unix
We can do these kinds of stuff with Maven as well. Note that you should design and implement your core jar to read *.properties from the conf directory properly. then use maven-assembly-plugin pack you app into this classical directory structure.
Sample pom.xml for a command-line app:
<!-- Pack executable jar, dependencies and other resource into tar.gz -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>attached</goal></goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/binary-deployment.xml</descriptor>
</descriptors>
</configuration>
</plugin>
Sample binary-deployment.xml for a command-line app:
<!--
release package directory structure:
*.tar.gz
conf
*.xml
*.properties
lib
application jar
third party jar dependencies
run.sh
run.bat
-->
<assembly>
<id>bin</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/java</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/bin</directory>
<outputDirectory></outputDirectory>
<filtered>true</filtered>
<fileMode>755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/doc</directory>
<outputDirectory>doc</outputDirectory>
<filtered>true</filtered>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
If not misleading, I think you want to let the jar and config to be separated, with jar exposed for client's testing.
The following can do this for you using copy-maven-plugin, it can accomplish almost tasks what assembly-plugin would do ,ex: copy, dependency and much more - download, upload ,move ,... .
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<resources>
<!--copy your scripts to ${myOutPutPath}/bin-->
<resource>
<targetPath>${myOutPutPath}/bin</targetPath>
<directory>${project.basedir}/src/main/scripts</directory>
<includes>
<include>*</include>
</includes>
</resource>
<resource>
<!--copy your configs-->
<targetPath>${myOutPutPath}/conf</targetPath>
<directory>${project.basedir}/src/main/config</directory>
<include>*</include>
</resource>
</resources>
</configuration>
</plugin>
Package main jar and put to your ${myOutPutPath}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<!-- The configuration of the plugin -->
<configuration>
<outputDirectory>${myOutPutPath}</outputDirectory>
<!-- Configuration of the archiver -->
<archive>
<!-- Manifest specific configuration -->
<manifest>
<!-- Classpath is added to the manifest of the created jar file. -->
<addClasspath>true</addClasspath>
<!--
Configures the classpath prefix. This configuration option is
used to specify that all needed libraries are found under lib/
directory.
-->
<classpathPrefix>lib/</classpathPrefix>
<!-- Specifies the main class of the application -->
<mainClass>com.xinguard.snmp.SNMP_ETL</mainClass>
</manifest>
<!-- you need to add some classpath by yourself, like conf here for client to use-->
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
then package the lib jar to lib directory under jar directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${myOutPutPath}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
With Maven 3, the site plugin has changed regarding reporting.
In the maven 2, the reporting section had the an "inherited" element. For example:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.plugin.version}</version>
<configuration>
<useFile>false</useFile>
</configuration>
<inherited>true</inherited>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Does report plugin inheritance exist in Maven 3? So in maven 3 what is the inheritance behavior for reportPlugins and is there any way to change this behavior like the maven 2 inherited element?
Secondly, does the section have any affect on plugin configurations in the reportPlugins under the site plugin? Or do configurations have to be duplicated in pluginManagement & reportPlugins sections? Does any of this configuration also have to be duplicated in submodules?
At the end of the day I'd like to do something like the following in Maven 3:
<!-- in parent pom -->
<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.plugin.version}</version>
<configuration>
<useFile>false</useFile>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- no version num or config - specified in pluginManagement section -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- no version num, config, or report set - specified in pluginManagement section -->
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<!-- in sub module pom -->
<!-- specify nothing - already in parent pom-->
And I would like all of these configurations to be inherited to submodules. Even the reportPlugins section.
Is any/all of this possible with maven 3 currently?
It looks like this may not be completely possible.
Refer to this issue in the maven-site-plugin.
It is supposedly now working just like you wanted back then,
since Maven 3.5, released in 2017.
I share a config file between several modules and I don't want the config file to be baked into any of the JARs.
How can i make Maven do (resource) filtering on the file which is not specified as a resource but is in a config folder on the same level as the root POM?
You could use the Maven Resources Plugin and its resources:copy-resources mojo. From the Examples:
Copy Resources
You can use the mojo copy-resources to
copy resources which are not in the
default maven layout or not declared
in the build/resources element and
attach it to a phase
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
Another option would be to use the Maven AntRun Plugin and Ant filtering capabilities (e.g. with the Filter and/or the Copy tasks) but the above looks just fine.