I am working on developing a java application which will be scheduled in control-m tool.
the program is configurable without modifying source code,meaning that has the ability to specify log file path, data input file for the program.
control-m or the windows shceduler may or may not have Jre or JDK installed on those machines. What I am thinking to do is to include jre related jars in my project jar(maven module) by specifying it as dependency in my pom.xml so that I don't need to worry whether java installed on those machines from which the program can run.
I am using jdk 1.6.
You can specify this plugin in pom.xml for java dependency.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<executable>${env.JAVA_HOME}/bin/javac</executable>
<fork>true</fork>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
For this JRE must be installed and JAVA_HOME path must be set on system machine.
Related
I have Java maven project with TestNG
Please see this pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_181\bin\javac.exe</executable>
</configuration>
</plugin>
So inside Windows when I want to run this project from command line I just navigate into this pom.xml folder and then:
mvn clean test
And this will start all my tests.
Now inside this pom.xml i have my javac.exe path so in order to run this project in MAC what I need to add/ change? (I want it to support both OS)
The best practice would probably be to rely on the standard JAVA_HOME environment variable:
<executable>${env.JAVA_HOME}/bin/java</executable>
I have a maven project. In the pom.xml file the following is stated:
...
<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>
...
</plugins>
</build>
...
AFAIK this is correct, it should build against JDK 7.
I run a Debian based Linux dist and when I do mvn clean install it seems to always build against the javac version I have set in my os.
I've tried reading up on what the plugin exactly does https://maven.apache.org/plugins/maven-compiler-plugin/, but it doesn't really state how.
An example is I have javac 8 running on my os. When I invoke mvn clean install, the project compiles against JDK 8 and not JDK 7 as stated in the pom.xml. Why is this?
By default the maven-compiler-plugin uses %JAVA_HOME%/bin/javac to compile, unless:
you set the executable-parameter to a different location
you use Toolchains, which seems to match your requirements, i.e a different Java Runtime for Maven compared to the JDK for the maven-compiler-plugin.
Source and target settings are just passed to the javac compiler as parameters. The javac installed on the machine is used.
I have a collection of "Samples" projects. The toplevel project is empty, while it contains a lot of modules.
Unfortunately, I am often required to set target bytecode to 1.5.
I did that many times from the beginning of the project, but it still drops back to 1.5.
How to stuck with 1.8 forever?
You can use this in your pom:
(https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
The issue in my case (RHEL 7, IntelliJ 2019.3.1) was missing environment variable JAVA_HOME.
Well I'm running Eclipse with Tomcat runtime environment (it is run from Eclipse) and I've recently turned my web project to Maven project. Now it finally compiles well, however when I try running it on server it doesn't seem to load the compiled classes and hibernate configuration files to the Tomcat working directory in :
**D:\Dropbox\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myProject**
So I have to copy all the compiled classes and practically all the missing files manually everytime I now change anything...
Can I change anything in Eclipse settings? Also where should I output my compiled classes from Maven? At the moment the build in pom.xml looks like this:
<build>
<sourceDirectory>src/</sourceDirectory>
<directory>${basedir}/build</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Can anyone help me with this? Thanks in advance.
I'm using Eclipse EE 3.7 with m2e plugin installed. I have JDK7 set in eclipse.
When I import maven projects, the JRE is set to JRE System Library [J2SE-1.5], So i have compilation issues with java 6 related stuff. Instead I want the JRE in eclipse to be by default set to JRE System Library [J2SE-1.6]
When i try to open a new project in eclipse File -> new -> Java project on the first screen i have an option to choose JRE and the third option is Use default JRE (currently 'jdk1.7.0_03')
From this i can see that the default JRE in Eclipse is 1.7, but when i import new Maven projects, the JRE is set to 1.5 by default.
Any help, how can i do this?
The problem is not with Eclipse, but with the projects you're importing. m2e will set the project's JRE to match the maven project. The POM specifies the JRE version, and this is defaulted to 1.5 if not present. You need this in the POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
artbristol gave the correct answer (and I upvoted him).
That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
The root cause of this issue is Eclipse cannot resolve a valid value for the maven.compiler.source property when updating the .classpath file from the pom, it is simply using default one i.e
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5.
Just Add following properties into you pom.xml and update project:
<properties>
<javaVersion>1.8</javaVersion>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
You can have your brand new Maven project in Eclipse have JRE System Library version other than JavaSE-1.5. For that,find below jar in the following location.
File: maven-compiler-plugin-3.1.jar
Location:
.m2\repository\org\apache\maven\plugins\maven-compiler-plugin\3.1
Then unzip the jar and locate "META-INF\maven\plugin.xml" which has four occurrences of default-value="1.5". Replace all four 1.5 with 1.8 or whatever the version you want. You would know the rest of the process.
Reference