Having trouble exporting maven javafx probject - maven

I recently made my own version of the 2048 game in javafx. I used maven and eclipse to build the project and whenever I run the project in eclipse it works perfectly fine. However, when I exported the project into a runnable jar, the jar wouldn't run. I tried running it from the command terminal to see what was wrong. I got the error "JavaFX runtime components are missing, and are required to run this application." The thing is when I created the maven project on eclipse I made sure to add the javafxml achetype to my maven project. I thought this would ensure that javafx would work with my project. This is my first time working with maven, so any advice would be appreciated.
pom.xml:
<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>game</groupId>
<artifactId>twentyfourtyeight</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>game.twentyfourtyeight.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Related

How to resolve a conflict with a system scope dependency jar

I have a jar that my code depends on and it is located locally on my PC.
That jar contains the 'org.apache.commons.lang3' package but an older version or a version that contains the class 'StringUtils' but without all of its methods.
In my maven pom, I am using the 'org.apache.commons.lang3' dependency also but at runtime I get the error 'NoSuchMethodError' which means that during runtime it is using the commons.lang3 version of the jar and not the one from my dependency.
Is there a way to force it to use the dependency in my pom file?
Here is how my pom looks like:
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<test.path>C:/Users/user/test</test.path>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${test.path}/dep.jar</systemPath>
</dependency>
</dependencies>
<!-- build fat jar file with dependencies -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>dep-included</shadedClassifierName>
<outputDirectory>${test.path}/out</outputDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
CONCLUSION FROM COMMENTS:
It is not possible to remove such packages in a jar with Maven. I have to manualy edit and remove the packages from the jar file.
Thank you all for taking the time to answer!

How to read values from .properties using maven plugin

How to read the properties from .properties file by using maven provided plugin, for one of my current project, I always used to set the properties in the <properties> tag of pom.xml, But here my requirement is, I will set the all properties in some .properties file for ex: dev.properties. It is having the following content inside it.
spring.package=org.springframework
spring.artifact=spring-core
spring.version=3.0.5.RELEASE
So, now I want to set the above properties into the pom.xml like the following:
<dependencies>
<dependency>
<groupId>spring.package</groupId>
<artifactId>spring.artifact</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
I gone through this link : How to read an external properties file in Maven
But it is giving the following error : Missing artifact org.springframework:spring-core:jar:spring.version
Here is the pom.xml
<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>com.ram</groupId>
<artifactId>DynamicProperties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring.version>spring.version</spring.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<urls>
<url>file:///D:/Hadoop_Apps/DynamicProperties/src/main/resources/dev.properties</url>
</urls>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
But spring-core-3.0.5.RELEASE jar is avail in maven repository.
Is there any other plugin in maven to do the same, or did I missed any additional config here.
Please correct if I am wrong.
Thanks.
First of all, when Maven reads your pom.xml, it'll immediately replace placeholders such as ${spring.version} with the actual value you specify as
<properties>
<spring.version>spring.version</spring.version>
</properties>
So changing the values later via a plugin is too late! Maven will not do this, however, if there's no value available at this time. Therefore you can remove these properties from pom.xml and let Maven plugin define them later in build lifecycle. This usually solves uses of properties overridden by plugins, but...
Second, there might be still another problem: Maven will likely resolve dependencies (including their versions) before even executing any plugin, which will prevent you from doing this whole thing. If that's the case, you can move your properties to a profile and activate a certain profile instead.
<properties>
<!-- default goes here, when no profile is used -->
<spring.version>3.0.4-RELEASE</spring.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.version>3.0.5-RELEASE</spring.version>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.version>3.0.1-RELEASE</spring.version>
</properties>
</profile>
</profiles>
Please find below the corrected 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ram</groupId>
<artifactId>DynamicProperties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring-version>spring.version</spring-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<urls>
<url>file:///${basedir}\src\main\resources\config.properties</url>
</urls>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
The problem was in -
<spring.version>spring.version</spring.version>
tag. It should have been
<spring-version>spring.version</spring-version>
inside properties tag.
BR

Jenkins package project out of his workspace

I tried to build maven war projects with Jenkins.
Jenkins pulls the code and builds the project. However, the build is not in the workspace, but rather in a folder with the project source. I think Jenkins takes the target folder from maven pom file and builds it.
How can I tune Jenkins to make a build and deploy pipeline?
In the deploy phase Jenkins cannot find war file.
OS is windows, IDE - eclipse.
<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>my.test.webapp</groupId>
<artifactId>webApp</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>webApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<directory>${basedir}\target</directory> <!-- tried with this line and without -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
The way I coped with a problem:
In pom.xml:
<properties>
<baseFolder>${basedir}</baseFolder>
</properties>
<build>
<directory>${baseFolder}/target</directory>
</directory>
In Jenkins run build maven build with properties
baseFolder=$WORKSPACE

About pom.xml run and outputs

I am new to pom and i run the below pom.xml it executed successfully but there is no results found in under target folder.
please tell me how to execute my pom and where i found my results (Like : Outputs)
<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>xx_groupid</groupId>
<artifactId>yy_artifactid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>yy_artifactid</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.15</version>
</plugin>
</plugins>
</build>
</project>
the pom is valid, try:
mvn package
if everything goes well, maven will package your project into a jar file at target/yy_artifactid-0.0.1-SNAPSHOT.jar
--edit--
you can use Exec Maven Plugin to run java programs
add the the plugin to your pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.example.Main</argument>
</arguments>
</configuration>
</plugin>
remember to change the org.example.Main to the main class of your program which should contains a static entry method: ** public static void main (String[] args)**
and then run: mvn compile exec:exec
to execute the unit tests of your application, put test cases under src/test/java fold, and run mvn test

run findbugs through maven eclipse

how to run findbugs through eclipse with maven project. I have configured in maven as:
<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>com.home.app</groupId>
<artifactId>home-app</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>home-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
i want to know what are the errors/warnings reported by findbugs.
You will find the report during the usual compile package phase created in the target directory. If you like to see a more readable output you have to use the findbugs goal in the reporting block instead of the build block.
You could also just use the findbugs eclipse plugin which will give you a nice eclipse window that points you directly to all of your bugs.

Resources