The Docs of Azure Service Bus have in example picture:
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-java-how-to-use-queues#configure-your-application-to-use-service-bus
that it uses java 8. Also code samples use Java 8 syntax and functions. I have an environment of java 7 and I am unable to get it work supposedly because java is too old.
Does anyone know a working combination of the Azure Service Bus with Java 7? I would need either the version that works for sure or answer that no version does so.
I test with newest 1.2 version available of Azure Service Bus.
I checked the maven repository list of Azure ServiceBus, these versions after 0.9.8 are all built by Java 8 via check the pom.xml file, the version 0.9.8 is built by Java 1.6. Therefore, there is not any released jar files compiled by Java 7 or other ealier Java version for the latest version 1.x.x.
A workaround way for yours is manually to download the source codes of Azure ServiceBus from GitHub repo to compile it in maven by yourself. You can use JDK 7 to do it, even use JDK 8. The only changes you need is use 1.7 instead of 1.8 for the configuration of maven-compiler-plugin in pom.xml, such as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.7</source> <!-- 1.8 -->
<target>1.7</target> <!-- 1.8 -->
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
Note: If using JDK 8 to do this above for compiling with the javac parameter -target 1.7 -source 1.7, you must make sure there is not any code of using Java 8 features which will cause compiler error, such as error: lambda expressions are not supported in -source 1.7 for JDK 8. However, I roughly checked its source codes that there seems not to be. For more details about -target or -source for Javac 8, please see https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html.
Related
I've a maven project with the maven-compiler-plugin configured as below:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
In my code I use a class java.nio.charset.StandardCharsets which is introduced since 1.7.
I'm surprised that my code compiles successfully, shouldn't the plugin throw an error because java.nio.charset.StandardCharsets is not 1.6 compilant?
Neither target nor source relate in any way to what classes are available on the compiler's classpath. If you're compiling your code with the 1.7 compiler then any classes that shipped with 1.7 will be available to your code.
What target does is tell the compiler to output .class files in a format that is compatible with the 1.6 release of java. source says only accept java code that would compile with the 1.6 version of the compiler.
So it's perfectly legitimate to make a call to a class that shipped only on 1.7 or later using Java 1.6 compatible source code written into a class file that is compatible with Java 1.6. It just won't run on 1.6.
The only way to ensure your code will run on 1.6 (if that's what you're trying to do) is to use a 1.6 JDK to compile your project.
We have a Java 7 project which uses a plugin built with Java 8. Is it possible to use the Java 8 plugin in Java 7 pom by setting the compiler version to use only for the plugin?
I just found that on the internet :
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
You should just add a configuration section specifying the jdk wanted as
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
I hope it helps !
It is only possible, if the plugin forks into a new JVM process and allows you to configure the JVM which it uses to execute. Otherwise it will use the JVM, which the whole build uses. You would then have to run the build with a JRE/JDK 8 (which shouldn't be a problem when you set the source and target version appropriately, like in the answer from Juan Wolf (just set 1.7 instead of 1.4)
This question already has an answer here:
Maven - use -source 5 or higher to enable... while building the project
(1 answer)
Closed 8 years ago.
Whenever I deploy a Jenkins build with Maven, it says that I have the 1.3 JDK, even though I have 1.7 installed.
Here is a picture of the error log I get when using an enhanced for loop:
http://gyazo.com/d1c7e297199dbf8a8b6ba23efa5733ba.png
However, I clearly have 1.7 JDK installed.
http://gyazo.com/27b85ba9ea25579aa714b0e2586fd618.png
If anyone knows why this issue occurs and how to fix it, please post below.
Sorry I don't have a ton of formatted information, but I have no idea why this could possibly be happening as I do not have such an outdated JDK and have the most recent updates from Oracle. Maven and Jenkins are also updated completely.
Thanks.
The complaint of maven is not about your jdk version, but about the -source parameter of the compiler. Older Maven versions use a version of the maven-compiler-plugin, which uses -source and -target 1.3 by default.
So, what you need to do is configure you project to use higher source and target levels in order to use your for each loop:
(taken from https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Note that simply setting the version of the maven-compiler-plugin would actually be sufficient, since for version 3.1 the default is 1.5, however it is good style to explicitly include the source and target version in your master pom.
You have the project set to compile with the default jdk according to your stack trace. Your default is your %JAVA_HOME% environment variable on the server which is probably set to an older jdk. In order to compile with the 1.7 jdk you have to specify this in your project config. Change jdk : (Default) to your 1.7 name.. which is jdk.
Or you can just go to the maven jdk and change it from (inherit from project) to jdk.
There is already an issue ticket open with jenkins related to this: https://issues.jenkins-ci.org/browse/JENKINS-755
The method java.lang.Long.compare(x, y) exists in Java 7 but not Java 6. So obviously this causes a NoSuchMethodException if code using this method is deployed to a server running Java 6.
However, either Maven nor Eclipse were picking up the error despite having set the source-compliance level to 1.6 in eclipse and the maven compiler source & target to 1.6.
Is there a way to enforce full Java 6 compliance in Eclipse, apart from downgrading my JRE to 6?
This is exactly why the animalsniffer-maven-plugin was introduced:
Animal Sniffer provides tools to assist verifying that classes compiled with a newer JDK/API are compatible with an older JDK/API.
This is what I put in my 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" >
...
<properties>
<java-version>1.6</java-version>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>
Once I have that defined in my POM I right click the project and go to Maven > Update project. This will apply any settings in the pom to the eclipse project which ensures the two are in sync.
In terms of JDK I use the latest JDK but compiled to the lower release. We're currently using JDK 7 but compile to 6. This gives you the best of both worlds in that the compiler will still make use of any optimizations that were introduced with 7 that are compatible with version 6.
There is a way to cross-compile Java source code, but the easiest way is to use the min. required JDK version when creating your artifacts (JARs etc.)/ during development.
-> use JDK 6 during development and releasing.
Note however that Oracle's JDK 6 reached End of Life and it is strongly recommended to upgrade to Java 7 if you don't have special support contracts with Oracle (or using a JDK from a different vendor).
Note: the source-level only makes sure you're using syntax constructs supported by that version and the target-level only makes sure the resulting class file is bytecode compliant to the specified version.
I was recently stung by some code making it through our deployment cycle without throwing any compile errors when it should have (we thought)...
The code in question being using the new static method Integer.compare which is since Java 1.7.
The server environment is run on Java 1.6. While our development environments have Java 1.7 installed.
Our assumption was that setting the project preferences to JavaSE-1.6 compliance would at least give us compile warnings on the code in question, however no warning or error is visible in eclipse.
Project > properties > java compiler > JDK Compliance > Use compliance from execution environment 'JavaSE-1.6' on the java build path
Secondarily to that, we use maven to compile the final deployment. The pom is clearly directed to comply with the 1.6 compiler:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
</configuration>
</plugin>
However the maven build runs successfully with the problem code.
How can I tell both maven and eclipse to fail when code will not work in an earlier Jvm than it is being compiled by?
Thanks, Paul.
Use the maven animal sniffer plugin to tell you when you use APIs that aren't backward compatible. I'm also told that Java 1.7 has a feature for this, but I have no personal experience with it.
Install java 1.6 in the development environment, then right click on the project in eclipse an go to Properties->Java Build Path. Go to the Libraries tab and remove the java 1.7 JRE, then add the java 1.6 JRE.
I'm not familiar enough with maven to answer that half.