How to make Maven Clean Install build JavaFX8? - maven

Every time I try to run my JavaFX 8 project, I need to do a clean install with Maven then build project with eclipse. Doing only the clean install will result in an Exception.
How can I make the maven clean install and eclipse build execute in one command.
If I need to add it in my pom.xml, should I put it in my parent pom.xml or all in its children?
Thanks!

Finally got mine working, I just added this lines of code on my parent pom.xml.
<build>
<plugins>
<!-- This will copy all your dependencies to target/libs, which will be
picked up by the ant task below -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<includeScope>compile</includeScope>
<includeScope>runtime</includeScope>
<excludeArtifactIds>javafx</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-javafx-packages</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml" classpath="${javafx.tools.ant.jar}"/>
<fx:application id="fxApp" name="${project.name}" mainClass="${project.main.class}"/>
<!-- Note: this will overwrite the JAR produced by maven-jar-plugin,
change destfile if you don't want this -->
<fx:jar destfile="${project.build.directory}/../../${project.build.finalName}">
<fx:application refid="fxApp"/>
<fx:fileset dir="${project.build.directory}/../.." includes="target/classes"/>
<fx:resources>
<fx:fileset dir="${project.build.directory}/../.." includes="libs/*.jar"/>
</fx:resources>
</fx:jar>
<fx:deploy outdir="${project.build.directory}/../../javafx-output" outfile="${project.build.finalName}" nativeBundles="all">
<fx:application refid="fxApp"/>
<fx:resources>
<!-- If you changed <fx:jar> above, don't forget to modify the
line below -->
<fx:fileset dir="${project.build.directory}/../.." includes="${project.build.finalName}.jar"/>
<fx:fileset dir="${project.build.directory}/../.." includes="libs/*.jar"/>
</fx:resources>
</fx:deploy>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>${javafx.version}</version>
<scope>system</scope>
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
</dependency>
</dependencies>

Try doing the following
mvn clean install eclipse:clean eclipse:eclipse and then do a refresh on the project in eclipse.
HTH,
Keshava.

Related

Maven - Install Local Dependencies during package phase

I'm trying to add to my pom an Ant run task to install local dependencies before building the jar.
So i added in my pom this part
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Install Local Dependencies</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<echo message="Installing local lib" />
<exec executable="/usr/local/bin/mvn">
<arg value="-f ${lib.dir}/pom.xml clean install " />
</exec>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</plugin>
but it fails because it tries to launch mvn from the current directory.
Is there a proper way to install an external pom before building the main pom?

Perform deployment of an application on multiple servers through the same Jenkins Job

I'm using Jenkins CI to automate the deployment of my Java application, and I'm currently using the following build configurations on the pom.xml file:
<!-- teste1 config -->
<deploy.jboss.teste1.host>192.168.0.1</deploy.jboss.teste1.host>
<deploy.jboss.teste1.port>9999</deploy.jboss.teste1.port>
<deploy.jboss.teste1.user>admin</deploy.jboss.teste1.user>
<deploy.jboss.teste1.password>admin</deploy.jboss.teste1.password>
<liquibase.teste1.database>db_01</liquibase.teste1.database>
<liquibase.teste1.host>192.168.0.2</liquibase.teste1.host>
<liquibase.teste1.user>admin</liquibase.teste1.user>
<liquibase.teste1.password>admin</liquibase.teste1.password>
<!-- teste2 config -->
<deploy.jboss.teste2.host>192.168.0.3</deploy.jboss.teste2.host>
<deploy.jboss.teste2.port>9999</deploy.jboss.teste2.port>
<deploy.jboss.teste2.user>admin</deploy.jboss.teste2.user>
<deploy.jboss.teste2.password>admin</deploy.jboss.teste2.password>
<liquibase.teste2.database>db_02</liquibase.teste2.database>
<liquibase.teste2.host>192.168.0.4</liquibase.teste2.host>
<liquibase.teste2.user>admin</liquibase.teste2.user>
<liquibase.teste2.password>admin</liquibase.teste2.password>
<profile>
<id>teste1</id>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.7.Final</version>
<configuration>
<hostname>${deploy.jboss.teste1.host}</hostname>
<port>${deploy.jboss.teste1.port}</port>
<username>${deploy.jboss.teste1.user}</username>
<password>${deploy.jboss.teste1.password}</password>
<name>${backend.deployment-name}</name>
<filename>${project.build.finalName}.war</filename>
<skip>${skipDeployment}</skip>
</configuration>
<executions>
<execution>
<id>deploy-jar</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<changeLogFile>${liquibase.changelog.file}</changeLogFile>
<diffChangeLogFile>${liquibase.changelog.file}</diffChangeLogFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${liquibase.teste1.host}:3306/${liquibase.teste1.database}?zeroDateTimeBehavior=convertToNull</url>
<username>${liquibase.teste1.user}</username>
<password>${liquibase.teste1.password}</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>update</id>
<phase>deploy</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>teste2</id>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.7.Final</version>
<configuration>
<hostname>${deploy.jboss.teste2.host}</hostname>
<port>${deploy.jboss.teste2.port}</port>
<username>${deploy.jboss.teste2.user}</username>
<password>${deploy.jboss.teste2.password}</password>
<name>${backend.deployment-name}</name>
<filename>${project.build.finalName}.war</filename>
<skip>${skipDeployment}</skip>
</configuration>
<executions>
<execution>
<id>deploy-jar</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<changeLogFile>${liquibase.changelog.file}</changeLogFile>
<diffChangeLogFile>${liquibase.changelog.file}</diffChangeLogFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${liquibase.teste2.host}:3306/${liquibase.teste2.database}?zeroDateTimeBehavior=convertToNull</url>
<username>${liquibase.teste2.user}</username>
<password>${liquibase.teste2.password}</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>update</id>
<phase>deploy</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And in Jenkins I created two Jobs, one for each profile, and in each Job the following maven command is executed respectively:
clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste1
clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste2
But I would like to deploy the application on two servers at the same time using the same Job, but so far I have not been able to figure out the method to perform such a task, I already tried the following commands but without success:
clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste1,teste2
clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste1 -P teste2
clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste1;clean package jboss-as:deploy javadoc:javadoc liquibase:update -P teste2
In all cases the deployment is done only in one server. Every help is welcome. Thanks.
EDIT:
To accomplish the task I wish I ended up using the "Post Steps" instructions as shown in the image below. It was not the most elegant solution but worked as expected. If someone has a better solution please share.

Maven project dependency "could not find artifact"

I have 2 maven projects. Project A and Project B. Project B is dependent on Project A but not the other way around.
In my project B pom I have this:
<dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>
When i try to package the project it fails with this error:
[ERROR] Failed to execute goal on project ProjectB: Could not resolve dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find artifact com:ProjectA:pom:1.0-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project ProjectB: Could not resolve dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find artifact com:ProjectA:pom:1.0-SNAPSHOT
So it can't find my ProjectA pom. Do I need to put it in my project? Where should it be located in my file structure.
For what it's worth, I am using intelliJ IDE.
Thanks in advance.
EDIT: When i run install on projectA I get this error:
The packaging for this project did not assign a file to the build artifact
EDIT2 - Adding ProjectA pom:
<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>edu</groupId>
<artifactId>ProjectA</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProjectA</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-jar-lib</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>prepare-package</id>
<phase>prepare-package</phase>
<configuration>
<target>
<copy file="${basedir}/src/main/webapp/META-INF/context-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/META-INF/context.xml" />
<copy file="${basedir}/src/main/webapp/WEB-INF/web-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<copy file="${basedir}/src/main/resources/log4j-${app.environment}.xml"
tofile="${basedir}/src/main/resources/log4j.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<phase>compile</phase>
<configuration>
<target>
<copy file="${project.build.directory}/classes/log4j-${app.environment}.xml"
tofile="${project.build.directory}/classes/log4j.xml" />
<delete>
<fileset dir="${project.build.directory}/classes" includes="**/*-local.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-test.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-prod.*"/>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${basedir}/src/main/webapp/META-INF/context.xml" />
<delete file="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<tstamp>
<format property="last.timestamp" pattern="yyyyMMddHHmmss"/>
</tstamp>
<property name="build.time" value="${last.timestamp}" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>true</failOnMissingWebXml>
<!--<webResources>
<resource>
<directory>src/main/WEB-INF/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>-->
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-file</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${artifactId}-${version}.war</sourceFile>
<destinationFile>${project.build.directory}/ProjectA##${build.time}.war</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You have to install ProjectA in your local Maven repo (or otherwise make it available in whatever remote repositories your pom.xml or settings.xml point at). For example:
cd whereever/projectA/lives
mvn clean install
This will write com/ProjectA/ProjectA.pom to your local Maven repo and when you do this ...
cd wherever/projectB/lives
mvn clean install
... Maven will resolve ProjectA.pom from that location.
Note: the dependency you have declared on ProjectA:
<dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>
... will transitively add all dependencies declared in com:ProjectA to ProjectB's POM, is that definitely your intention? This only makes sense if ProjectA is packaged as a POM, if it is packaged as a JAR then you need to update the dependency declaration in ProjectB to remove this line: <type>pom</type>.

Use dependency command line parameters with maven build

I am using findbugs-maven-plugin in the verify phase of the maven life cycle. i.e. it runs on mvn clean install. This is the code I have in my parent pom.xml (in a multi-module project).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<findbugsXmlOutputDirectory>target/findbugs</findbugsXmlOutputDirectory>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>target/findbugs</dir>
<outputDir>target/findbugs</outputDir>
<stylesheet>plain.xsl</stylesheet>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
This is working fine and html files are being generated in each module target. However I want to take this a step further by being able to use parameters allowed by findbugs during the maven build (for example onlyAnalyze). I do not want to add configuration in the pom.xml.
I want the build process to remain the same unless I specify by some command that I want to analyze only one class, for example by running:
mvn clean install -Dfindbugs:onlyAnalyze=MyClass
Do you know of a way I can do this?
This is how you can call a standalone goal:
plugin-prefix:goal or groupId:artifactId:version:goal to ensure the right version.
In your case: findbugs:findbugs
With -Dkey=value you can set plugin parameters if they are exposed. http://mojo.codehaus.org/findbugs-maven-plugin/findbugs-mojo.html doesn't show that option. Just to compare: http://mojo.codehaus.org/findbugs-maven-plugin/help-mojo.html does have such options. Here it is still called Expression with ${key}, nowadays it's generated as User property with just key.
If you want onlyAnalyze to be set from commandline, either ask the mojo-team to fix that, or do the following:
<project>
<properties>
<findbugs.onlyAnalyze>false</findbugs.onlyAnalyze> <!-- default value -->
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<configuration>
<onlyAnalyze>${findbugs.onlyAnalyze}</onlyAnalyze>
</configuration>
</plugins>
</build>
</project>
Now you can call mvn findbugs:findbugs -Dfindbugs.onlyAnalyze=true

maven execute java command

I want to execute a jar file with parameters from maven. The command I want to execute is listed below. I have the perf4j jar file in the dependency. The times.log file is in they filesystem.
java -jar perf4j-0.9.16.jar times.log
Thanks
You might want to take a look # exec-maven-plugin
first
mvn clean install
than
mvn exec:java -Dexec.mainClass="com.java.App" -Dexec.args="Args"
What do you really want to do ? Using a jar (which is a dependency) to monitor your app ?
Did you took a look at maven exec plugin ?
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
...
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>maven</executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>-X</argument>
<argument>myproject:dist</argument>
...
</arguments>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
I had looked at maven exec plugin but wasn't sure how and where to specify the jar file name, hence thanks for your responses, but I was looking at a little more info especially with jar file. With some trial and error the following worked. I had to find the main class to use from the jar file. mvn install runs the file and produces the following output:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.perf4j.LogParser</mainClass>
<arguments>
<argument>InlineLogging.log</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
</dependency>
</dependencies>

Resources