Specify JRockit or JDK to Maven - maven

I'd like to know how to specify the path of JRockit libraries to Maven to use , same as we do for eclipse when you specify the JRE .
Also how do i configure maven to use Sun JDK in a project and use JRockit in another project ?
Thanks

A number of options available:
Maven uses the JAVA_HOME environment variable to determine which JVM
should run Maven (Maven is itself a Java program). I recommend this as the first option because build servers like Jenkins can easily control the JVM being used to run Maven.
You can tweak the settings of the compiler plugin to compile using
a different JDK
An alternative approach (clearer to others running your build) would
be to build in a pre-condition check into the POM, using the
enforcer plug-in. Specify a rule that the it should be compiled
using a specified Java version.

Related

What version of java does gradle use to run your application?

I have a JavaFX project I am working on using Gradle. What version of java is used when I use the gradle run task from the application plugin?
In IntelliJ I can go into the Gradle settings and change the "Gradle JVM" to any version I want. Is this just the version of java that is used to run the build? Or is this also the version that my application will be run on?
Where does my JAVA_HOME come into this, if at all?
Irrespective of IDEs, Gradle will use whatever language level of the JVM that is running Gradle. Typically whatever the value is for JAVA_HOME.
See Environment variables and Targeting a specific Java version
The new way to do it as of Gradle 6.7 is to use Toolchains for JVM projects
Your IDE should respect whatever Gradle configuration that is configured.

Change java source version for multiple project using same sonar scanner

I have 3 different projects. One of them is based on java 1.6 and the others are using java 8 features. I have sonar-scanner locally and running the analysis by using scripts (no Maven or Gradle is being used). I have configured the sonar.java.source to be 1.6.
My problem is that same runner is being used to analyze the other 2 projects (java 8 ones). How can I change the version of the java source for the other ones? I don't want to manually change it each time I want to run the runner.
Can I somehow pass it as parameter?
Source version is not a property of the scanner, but of the projects. Configure these values in your pom, or your sonar-project.properties files, or in the command line arguments (-Dsonar.java.source=1.x), but not in the SonarQube Scanner properties.

How to specify JDK in maven jetty plugin

How to specify JDK in maven jetty plugin?
Like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webApp>
<contextPath>/${project.build.finalName}</contextPath>
<jettyEnvXml>${project.basedir}/src/over/here/jetty-env.xml</jettyEnvXml>
</webApp>
<httpConnector>
<port>8080</port>
</httpConnector>
<!--<executable>${env.JAVA_IBM_HOME}/bin/javac</executable>-->
</configuration>
</plugin>
Please note: the excutable tag is incorrect, I just use it as an example.
To clarify: you actually want to specify an executable, so probably an JRE (Java Runtime Environment) and not a JDK (Java Development Kit). While it is true that JDK serve as JRE as well, this is a required clarification in my opinion.
Coming to your question, there is no such a think to specify a different JDK/JRE used to execute a certain Maven plugin: plugins are executed as part of the mvn command, which in turn is executed using the system JDK/JRE by default (set in the path) and it is actually a script which invokes a plain Java main, yes, Maven it's written in Java and its execution starts from a Java main, the following one to be clear:
org.codehaus.plexus.classworlds.launcher.Launcher#main
If you want to change the JRE used to launch this main, you need to change the JAVA_HOME variable upfront, as also explained by this old SO post.
So you would need the following:
set JAVA_HOME=path_to_your_different_jdk
mvn jetty:run
In your IDE and according to the screenshot you posted in your answer, you are actually doing the same: setting which JVM must be used.
This is true for most of the plugins, unless a specific forking mechanism is foreseen. For instance:
The Maven Surefire Plugin provides a fork mechanism via the reuseForks option and the jvm option, which also explains that:
Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the jvm will be a new instance of the same VM as the one used to run Maven.
The specified JVM (JRE or JDK used as JRE) will then be used to executed the tests (basically the same scenario you were looking for concerning the Jetty Maven Plugin.
The Maven Compiler Plugin also provides a fork option which can then use an executable option where you can effectively point at a different JDK (and not JRE in this case) to compile your code.
Sets the executable of the compiler to use when fork is true.
The Jetty Maven Plugin is executed as part of the Maven command (again, a Java main using the JRE specified by the JAVA_HOME variable or the default of your system), as also specified in its official documentation:
The classpath of the running Jetty and its deployed webapp are managed by Maven
...
For example, you might need to run your webapp in a forked instance of Jetty, rather than within the process running Maven;
And indeed a run-forked goal is provided
This goal allows you to start the webapp in a new JVM, optionally passing arguments to that new JVM. This goal supports the same configuration parameters as the jetty:run goal with a couple of extras to help configure the forked process.
This option however is mostly used to pass different arguments to Jetty rather than a different executable (for example, in case you already set the same argument for Maven and you want it with a different value for the Jetty run). So, again, the option is not there (to specify which executable/jvm to use for this forked execution). That's a pity, because they got almost there with this goal.
I think I got the answer by myself, but I still don't know how to do it in maven xml file, if you know it, please tell me.

Installing maven and the maven eclipse plugin?

I installed maven from here: http://maven.apache.org/download.cgi
and also installed plugin for eclipse from the eclipse marketplace.
This is a really dumb question, but what's the difference between the two?
both are same thing ? or for differnet purposes ?
do we need both on system ?
Maven itself is the software you can use on your machine. It has nothing to do with Eclipse. You can use it from the command line with the mvn command to execute Maven goals on your projects in the file system.
The Maven Eclipse plugin (m2e) integrates Maven with Eclipse so you can comfortably use Maven functionality from inside Eclipse rather than using Maven as an external tool. The plugin just integrates Maven with Eclipse and needs a Maven installation to work. You can configure the plugin to use the Maven installation on your system but there is no need for one. It can use it's own internal "installation" of the actual Maven software. This would be basically the same as you can download and install yourself but it is integrated with the plugin. It therefor can't be used outside Eclipse.

Release a Maven POM without expanding a variable

I've got a dependency on tools.jar in my project, which is a javac plugin. It can be configured to be run in a Maven build. So there's a maven plugin to enable a javac plugin.
This can be done by following the Maven FAQ:
http://maven.apache.org/general.html#tools-jar-dependency
includes
<systemPath>${java.home}/../lib/tools.jar</systemPath>
The problem is that the mvn release pom expands all variables, so when I've released my maven plugin, it refers to a hardcoded jdk path from the machine where the release was performed, rather than a variable to resolve it at runtime on the client machine.
That obviously causes my Maven plugin to fail to include tools.jar on the classpath.
I can't find any way to convince the maven release plugin to leave this variable in the output. Any ideas?
Bug reference: https://code.google.com/p/error-prone/issues/detail?id=18

Resources