How do I make my archetype from a multimodule project use directories that are based on the artifactId? - build-process

I have create an archetype using archetype:create-from-project out of a multi module project.
The archetype-metadata.xml is like below, what I would want is that the "dir" can be modified when I run mvn archetype:generate by using the archetypeId I provide instead of using a fixed dir. Can that be done?
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="service-parent"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modules>
<module id="service-def" dir="service-def" name="service-def">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="service" dir="service" name="service">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.sql</include>
<include>**/*.dtd</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="service-web" dir="service-web" name="service-web">
<fileSets>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/webapp</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
</modules>
</archetype-descriptor>
This is the structure of the archetype:
├── pom.xml
└── src
├── main
│   └── resources
│   ├── archetype-resources
│   │   ├── pom.xml
│   │   ├── service
│   │   │   ├── pom.xml
│   │   │   └── src
│   │   │   ├── main
│   │   │   │   └── java
│   │   │   └── test
│   │   │   ├── java
│   │   │   └── resources
│   │   ├── service-def
│   │   │   ├── pom.xml
│   │   │   └── src
│   │   │   └── main
│   │   │   └── java
│   │   └── service-web
│   │   ├── pom.xml
│   │   └── src
│   │   └── main
│   │   ├── resources
│   │   │   ├── dao-context.xml
│   │   │   ├── hibernate.cfg.xml
│   │   │   └── single-context.xml
│   │   └── webapp
│   │   └── WEB-INF
│   │   ├── jboss-web.xml
│   │   ├── remoting-servlet.xml
│   │   └── web.xml
│   └── META-INF
│   └── maven
│   └── archetype-metadata.xml
└── test
└── resources
└── projects
└── basic
├── archetype.properties
└── goal.txt

You need to use the rootArtifactId placeholder such as :
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="service-parent"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modules>
<module id="${rootArtifactId}-def" dir="__rootArtifactId__-def" name="${rootArtifactId}-def">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}" dir="__rootArtifactId__" name="${rootArtifactId}">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.sql</include>
<include>**/*.dtd</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-web" dir="__rootArtifactId__-web" name="${rootArtifactId}-web">
<fileSets>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/webapp</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
</modules>
Rename your module folders using the __rootArtifactId__ prefix.
You can see an example of such archetype in http://code.google.com/p/open-archetypes/source/browse/multi-javaee5-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

Related

Error: Unable to initialize main class home.bank_application.BankAppRunner

I can't execute my jar of application. And I have that error:
Error: Unable to initialize main class home.bank_application.BankAppRunner
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
My plugins for jar in pom.xml:
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>home.bank_application.BankAppRunner</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>home.bank_application.BankAppRunner</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
When I build the project with "mvn clean intall" plugin "maven-assembly-plugin" doesn't install. I wish my project was built without all dependencies. How can I build my project with dependencies?

Create empty folder on Karaf / ODL / Opendaylight

I need to create an empty folder when installing a feature.
Any suggestion?
So far I tried something like(without success):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>empty-config-folder</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${project.build.directory}/assembly/etc/empty-folder" />
</target>
</configuration>
</execution>
</executions>
</plugin>
You can simply create the folder in Java code inside one of the bundles you install. See File.mkdirs()

Maven overwrites file with replaced string

I'm creating web-app with Java+Spring+FreeMarker, and, I want to write app version directly into FreeMarker template. I try using maven replacer plugin, but, when I create war package, file with replaced string (in target directory) becomes overriden with file with origin token.
Here is quote from pom.xml:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${basedir}\src\main\webapp\templates\include\version.ftl
</include>
</includes>
<outputFile>${basedir}\target\${project.build.finalName}\templates\include\version.ftl
</outputFile>
<replacements>
<replacement>
<token>version</token>
<value>${project.build.finalName}</value>
</replacement>
</replacements>
</configuration>
</plugin>
What I'm doing wrong?
I've found solution. Need to use prepare-package phase in war plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<useCache>true</useCache>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
<version>2.6</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>

Google closure compiler with Maven

I am trying to minify my JS file using google closure compiler
I used the following simple 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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx</groupId>
<artifactId>closurecompiler</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>closurecompiler Maven Webapp</name>
<url>http://maven.apache.org</url>
<build>
<finalName>closurecompilertest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler</artifactId>
<version>r1810</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>target/builddependency</outputDirectory>
<destFileName>closure-compiler.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.12</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>target/builddependency</outputDirectory>
<destFileName>args4j.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r07</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>target/builddependency</outputDirectory>
<destFileName>guava.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<echo
message="Minifying JS files. This takes a few minutes, please be patient" />
<apply executable="java" failOnError="true">
<arg line="-cp target/builddependency/args4j.jar;target/builddependency/guava.jar;target/builddependency/closure-compiler.jar com.google.javascript.jscomp.CommandLineRunner --compilation_level WHITESPACE_ONLY --charset UTF-8 --js " />
<fileset dir="src/main/webapp/js/" includes="*.js" />
<redirector>
<outputmapper id="out" type="glob" from="*.js" to="target/cc/*.js" />
</redirector>
</apply>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
i placed three js files in the source and when I check the output folder, i am getting empty files without any content
The same command works fine if run in command prompt.
any idea why i am getting empty file?

flexmojos:copy-flex-resources not copying resource files

Hi i had been setting up a flex project, its basically into 3 modules, a flex, a java and a war project. Am able to compile all, but the flexmojos:copy-flex-resources plugin only copies the ".swf" file into the webapp directory. There are other files like html wrapper which are skipped. Had anyone sort it out. Thanks!
My SWF POM
swf Application
<properties>
<path_to_services_config_xml>${basedir}/src/main/resources/services-config.xml</path_to_services_config_xml>
</properties>
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<directory>target</directory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<!-- <version>3.8</version> -->
<executions>
<execution>
<id>html-wrapper</id>
<goals>
<goal>wrapper</goal>
</goals>
<configuration>
<templateURI>folder:/html-template</templateURI>
<parameters>
<swf>${project.build.finalName}</swf>
<width>100%</width>
<height>100%</height>
<version_major>${flash.major}</version_major>
<version_minor>${flash.minor}</version_minor>
<version_revision>${flash.revision}</version_revision>
<bgcolor>#FFFFFF</bgcolor>
</parameters>
<htmlName>Main</htmlName>
<!-- <targetPlayer>${flash.major}.${flash.minor}.${flash.revision}</targetPlayer> -->
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.adobe.flex.compiler</groupId>
<artifactId>flex-compiler-oem</artifactId>
<version>4.5.1.21328</version>
</dependency>
</dependencies>
<extensions>true</extensions>
<configuration>
<debug>true</debug>
<!-- <output>target/bin/</output> <sourcePaths> <path>src/main</path>
</sourcePaths> Configuration to copy assets (Images) folder to target -->
<includeFileSets>
<fileset>
<directory>src/main/assets</directory>
<includes>
<include>*.*</include>
</includes>
</fileset>
</includeFileSets>
<!-- service-config.xml specification (path defined above) -->
<services>${path_to_services_config_xml}</services>
<!-- Context Root URL -->
<contextRoot>clv-web-0.3</contextRoot>
<localesCompiled>
<locale>en_US</locale>
<locale>fr_FR</locale>
</localesCompiled>
<localesSourcePath>${basedir}/src/main/locale/{locale}</localesSourcePath>
<!-- <localesSourcePath>${basedir}/src/main/locale/fr_FR</localesSourcePath> -->
<!-- <templateURI>${basedir}/html-template/</templateURI> <outputDir>target/flex-html</outputDir>
<htmlName>myindex.html</htmlName> <parameters> <swf>${build.finalName}</swf>
</parameters> -->
</configuration>
<!-- <executions> <execution> <goals> <goal>wrapper</goal> </goals> </execution>
</executions> -->
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>4.5.1.21328</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>0.85</version>
<type>swc</type>
<scope>test</scope>
</dependency>
and my war POM is
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>4.1-beta</version>
<extensions>true</extensions>
<executions>
<!-- <execution> <id>wrapper</id> <phase>generate-resources</phase>
<goals> <goal>wrapper</goal> </goals> <configuration> <wrapperArtifact> <groupId>com.cat.clv.swf</groupId>
<artifactId>clv-swf</artifactId> <version>0.3</version> </wrapperArtifact>
<htmlName>Main</htmlName> </configuration> </execution> -->
<execution>
<goals>
<goal>copy-flex-resources</goal>
</goals>
<configuration>
<webappDirectory>>${basedir}/src/main/webapp/demo</webappDirectory>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
</resource>
</webResources>
<debug>true</debug>
<!-- <warSourceExcludes>index.template.html</warSourceExcludes> <webResources>
<resource> <directory>target</directory> </resource> </webResources> -->
</configuration>
</plugin>
I am the guy who has officially taken over development of flexmojos.
The problem you are encountering might be related to some changes in flexmojos staring with 3.x (don't remember the version) I was having the same problems as you were. While searching for the reason I found out that flexmojos was having trouble determining the finalName from the projects pom because in some cases maven throws errors. As I was specifying the finalName myself I solved the problem by setting false in the copy-flex-resources configuration. Eventually this helps.
Another solution I had to use in a different project was to explicitly use an oder version of the copy-flex-resources mojo in my war project. 3.7.1 seems to be the last version without this problem.
Unfortunately I didn't manage to sort out this error yet, but it's still on my radar.
Chris
I had a very similar configuration issue with flexmojos-maven-plugin version 3.8 which I fixed by adding by warSourceDirectoryPath to the outputDirectory of the wrapper goal config in the swf project:
I defined a property:
warSourceDirectoryPath = ../workbench-server/src/main/webapp/flex
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<executions>
<execution>
<id>flex-ui-wrapper</id>
<phase>generate-resources</phase>
<goals>
<goal>wrapper</goal>
</goals>
<configuration>
<templateURI>folder:/html-template</templateURI>
<templateOutputDirectory>${project.build.directory}/templates</templateOutputDirectory>
<outputDirectory>${warSourceDirectoryPath}</outputDirectory>
<parameters>
<swf>${project.build.finalName}</swf>
<title>Workbench</title>
<application>myapp</application>
</parameters>
<htmlName>Workbench</htmlName>
</configuration>
</execution>
</executions>
<dependencies>
...
</dependencies>
<extensions>true</extensions>
<configuration>
<debug>true</debug>
<sourceFile>${basedir}/src/main/flex/Workbench.mxml</sourceFile>
<contextRoot>/workbench-server</contextRoot>
<generateHtmlWrapper>true</generateHtmlWrapper>
<targetPlayer>11.1.0</targetPlayer>
<!-- <services>generated-resources</services> this is the default -->
</configuration>
</plugin>
Hope that helps.

Resources