using JSBuilder2.jar in Maven2 Web Application - java

I have started playing with Maven2 and I'm attempting to port one of my projects from ant to maven. I have managed to build ear file, use jaxb and other bits, but there is one thing left I don't know how to approach.
I have WAR module, with ExtJS code, and I'm using JSBuilder to create and package the code nicely. This is done as ant task and looks like this:
<target name="-pre-compile" description="Building Frontend Libraries">
<java jar="web/lib/dev/JSBuilder2.jar" failonerror="true" fork="true" >
<arg line="--projectFile web/lib/dev/frontend.jsb2 --homeDir web/lib"/>
</java>
</target>
I am wondering what would be the 'maven' way to do this? Is there a way I can do it purely in maven (had a look at maven:exec plugin but is a bit confusing) or do I have to call ant from maven to achieve this?
Thanks

The exec-maven-plugin is the correct answer (though you want the java goal). You need to bind it to a lifecycle phase. Look at the usage page for an example. In your case, you'd need something like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>jsbuilder</id>
<goals>
<goal>java</goal>
</goals>
<phase>compile</phase>
<configuration>
<mainClass><!-- fill in from jar's META-INF/MANIFEST.MF --></mainClass>
<argument>--projectFile</argument>
<argument>web/lib/dev/frontend.jsb2</argument>
<argument>--homedir</argument>
<argument>web/lib</argument>
</configuration>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
</configuration>
<dependencies>
<!-- a bit nasty, would be better if jsbuilder2 available in a maven repo. -->
<dependency>
<groupId>com.extjs</groupId>
<artifactId>jsbuilder2</artifactId>
<version>2.0.0</version>
<scope>system</scope>
<systemPath>web/lib/dev/JSBuilder2.jar</systemPath>
</dependency>
</dependencies>
</plugin>
If you're a big user of JSBuilder2, it'd be worth asking Cencha if they can release it to the maven central repo. Point them at OSS Repository Hosting.

Related

Versions Maven Plugin rules that are inheritable

When running mvn versions:display-dependency-updates for the Version Maven Plugin I see lots of things like this:
[INFO] org.slf4j:slf4j-api ........................... 1.7.36 -> 2.0.0-alpha7
But just because I'm not using the alpha version of a later version doesn't mean I'm not using the latest available release version. Another Stack Overflow answer indicated that I can set up a rules.xml file to ignore versions like *.-alpha*, putting something like this in my POM:
<configuration>
<rulesUri>file:///${project.basedir}/rules.xml</rulesUri>
</configuration>
My question: is this rules.xml file inheritable? If I put it in a separate project in a parent POM of <packaging>pom</packaging>, published to Maven Central, will the child POMs pick it up? Or will the child projects look for a rules.xml file in the child project directory?
I want to configure the versions-maven-plugin in the parent POM (as I do already) and run mvn versions:display-dependency-updates on any child POM or descendant POM. How can I set up the ignore rules in the parent POM so that these version ignore rules will be picked up when I check for dependency updates in a child POM? (Is there no way to include the rule within the POM itself?)
Or will the child projects look for a rules.xml file in the child project directory?
Yes, if you define the rules.xml file via ${project.basedir} it will resolve to the current local base directory of the child project. I've verified this with a simple parent-child pom setup. So that will not work, unless you duplicate the rules file in every project.
If you wish to include the plugin configuration and ruleset in the parent pom without duplicating the rules file, you have two options:
If you have your ruleset xml file hosted at, for example, http://www.mycompany.com/maven-version-rules.xml then the following configuration in your corporate pom would ensure that all projects use this rule set.
<configuration>
<rulesUri>http://www.mycompany.com/maven-version-rules.xml</rulesUri>
</configuration>
or
You can provide your ruleset xml file also within a jar, if you want to distribute your ruleset xml as Maven artifact. Therefore you have to declare the containing jar as direct dependency of the versions-maven-plugin and to use classpath as protocol.
<configuration>
<rulesUri>classpath:///package/foo/bar/rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>version-rules</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Source:
https://www.mojohaus.org/versions-maven-plugin/version-rules.html
The configuration in the pom only has rudimentary includes and excludes filters. Those will allow you to exclude any dependency as a whole, but not specific update versions. As far as i can tell from the available documentation there is no way to define version rules in any other way.
See
https://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html
Update 09-2022
In the github ticket we found in the comments we can see the following update:
It looks like a feature like this has recently been implemented by #369. Please see #318 where it's possible to provide inclusion and exclusion filters for determining which dependency patterns will be considered. Thanks to that, you can rule out patterns such as .*-beta. or .*_ALPHA, albeit not using regexp, but simple asterisk wildcards.
This will land in today's release (2.12.0).
This will add the following features:
Version 2.12.0 will introduce new arguments: dependencyIncluded, dependencyExcludes, dependencyManagementIncludes, dependencyManagementExcludes.
With the following example configuration in pom.xml given:
<profile>
<id>display-dependency-updates</id>
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
</goals>
<configuration>
<dependencyIncludes>org.apache.maven.*:doxia*</dependencyIncludes>
<dependencyManagementIncludes>com.puppy*:*</dependencyManagementIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
This will also be implemented for filtering plugin and pluginManagement, but that will probably be added in a later release:
So, I've just added the missing plugin- and plugin management filtering which works likewise. I really doubt it will land into today's release though.
Pasting my answer here from Github, because I think it might benefit others.
Provided you have a directory called rules-test in your project containing the rules template file:
<ruleset comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0
https://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<ignoreVersions>
<ignoreVersion type="regex">${ignoredVersions}</ignoreVersion>
</ignoreVersions>
</ruleset>
Then, in your main project, create the following profile:
<profile>
<id>rules-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>rules-test</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.12.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
</goals>
<configuration>
<rulesUri>file://${project.basedir}/compiled-rules.xml</rulesUri>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
If you then execute the following Maven target:
mvn -P rules-test "-DignoredVersions=.*-(M\d*|.*-SNAPSHOT)" clean validate
then you will get a dependencies report using the filter in the -DignoredVersions argument (filtering out both *-M* and *-SNAPSHOT).
And if you put your ignoredVerions property in your project instead of passing it as a -D argument, then it will be inheritable!

NoClassDef-s with Eclipse Jetty's Maven plugin, again

Please, someone help me, I'm desperate. I've been trying all night. The problem I have is this: Weird NoClassDef-s with Eclipse Jetty's Maven plugin
Basically: I can't make recent versions of the Jetty plug-in to work properly in an integration test. Indeed, everything works fine until the Jetty's shutdown stage, when I'm told that org.eclipse.jetty.util.FutureCallback is missing.
I've included the dependencies told in the link above. Initially they were ignored, then I've added them in project/build/extensions. Now I've several other ClassNotFoundExceptions and I can't fix that.
This is what I have in my POM:
<plugins>
<!-- This is activated before tests and uses the overlay import mechanism -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Triggers test data creation in uk.ac.ebi.fg.myequivalents.webservices.server.test.WebTestDataInitializer -->
<systemProperty>
<name>uk.ac.ebi.fg.myequivalents.test_flag</name>
<value>true</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<useTestScope>true</useTestScope>
<httpConnector>
<!-- 8080 is often busy on EBI hosts -->
<port>10973</port>
</httpConnector>
<stopPort>10974</stopPort>
<stopKey>KILL</stopKey>
</configuration>
<executions>
<!--
starts jetty before tests and stops it afterwards. Note that no stop goal is needed, it magically stops
after tests
-->
<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>
And these are the extesions I've set up:
<extensions>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaspi</artifactId>
<version>${jetty.version}</version>
</extension>
</extensions>
${jetty.version} is defined in the parent and = 9.1.3.v20140225, but I've tried many, down to 7.x
Moreover, Maven is 3.2.1, Java is 1.7.0_51, running on OS X 10.9.2
Thank you in advance for any help for this nasty issue.
I've found it!!! Apparently, the problem is the 'stop' goal is (rightly) attached to the 'post-integration-test' phase. So, if you issue 'mvn integration-test', such phase, as far as I understand, is not reached (http://tinyurl.com/omwulm5). By just giving 'mvn verify' or 'install', and without adding any Jetty-related dependency to the POM (everything needed should now be included in 9.1.x), Maven completed without any complaint (hooray!).
This might look silly to readers smarter than me, I'm reporting it nonetheless, just in case you're struggling as much as I've just done for hours.
You should not be using the "run" goal with an execution binding. Instead, you should be using the "start" goal. See the documentation here: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal
The difference is that the "run" goal will run a fresh build up until the "test-compile" phase. The "start" goal does not invoke a parallel build and simply runs at whatever phase it is bound to.
Jan
Just try to add <stopWait>10</stopWait> to plugin configuration.
Full configuration you can see in this answer.

getting parent directory of ${basedir} from maven

Is there way to get parent directory for ${basedir} in my pom.xml? Currently I have
<earSourceDirectory>${basedir}/EAR/src/main/resources</earSourceDirectory>
but I need to access parent directory of basedir as my resources lies in different maven project.
How can I get the parent folder of ${basedir}?
In the children:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
In the grandchildren:
<properties>
<main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>
${project.basedir}/../
However, access resources in a different module is something I try to avoid. I'd suggest using the unpack goal of the maven-dependency-plugin.
Please, don't try to go outside the basedir, because it's considered a very bad practice.
Even if you succeed now, it will be the start of a workaround over workaround, trying to battle Maven. In the end, Maven will win.
If a developer checks out a directory with a pom.xml, it should be able run the project with mvn verify without any references to other directories.
If these are shared resources, make it a separate project and include it as a dependency (search for multi module projects). Or use the maven-remote-resources-plugin to pull these resources into your project.
I had the requirement of moving zip generated in MainDirectory/Submodule/target/ to MainDirectory/target/.
I tried all solutions from everywhere but I was unable to solve. I finally tried Ant plugin in pom.xml of submodule to copy as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy to parent target</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="../target/" overwrite="true" flatten="true">
<fileset dir="${basedir}/target/"/>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>

Can and should a Maven POM specify if it requires Maven 3 or newer?

I am currently doing some cleanup of Java projects which use Maven, and use NetBeans IDE to 'debug' problems in the POM. I have set Maven 3.0.4 in the IDE as the Maven version, but other developers or our Continuous Intgeration system might have different settings.
Is it possible to 'enforce' a specific Maven version directly in the POM (for example by using a Maven 3 specific element)?
Yes you can and you should. Some Maven plugins requires Maven 3 or newer.
Use the maven-enforcer-plugin by adding the following to your pom.xml:
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-maven-3</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0.5</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Another option is to use the prerequisites element in the pom, for example:
<project>
...
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
...
</project>
As noted Michal Kalinowski's answer - this simple approach does not work so well for children projects.
For a summary of which approach will work best for you, see here: enforcing maven 3 - when to use maven enforcer plugin? when to use pom prerequisites element?
The best thing you can do is to use Enforcer plugin. Here's an example:
http://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
There is no out-of-the-box method in Maven itself for doing this. There is actually prerequisites tag but it doesn't work well, because children don't inherit it.

How to build an MSI using WIX, JAVA and MAVEN

I'm trying to build an Msi from a java application which is using the spring and maven frameworks. From all the reading up i have done it would seem Wix is the best option. With some further research i started seeing mention of a Wix Maven plugin. The problem is following the websites and what i should place into the pom I don't get the Jar file being found.
has anyone succeded in this or know where to find the jar file?
Below is the Wix maven information.
<plugin>
<groupId>npanday.plugin</groupId>
<artifactId>wix-maven-plugin</artifactId>
<version>${version}</version>
<configuration>
<sourceFiles>
<sourceFile>installer/Kiddo.wxs</sourceFile>
</sourceFiles>
<outputDirectory>target</outputDirectory>
<objectFiles>
<objectFile>target/Kiddo.wixobj</objectFile>
</objectFiles>
<outputFile>target/Kiddo.msi</outputFile>
</configuration>
<executions>
<execution>
<id>wix</id>
<goals>
<goal>candle</goal>
<goal>light</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>wix-maven-plugin</artifactId>
<version>1.4.0-incubating</version>
</dependency>
these are wrapped with the additional maven tags and
Nathan
Still a work in progress, but you might also be interested in a more fully featured WiX maven lifecycle. There is more than just candle and light.
com.github.wix-maven:wix-maven-plugin
sourced from github

Categories

Resources