JavaFX project using Maven in NetBeans - maven

In Netbeans 8.0 I develop JavaFX project using Maven. My java version is 1.7 and I have problems with upgrading to java 8. I tried to change <source> and <target> in pom-file to 1.8
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
but I get error
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ...: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
My JAVA_HOME environment variable set to java 1.8.
When I try to create new JavaFX project like File - New Project - Maven Category - JavaFX Application I still get project with JDK 1.7. How can I force to use JDK 1.8?

First you need to install JDK 1.8, of course.
Then either
in the installation directory set the default JDK location (netbeans_jdkhome property in etc/netbeans.conf )
or
in Tools -> Java Platform: add an entry for JDK 1.8
in the Project properties set the Java Platform to JDK 1.8
I also recommend to use NetBeans 8.x when working with JDK 1.8

you can add in maven tag properties this code
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
and check:
1-Tools -> Java Platform: add an entry for JDK 1.8.
2-the Project properties >> source window >> source/binaryFormat 1.8
Most of time the problem is (2):that netbeans create the JavaFx Maven project with the low jdk 1.7.

Related

I want maven to use JRE system Library [JavaSE 1.8] always while creating new maven quickstart project

I have jdk/jre 1.8 installed on my windows system. In Eclipse whenever I create a quick-start maven project, the project gets created with JRE System Library[J2SE 1.5]. I am fed up of this problem tried to change the execution environment by doing right click on above JRE library-properties and changing the execution environment to 1.8 but again if I update this maven project, the JRE system library goes back again to J2SE 1.5, I also tried changing the compiler compliance to 1.8 which was earlier set to java 10 and also did adding the source and target tag with version 1.8 inside plugin tag of pom.xml but this was also a temporary solution. As when I create a new maven project it sets the default JRE system Library[J2SE 1.5]. Please Provide me with a permanent fix where whenever i create a new maven project, it should be created with JRE System Library[JavaSE 1.8].
Add the following to pom.xml to configure which JDK version you would want to use:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
or the followings:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
It is because when you do Maven --> Update Project in Eclipse , Eclipse 's maven plugin will use what you define in pom.xml to update the setting of the eclipse project. If you don't specify above settings , the default is to use JDK 1.5 (before maven-compiler-plugin version 3.8.0) or JDK 1.6 (3.8.0+)
Basically I want maven to use JDK 1.8 by default. So that i wont need
to change pom.xml contents again and again while making a new project
If you do not want to change any settings related JDK version in pom.xml after creating a project , you may consider to create your own archetype to fully customize what pom.xml looks like after creating an project. Or a more simple way is to search some Java8 archetype created by others and simply use it such as this.
Refer this for how to create a Maven project with an specific archetype using Eclipse. You may probably need to click "Add Archetype" to configure the require information when you use that archetype for the first time. For example , for this archetype, you have to configure the following for the 1st time:
archetypeGroupId=pl.org.miki
archetypeArtifactId=java8-quickstart-archetype
archetypeVersion=1.0.0

Maven goals run in Java6 mode when run in a Jenkins freestyle job

On my jenkins machine, as far as I know, I have two Java installations :
[1041][root#server:/tmp]$ alternatives --display java
java - status is manual.
link currently points to /logiciels/jdk/jdk1.7.0_76_Linux_64bits/jre/bin/java
/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java - priority 16000
I have configured only the jdk 7 to be usable in my jobs.
But, when I run my freestyle job containing a maven goal, I always get
Caused by: java.lang.UnsupportedClassVersionError: myPlugin : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at org.sonatype.guice.bean.reflect.URLClassSpace.loadClass(URLClassSpace.java:101)
which seems to indicate that my plugin runs on a java 6 JRE. How ? And how can I change that ?
UPDATE
I've taken the liberty to run the maven executable from command line ... with the following result.
[1041][root#server:/tmp]$ /logiciels/apache-maven-3.0.5/bin/mvn -v
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /logiciels/apache-maven-3.0.5
Java version: 1.6.0_65, vendor: Sun Microsystems Inc.
Java home: /logiciels/jdk/jdk1.6.0_65_Linux_64bits/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-358.11.1.el6.x86_64", arch: "amd64", family: "unix"
So, it seems the "run maven high level goals" just triggers that mvn executable, which uses an incorrectly configured java version. But weird can only get weirder :
[1041][root#server:/tmp]$ echo $JAVA_HOME
/logiciels/jdk/jdk1.5.0_51_Linux_64bits/jre
The correct way to set jdk used by maven plugins is by using maven toolchains.
Fisrt, create a toolchains.xml in your .m2 directory containing something like:
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
</provides>
<configuration>
<jdkHome>/path/to/your/jdk7</jdkHome>
</configuration>
</toolchain>
</toolchains>
You can have several toolchain defined in this file, each providing a specific version of java and his path.
Then, add the toolchain plugin in your pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
</jdk>
</toolchains>
</configuration>
</plugin>
Once you do that, many plugins, including compiler maven plugin, will use the jdk selected by the toolchain configuration.
Doing that let you use any version of java to execute maven or the jdk set on main path, and add abstraction on where find java on specific machine because defined in toolchains.xml configuration.
BTW, you should consider upgrading maven to version 3.3+ because you use a old (deprecated?) version (3.0)
On the Jenkins freestyle project configuration, you can check the JDK settings applied to the build, at the top of the configuration page, before the "Advanced Project Options" section. Below a picture pointing at the concerned configuration entry
Be sure you are using the JDK of interest. The values available from the drop down box are the JDK configured via Jenkins > Manage Jenkins > Configure System > JDK > JDK Installations..
I just created a free-style build with two steps running a javac -version and a mvn -version and changing JDK version in two runs and indeed changes are effectively applied as expected.

Sonarqube-Analysis on Jenkins fails due to PMD Plugin throwing UnsupportedClassVersionError: Unsupported major.minor version 52.0

Java-Version Configuration
Java-Version used for compiling classes with ant: 1.8
pom.xml für Sonarqube-Analysis defines:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
and
<!-- Set the sonar.java.source property to tell PMD which version of Java your source code complies to. The default value is 1.5. -->
<sonar.java.source>1.8</sonar.java.source>
Sonarqube-Version: 4.5.4
Sonarqube-PMD-Plugin-Version: 2.4.1
JDK configured in Jenkins-Job: 1.8
Sonarqube-Server runs using Java 8
There is only Java8 installed on both Jenkins- and Sonarqube-Server.
Jenkins executes the following maven-comand to start the analysis:
mvn.bat -f "D:\Jenkins\workspace\DVLP MW2.0 Coverage und Codeanalyse\sonar-pom.xml" -e -B sonar:sonar -Dsonar.jdbc.driver=com.mysql.jdbc.Driver "-Dsonar.jdbc.url=jdbc:mysql://192.168.58.121:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8" -Dsonar.host.url=http://192.168.58.121/sonar
What are we missing?
You should remove property sonar.java.source. SonarQube gets Java Class Version from maven-compiler-plugin configuration. It is not a problem if you compile with JDK7 and run analysis with JDK8 (or do both actions with JDK7/JDK8).

jdk version for compiling java code: jenkins vs pom.xml

We are using jdk 6 to compile our code (specified in jenkins), I am trying to specify jdk 7 to compile the projects from now on. I noticed some of the projects have specified jdk 6 in their pom.xml. I am not sure which one takes precedence when jenkins specifies jdk 7 but pom.xml speicifies jdk 6. Any idea which one takes the final precedence to compile the code?
In JDK you can specify the generated class files that target a specified version of the VM. For example if JDK 1.7 is used you can specify the target class file version as 1.7 or lower version.
In maven compiler plugin you can specify the source and target version as follows.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${sourceVersion}</source>
<target>${targetVersion}</target>
</configuration>
</plugin>
</plugins>
</build>
In your case if you want the class to be compiled to java 1.7 then you have to specify ${sourceVersion} to 1.7 and the ${targetVersion} to 1.7
I am not sure which one takes precedence when jenkins specifies jdk 7 but pom.xml speicifies jdk 1.6
If JDK 7 is used in Jenkins and the target version in the pom is 1.6 then the classes will be compiled to jdk 1.6 version.
Check the following links for more information.
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#options

Maven Compiler Plugin Fork Option Not Working

I have a maven pom file with the following compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<executable>${path_to_JDK6}</executable>
<fork>true</fork>
<compilerVerison>1.6</compilerVerison>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
My system's JAVA_HOME is set to a 1.5 JDK. When I run mvn package, maven throws the following error message:
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6
Usage: javac <options> <source files>
Does anyone have any ideas about why Maven is using the 1.5 JDK instead of forking to the 1.6 executable? Is there any debugging option that I could use? Are the fork and executable options broken in Maven 2?
Note: My system admin would not allow me to change the value of JAVA_HOME and some of my new libraries are written for java 6. So I would like to find a workaround to make maven compile with JDK 1.6.
My ${path_to_JDK6} variable only included the path to the folder containing the JDK. It did not include the /bin/javac. When I added /bin/javac, the 1.6 compiler was invoked.

Resources