Sencha cmd build : specify 2 --destinations - maven

I am calling the following as part of a Maven build to generate my ExtJS project resources
sencha app build --destination "some path"
There is a requirement to copy the generated resource files into 2 locations within the project. Ideally I could specify 2 paths like this
sencha app build --destination "first path" "second path"
This is not working nor is specifying the --destination argument before each path.
I could use a symlink to copy contents of first path into second but this could get complicated when working on branches where the symlink is not defined.
I looked into the Maven resources plugin: copy-resources but it starts copying the files before the Sencha build has finished. How can I make this plugin wait until the build has finished ?
Any other suggestions welcome

I managed to achieve this by changing the phase element value to 'package'. It now waits until the sencha build is complete before copying resources
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-appCtx</id>
**<phase>package</phase>**
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/othersrc/</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

Related

Use JVM Options in Maven Plugin to get rid of relative path dependency

I've got a project A which consists of several modules. This is the "product" itself (server/client application). Furthermore there is another project B which is a specific customer project.
When the client+server *.jar of project A are assembled, resources of project B need to be integrated. I.e. copied into a resource folder.
I'm using the maven-resources-plugin to copy some of the property files:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>../../commonDashboard/src/main/resources/</directory>
<includes>
<include>commonDashboard.*.properties</include>
<include>db.*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This approach requires a relative dependency between both projects. I want to get rid of the relative path and use a path definition which is provided as VM Options in IntelliJ. So when running the assembly modules I need to access the VM options. I'm not quite sure if this is possible at all. I guess it's not, right? Do you know any other approach to get rid of this dependency between both projects? I don't want to add the options into the maven assembly file itself.

Maven 2.2.1: [Warning] JAR will be empty - no content was marked for inclusion

Maven 2.2.1
JDK - 1.6.0_45
[WARNING] JAR will be empty - no content was marked for inclusion!
BUILD SUCCESSFUL
But build creates jar with pom.xml but no class files.
On the maven source code this exception is thrown only when source directory is not found.
The build is working for all other developers except on my workstation and one more workstation
I have tried all the solutions provided for this issue on stack overflow.
My source directory is src/java.
I also created src/main/java as source still no result.
I am calling mvn -o jar:jar && call mvn -o antrun:run
-o is becuase at this point I am testing with some old jars.
<build>
<sourceDirectory>src/java</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<optimize>false</optimize>
<showDeprecation>true</showDeprecation>
<source>1.5</source>
<target>1.5 </target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>test*/temp/*.java</exclude>
<exclude>test*/support/*.java</exclude>
<exclude>test*/debug/*.java</exclude>
</excludes>
<includes>
<include>test*/**/AllTests.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>default-cli</id>
<phase>install</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${artifactId}-${version}.jar"
todir="${user.home}/.m2/repository/${groupId}/${artifactId}/${version}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
First follow the conventions in Maven which means your production sources code should be in src/main/java. You should also locate your resources like property files or other kind of files (like xml files) in your case to the proper location which is for production src/main/resources and for unit tests src/test/resources.
The first thing you should change is the directory structure for your project in the process in migration. That will save many hassles with configurations in Maven cause you are violating the convention over configuration paradigm.
Your unit tests code in src/test/java and follow the naming conventions for unit tests which means name your unit tests like *Test.java nothing more. You don't need to define a suite to run all the tests. If you follow the naming convention maven-surefire-plugin will do all the work for you.
Remove the antrun plugin from your pom configuration and use
mvn install
instead to install your produced jar into local repository. Based on the build life cycle you will compile, unit test and package your code into resulting jar files.
Usually in Maven there is no reason to call mvn jar:jar separately.
Apart from that all you should stop using Maven 2.2.1 cause it has defined End Of Life. Better start with Maven 3.X instead. But everything i wrote before is valid Maven 3.
I got Build Success but same error:
JAR will be empty - no content was marked for inclusion.
It was a test project and I realized that I had no "main" under "src". As soon as I corrected this, it was fixed. I am adding the wrong and right structure screenshots in the attachments:
right structure
wrong structure - missing main folder

How to hot deploy JSP changes in maven app?

I have a maven web application. I am using springsource tool suite and its built in tc fabric server.
Every time I make any changes I have to do mvn clean install and restart the server. Even for the JSP changes.
Is there any way I can just make JSP changes and they are reflected in the browser on refresh like a regular web app (not maven app).
I have searched over internet but no success as yet.
Still No clue about it. It makes the development process extremely slow. I looked into jrebel but its not free and I am not looking for hot deploy of classes but just the hot deploy of JSP's, javascripts, css etc.
I currently use a profile to copy JSPs to my target dir, which I call from Eclipse once i need the JSPs updated.
You could also copy classfiles like this by adding executions.
<profile>
<id>copyJsps</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<outputDirectory>${basedir}/target/app/WEB-INF/jsp</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/jsp</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Use: mvn resources:copy-resources -PcopyJsps
You can use Eclipse Filesync plugin to achieve this. You can configure plugin to map maven output folder to Application server directory
I know this is not maven way but it works.
Maybe this question will give some more insights.
This is my simple solution (workaround?) while using JBoss on Linux. It should also be valid for Tomcat or any other container that supports exploaded war's.
1. Use mvn war:inplace to create an exploaded war in src/main/webapp.
This will copy classes and lib there. You don't need to repeat this step if you're just changing JSP (or other /webapp/ files).
Alternatively you can create symlinks to classes and lib in src/main/webapp/WEB-INF:
cd src/main/webapp/WEB-INF
ln -s ../../../../target/classes
mvn package
ln -s ../../../../target/*/WEB-INF/lib
2. In the deployment directory create a symlink to src/main/webapp:
cd $DEPLOYMEN_DIR
ln -s $MYAPP_DIR/src/main/webapp myapp.war
This makes changes to JSP and other webapp files instantly available.
If you want to see the changes in your classes then you can trigger a reload of the application only my modifying web.xml. On you can run this script to monitor trigger the restart:
#!/bin/bash
while sleep 1; do
if [[ -n $(find WEB-INF/classes -newer WEB-INF/web.xml -type f) ]];then
date
touch WEB-INF/web.xml
fi
done
Run it from the src/main/webapp/ directory.
Note on JBoss AS 7: Here to trigger a reload you need to create a myapp.war.dodeploy file instead of touching web.xml
You can clean and copy the static files easy with the clean and resources plugins, but it won't work for the JSP files always. If the java source in the JSP files being copied introduces a new dependency you are not going to copy it to the lib folder. In that case, the app will break with a ClassNotFoundException.
Even if it is copied it can still break because the server has to be configured to scan the folder with dependencies and refresh the classpath. And that is the start of hot deployment I believe (details).
Try with Vinay's suggestion also. Judging by his answer it seems that the tc server supports scanning of dependencies by default, and with proper maven build this might be a satisfying solution.
To clean and copy the static files from your source directory to where it is deployed:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>clean-loaded</id>
<phase>compile</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${path.server.input}</directory>
<followSymlinks>false</followSymlinks>
<useDefaultExcludes>false</useDefaultExcludes>
<includes>
<include>**/*.jsp</include>
<include>**/*.js</include>
<include>**/*.html</include>
<include>**/*.css</include>
<include>**/*.png</include>
<include>**/*.gif</include>
<include>**/*.jpg</include>
<include>**/*.jpeg</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-compile-output</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${path.server.input}</outputDirectory>
<overwrite>true</overwrite>
<includeEmptyDirs>true</includeEmptyDirs>
<filtering>true</filtering>
<resources>
<resource>
<directory>${path.jsp.source}</directory>
<targetPath>${path.element.jsp.deploy}</targetPath>
<includes>
<include>**/*.jsp</include>
</includes>
</resource>
<resource>
<directory>${path.static.source}</directory>
<targetPath>${path.element.static.deploy}</targetPath>
<includes>
<include>**/*.js</include>
<include>**/*.html</include>
<include>**/*.css</include>
<include>**/*.png</include>
<include>**/*.gif</include>
<include>**/*.jpg</include>
<include>**/*.jpeg</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
add this to your properties section:
<path.server.input>ABSOLUTE_PATH_TO_DEPLOYED_WEBAPP_ROOT</path.server.input>
<path.jsp.source>ABSOLUTE_PATH_TO_JSP_SOURCE_ROOT</path.jsp.source>
<path.static.source>ABSOLUTE_PATH_TO_STATIC_SOURCE_ROOT</path.static.source>
<path.element.jsp.deploy>REALTIVE_PATH_TO_JSP_DEPLOY_ROOT</path.element.jsp.deploy>
<path.element.static.deploy>REALTIVE_PATH_TO_STATIC_DEPLOY_ROOT</path.element.static.deploy>
Properties that start with path must be absolute paths or start with a ${project.basedir} or similar. Properties that start with path.element are relative paths meaning that they must not be prepended with a / or start with another property that is an absoulte path. That is so because resources plugin copies in outputDirectory/targetPath (resources:copy-resources,
resource)
In my experience, IDE's usually bind their clean-and-build UI action to the compile phase. Also IDE's usually have a way to map a shell command or maven custom goal to be visible from it's UI menu.
To run with clean-and-build
The plugins are already bound to the compile phase. To ensure that clean plugin will run before resources plugin at the end of the compile phase, place them together at the end of your plugins section. It doesn't matter if a plugin is defined twice, just make sure that when reading the pom from top, the first clean plugin definition comes before the first resources plugin definition.
To run as separate action
Change under the execution tag for both like this:
<id>default-cli</id>
<phase>never</phase>
and now it won't be run in compile phase but by invoking from command line:
mvn clean:clean resources:copy-resources
In this case the placement of plugin definitions in pom is irrelevant, since you are defining their order with command arguments order. If this suits you your IDE most probably has a way to map this command as a custom goal visible from it's UI menu.
In both cases, I recommend backing-up the project folder when running for the first time.

how to assemble external artifacts into one global directory with the maven-assembly-plugin (or otherwise)

I am experimenting with Maven and I am trying to mavenize a project originally build with shell scripts.
With the Maven rule-of-thumb: one project, one artifact, I created the following structure:
<PROJECT>
<MODULE-1>
<MODULE-2>
<MODULE-3>
..
<MODULE-N>
<RESOURCES>
<DISTRIB>
The RESOURCES module is structured as follows:
<RESOURCES>/src/main/resources/<MODULE-1>/bin
<RESOURCES>/src/main/resources/<MODULE-1>/lib
<RESOURCES>/src/main/resources/<MODULE-1>/doc
<RESOURCES>/src/main/resources/<MODULE-2>/bin
<RESOURCES>/src/main/resources/<MODULE-2>/lib
<RESOURCES>/src/main/resources/<MODULE-2>/doc
...
<RESOURCES>/src/main/resources/<MODULE-N>/bin
<RESOURCES>/src/main/resources/<MODULE-N>/lib
<RESOURCES>/src/main/resources/<MODULE-N>/doc
The reason for doing it this way was that the resources above are needed at runtime, not compile-time and they are mostly property files, config files and shell scripts to invoke the various jar-files. For the final resources step, I wanted to combine the subdirectories into one global bin/lib/doc directory. However, I do not see an option in the assembly descriptor to strip of the prefix of the modules to get to what I want:
<RESOURCES>/target/resources/bin
<RESOURCES>/target/resources/lib
<RESOURCES>/target/resources/doc
where bin would contain all the files found in the /src/main/resources//bin directory, /src/main/resources//bin directory etc. Similarly for lib, doc.
My question: should I have a:
<MODULE-1>/src/external/resources/bin
<MODULE-1>/src/external/resources/lib
<MODULE-1>/src/external/resources/doc
...
<MODULE-N>/src/external/resources/bin
<MODULE-N>/src/external/resources/lib
<MODULE-N>/src/external/resources/doc
structure instead, that I would then access through a dependency-set? These files should not be part of the jar-file of the various modules and therefore cannot be stored in src/main/resources of their respective projects. Or is what I want to achieve doable by using some other maven plugin instead?
In the DISTRIB module I would combine the output of the RESOURCES module with the JAR-files and dependencies to create a directory structure that would then be used with a packaging tool (Solaris package and WiX installer).
Any help would be appreciated!
In the pom fort he resources module set the source directory to something other than /src/main/resources/ so that it does not copy them to the target folder. Then use the Maven Resources Plugin to copy the resource files to target/bin and target lib etc.
e.g.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/bin/</outputDirectory>
<resources>
<resource>
<directory>src/external/resources/bin</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/lib/</outputDirectory>
<resources>
<resource>
<directory>src/external/resources/lib</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>`

Full search and replace of strings in source files when copying resources

I have some java source files that use a package prefix (they are emulating some JDK classes). I use these files with the prefix to run against some unit tests. If the tests pass I want to produce a jar that contains the source files but with the package prefix removed from all the java files.
I am using maven for builds. Does any one know of a way to do this? Essentially what I want is something like the resources plugin filtering feature, but that does proper search and replace (like: s/my.package.prefix.//g), rather than filtering on ${vars}.
You can also use
http://code.google.com/p/maven-replacer-plugin/
100% maven and doing exactly what you want and more
This can be solved with the antrun plugin. Firstly the sources need to be copied to the target directory, with:
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
...
</build>
Secondly you use the replace task of the antrun plugin to replace the files using the prepare package phase
<build>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<tasks>
<replace token= "my.package.prefix." value="" dir="target/classes">
<include name="**/*.java"/>
</replace>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
...
</build>
This will copy the source files to target/classes in the process-resources phase, do a search and replace on the files inplace in the target/classes directory in the prepare-package phase and finally they will jarred up in the package phase.

Resources