Using a variable in Maven from the super pom - maven

I am giving myself a crash course in Maven and stumbled across a great plugin called buildnumber: http://www.mojohaus.org/buildnumber-maven-plugin/create-mojo.html
I have setup a VERY rudimentary, beginners project and in the pom.xml file I am successfully having the ${buildNumber} to interpolate.
I have the pom.xml below (I apologize for the length of it).
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<scm>
<connection>scm:git:ssh://git#bitbucket.org/XXXX/bb101repo.git</connection>
<developerConnection>scm:git:ssh://git#bitbucket.org/XXX/bb101repo.git</developerConnection>
<url>https://bitbucket.org/XXXX/bb101repo.git</url>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<shortRevisionLength>5</shortRevisionLength>
<!-- doCheck : Check for locally modified files. If true build will fail if local modifications have not been commited -->
<!-- doUpdate : Update the local copy of your repo. If true the plugin will update your local files with the remote modifications before building -->
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When I run mvn package, it works as intended.
I have another file in my project (under src) called info.xml and it's below.
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>FMS Help</display-name>
<version>${buildNumber}</version>
</web-app>
How do I get the ${buildNumber} to unpack in my tag under target?
I'm guessing it's a really simple solution, but I'm stumped. Again, I'm a complete n00b at Maven and any pointer in the right direction would be appreciated.
JW

You need to tell Maven to apply filtering to your resources. Check out the resources plugin documentation here:
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
To avoid applying filtering to all your source files, you'd either need to set up the proper include/exclude paths or move the info.xml file to the resources directory.

Related

Setting a custom icon on javafx application

I'm trying to build a native bundle on macos and add a custom icon instead of default java.
I put my 128x128 icns file in src/main/deploy/package/macosx, add javafx-maven-plugin in pom.xml and run command mvn jfx:build-native (or mvn jfx:native). And nothing happens. Meaning it is successfully built, but still uses default icon. What am I'm doing wrong?
Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>StarWars</groupId>
<artifactId>Minesweeper</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>example.minesweeper.Main</mainClass>
<application.title>${project.artifactId}</application.title>
<copyright>Han Solo</copyright>
</properties>
<organization>
<name>Star Wars</name>
</organization>
<name>Minesweeper</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>testfx-core</artifactId>
<version>4.0.6-alpha</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>testfx-junit</artifactId>
<version>4.0.6-alpha</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<vendor>AndreySerebryanskiy</vendor>
<mainClass>example.minesweeper.Main</mainClass>
<deployDir>${project.basedir}/src/main/deploy</deployDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
And here is a screenshot of my project structure.
By the way, I'm using IntelliJ IDEA 2017.1.4. I also have seen this range of questions:
JavaFX native bundle icon OS X
including an icon into a self-contained JavaFX application (.exe)
I also tried to put package/macosx in the project folder but it didn't work.
How to set custom icon for javafx native package icon on Windows
I also saw a simple way of accomplishing this task in NetBeansIDE (for example here). But I do not want to change IDE because of such simple issue.
Thank you in advance!
Edit 31.07
After turning verbose mode on I found that it was expecting Minesweeper-1.0.icns instead of Minesweeper.icns. Adding appName field in conficurations of javafx-maven-plugin solved my problem.
You will have to add to your javafx-maven-plugin configuration.
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<vendor>AndreySerebryanskiy</vendor>
<mainClass>example.minesweeper.Main</mainClass>
<deployDir>${project.basedir}/src/main/deploy</deployDir>
<verbose>true</verbose><!-- always a good idea to have this set to true while debugging -->
<appName>Minesweeper</appName>
</configuration>
</plugin>
Please make sure your ICNS-filename is the same as inside <appName>, then just call mvn jfx:native to have your application bundled.

How to package EAR for GlassFish with Maven?

I want to package one EAR that will be deployed on GlassFish Server Open Source Edition.
Here are the relevant parts of the pom.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
....
<packaging>ear</packaging>
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>/lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
I usually run mvn compile and mvn package in the command terminal. The resulting EAR has the following structure.
EAR/lib/*.jar
EAR/META-INF/application.xml
EAR/META-INF/META-INF.MF
EAR/META-INF/maven/...
The application.xml is
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>test-app</display-name>
<library-directory>/lib</library-directory>
</application>
If I try to run asadmin deploy test-app.ear to deploy the EAR to GlassFish I get this error.
remote failure: Error occurred during deployment: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 22; Deployment descriptor file META-INF/application.xml in archive ....
Here I rename application.xml to glassfish-application.xml and change its content to
<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Java EE Application 6.0//EN"
"http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
<unique-id>67488732739338240</unique-id>
</glassfish-application>
If I rerun asadmin deploy test-app.ear GlassFish recognizes the deployment descriptor but throws the next error that says Application [test-app] contains no valid components.
Here I move all jars from EAR/lib/*.jar to EAR/META-INF/lib/*.jar.
If I now rerun asadmin deploy test-app.ear GlassFish recognizes the EAR as valid and deploys it.
Since I dont want to manually change the EAR every time. How can I configure Maven to
1. Output a valid application.xml or glassfish-application.xml
2. Copy the dependencies not to EAR/lib/ but to EAR/META-INF/lib (if it is really necessary)
Thanks in advance.
How can I configure Maven to
Output a valid application.xml or glassfish-application.xml
Copy the dependencies not to EAR/lib/ but to EAR/META-INF/lib (if it is really necessary)
application.xml can be autogenerated by maven-ejb-plugin and for the simple test I would leave it up to plugin
for dependencies copying - it depends what you package in your ear (can be war/jar/...) but in general, it's a good idea, to let maven do it. For the purpose you miss in your pom.xml sections that would refer to modules (war/jar/...) you want to be included in there
moreover I don't see a reason for non-standard libs folder you specified with: <library-directory>
So I'd go for config like the sample present here.
To include the relevant sections in answer:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<modules>
<webModule>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<bundleFileName>myWarNameInTheEar.war</bundleFileName>
<contextRoot>/myWarConext</contextRoot>
</webModule>
<ejbModule>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<bundleFileName>myEjbNameInTheEar.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>My Ear Name displayed in the App Server</displayName>
<generateApplicationXml>true</generateApplicationXml>
</configuration>
</plugin>
</plugins>
</build>
<!-- Define the versions of your ear components here -->
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
Please note you need to specify dependencies - for modules, but include those in modules section as well, to have them packaged.
Feel free to ask in case of any further questions.

How to download spring framework zip file [duplicate]

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
SpringSource.org changed their site to http://spring.io
Does someone know how to get the latest build without Maven/github? from http://spring.io/projects
Please edit to keep this list of mirrors current
I found this maven repo where you could download from directly a zip file containing all the jars you need.
https://maven.springframework.org/release/org/springframework/spring/
https://repo.spring.io/release/org/springframework/spring/
Alternate solution: Maven
The solution I prefer is using Maven, it is easy and you don't have to download each jar alone. You can do it with the following steps:
Create an empty folder anywhere with any name you prefer, for example spring-source
Create a new file named pom.xml
Copy the xml below into this file
Open the spring-source folder in your console
Run mvn install
After download finished, you'll find spring jars in /spring-source/target/dependencies
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-source-download</groupId>
<artifactId>SpringDependencies</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>download-dependencies</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Also, if you need to download any other spring project, just copy the dependency configuration from its corresponding web page.
For example, if you want to download Spring Web Flow jars, go to its web page, and add its dependency configuration to the pom.xml dependencies, then run mvn install again.
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>

Getting Started with Maven + Jaxb project + IntellijIdea

I am complete new to IntellijIdea and i am looking for some step-by-step process to set up a basic project.
My project depends on Maven + Jaxb classes so i need a Maven project so that when i compile this project, the JAXB Objects are generated by Maven plugins. Now i started like this
I created a blank project say MaJa project
Added Maven Module to it
Added following settings in POM.XML
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MaJa</groupId>
<artifactId>MaJa</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resource/api/MaJa</schemaDirectory>
<packageName>com.rimt.shopping.api.web.ws.v1.model</packageName>
<outputDirectory>${build.directory}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
First of all, is it right settings ?
I tried clicking on Make/Compile 'MaJa' from Project > Right Click Menu and it didn't do anything.
I will be looking forward to yoru replies.
You must click not on Make/Compile 'MaJa'
1) You must choose one of maven Build Lifecycle phases here (not less then Compile).
2) Set path to maven in settings.
3) Add version for jaxb-api artifact
I add shiporder.xsd to directory /src/main/resource/api/MaJa and java classes were generated well
[jaxb2:xjc]
Generating source...
parsing a schema...
compiling a schema...
com\rim\shopping\api\web\ws\v1\model\ObjectFactory.java
com\rim\shopping\api\web\ws\v1\model\Shiporder.java

Maven descriptor (META-INF/maven) duplicate entry in archive

I'm facing a problem with maven build. I have several ejb projects. After maven build the jar-file contains the maven descriptor in META-INF/maven twice, i.e. if I extract files to disk 7zip asks to overwrite files although extracted to a new folder. If a specify <addMavenDescriptor>false</addMavenDescriptor> in the archive-tag of the ejb plugin then the maven decriptor is still generated but only once. Is there another place where I can disable maven descriptor generation or does anybody know the reason for the duplicate generation?
Maven version is: 3.0.3
Project structure is like:
-pom
-ejb
Here is the pom.xml of the EJB module:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>TestMavenDescriptors</artifactId>
<groupId>de.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>TestEJB</artifactId>
<packaging>ejb</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Here is the pom.xml of the parent project.
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.test</groupId>
<artifactId>TestMavenDescriptors</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>TestEJB</module>
</modules>
</project>
I found out that this is a problem special to eclipse version (I have RAD 8 trial) and possibily of the m2e plugin version. The above behavior (duplicate generation of maven descriptors) occurs only if I have the EJB project in my workspace added. That means if I remove the EJB project from workspace (without deleting contents on disk) such that only the hierarchal parent maven project (pom packaged) is existing in the workspace (which contains the EJB project but EJB project is then not known to eclipse) then everything works fine. Strange, isn't it?!
BTW: on current eclipse (java ee package) this doesn't occur, all fine there.

Resources