Can JDK version be specified in source code? - ide

I'm developing a Java app on two different computers (same source code) that have different JDK versions. Is there a way to specify JDK version in the source code so that an IDE (e.g. NetBeans) will compile the source code the same way on both machines?
One of my computers has JDK5 and the other has JDK6. Under 5, jdbc-interface doesn't support some methods (e.g. NClob, XML...) which are available in 6, so code that gets compiled on the 6 machine works while code compiled on the 5 machine doesn't. Right now, I have to comment out 6-only stuff when working on the 5 machine.

Not in the source code. You want to set your IDE to compile using a Java 5 JDK. You can do this by installing a Java 5 JDK alongside the Java 6 JDK, and specifying that (which is IDE dependent).
Alternatively, if you're using Ant, you can specify the Java version in the javac task.

Don't overcomplicate the issue... install the same version of the JDK on all the machines, and set your IDEs to use that version. Ignore other versions.

I know this has been answered but if you cant update the 1.5 to 1.6 then all you need to do is set the ide that is using 1.6 to compile to "source compatibility" of 1.5
There is no need to install the 1.5 on the machine that is running 1.6 because the JDK is backward compatible.
The setting in eclipse is preferences > Java > Compiler

You'll always have to regress to and code against the lowest version of the JDK - in your case you can't use the features introduced in JDK version 6.
As Brian has said, it's probably safest if you work with the IDE configured to use the same JDK (version 5 in your case).
You can switch to a particular runtime version using the version argument, but that's probably not going to help in you.
Also note, compiling your code against version 6 and running against version 5 will cause runtime error due the incompatible class versions, when as you stated you try to use JDBC methods that didn't exist in the older version.

In NetBeans you have right click on project properties then source version if you have jdk 1.6 you can build it with previous versions

What you need to do is specify the source compatibility to something that's supported by both JDKs (<= 1.5). It may make sense to go lower than 1.5 if, for instance the application you're building may be deployed to an environment that only has Java 1.3 installed.
I know this is possible in Eclipse, but unfortunately, I'm not familiar with NetBeans, but I'm sure it would be possible too.
If it's any help, here's how you do it if you're just running javac from the console (assuming you want 1.5 as your base level):
javac -source 1.5 ...
This is also possible as a plug in configuration within a Maven POM, if you're using Maven (which I understand NetBeans has excellent support for). This is how you'd do that (from http://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>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
And as Brian Agnew points out, possible in Ant also.

Problem is: do you need to support JVM 1.5? If so, your code should be fully 1.5-compatible (which doesn't seem to be). If not, just update your JVM in all your machines (as already suggested) to same JVM version (and don't forget version minor: 1.6.0_03 != 1.6.0_14).

Related

How to use javaparser plugin of JQAssistant?

I'm trying to use javaparser plugin of JQAssistant using command line. I have done the following:
Copied "jqassistant.plugin.javaparser-1.8.0.jar" to "plugin" folder.
I also noticed plugin has runtime dependency to "com.github.javaparser:javaparser-core:3.6.25". So I copied "javaparser-core-3.6.25.jar" to plugin folder too.
But when I try to scan a Java file I get the following error:
"ANTLR Tool version 4.9.2 used for code generation does not match the current runtime version 4.7.2"
The ANTLR version bundled with JQAssistant is 4.9.2 but plugin is expecting older version 4.7.2.
Has anyone been able to use javaparser plugin?
Some plugins (not only javaparser) indeed depend on JARs bundled with jQAssistant. Sometimes there are version conflicts, that's why it can only be guaranteed that Kontext E plugins with a certain version (let's say 1.8.x) are compatible with jQAssistant with the same major and minor version (so jQA 1.8 in this case). If you use javaparser 1.8.0 with jQAssistant 1.8.0 (which comes with org.antlr-antlr4-runtime-4.7.2), it works.

Why is there no kotlin-stdlib-jdk11?

I'm using Kotlin for backend development...
Is it because Kotlin 1.4 already supports it? Or kotlin-stdlib-jdk8 would suffice? Or Kotlin does not have plans to support JDK 11?
Please enlighten me.
Thanks!
TL;DR kotlin-stdlib-jdk8 can be successfully used with JDK 11.
The motivation of splitting binaries by JDK 1.7 and JDK 1.8 is the dependency of the jdk8 artifact on some APIs not available (e.g., ThreadLocalRandom) in older Java versions.
Currently, there is no need for a special standard library artifact for JDK 11 because Kotlin doesn't provide any APIs depending on it.
Update: just in case, if you use Kotlin Gradle Plugin, you don't need to specify Kotlin's standard library dependency manually since the plugin adds it to all the Kotlin source sets automatically.

Difference between IntelliJ IDEA versions "Linux" and "Linux, without JDK"

When downloading IntelliJ IDEA, there are two options for Linux:
I assume the Linux (.tar.gz) version comes with a JDK and the Linux, without JDK (.tar.gz) version does not. However, when reading the documentation I see:
IntelliJ IDEA does not include an SDK. So, before you start writing your code, you have to download and install at least one SDK and define it in IntelliJ IDEA.
So what exactly is the difference between the two versions? And if one comes with a JDK, which JDK does it come with?
This is the JDK IntelliJ IDEA itself runs on. To quote a related support document:
Starting from IntelliJ IDEA 16 and the most recent versions of the lightweight IDEs, we are bundling custom JRE with Linux distributions, just like we've been doing for Mac. Our custom JRE is based on OpenJDK and includes the most up to date fixes to provide better user experience on Linux (like font rendering improvements and HiDPI support).
For your own projects you will probably want to use an official and supported Oracle JDK.

Can maven3 runtime execute maven2 compatible pom.xml files

Some of our new projects have been migrated to maven3 and some of the older projects are still using the maven2 compliant pom.xml files.
Can maven3 runtime execute maven2 compatible pom.xml files also?
maven 3 is mostly compatible with maven 2 configuration. But there is still some incompatibilities.
For a full list you should check here there is also sometime problems with plugins (as Torsten suggested).
Resources:
Maven 3.x Plugin Compatibility Matrix
On the same topic:
switching to maven3
Typically yes, but it may depend on the plugin version you are using.
Please note that e.g. the maven site plugin is different for maven 2 and maven 3 or some options of the maven enforcer plugin are no longer valid for maven 3. There might be others.
Yes, it is.
At first you may be alarmed by the fact that it reports a bunch of warnings and sometimes refuses to build before you take care of the problems, but this is actually better for you as (if you run into this) it simply tells you what was wrong with your project so far.
Other than that, the site plugin is completely re-written and you need to use the version for Maven 3. (Check here)

How can I JSDK of Intellij on MacOSX

How can I JSDK of Intellij 9.0 on MacOSX? I want to set it to JDK 1.5 on MacOSX.
I have tried reintall Intellij, but it somehow remember the JSDK of my previous installation.
Can you please tell me how can I reset it?
Thank you.
Not sure if you mean Java version IntelliJ runs under, or Java version IntelliJ uses for projects.
If it's the first:
On OS X applications are usually directories. This is true for IntelliJ.
Go into the IntelliJ 9.0.app folder
Go into Contents folder
edit Info.plist (you will need to have installed Apple's Developer tools)
There is a Java subsection that has the setting you need to change.
If it's the second, go to Project Structure -> JDKs and create whatever ones you want.
Depending on your OS X version, you may have no JDK 1.5 installed at all (Snow Leopard 10.6.x comes with no JDK 1.5). In this case IDEA will run under the first JDK it finds, even if it's 1.6 while Info.plist specifies 1.5. If you have both JDK versions installed, Info.plist should work fine, see the IDEA FAQ.
If you want to install JDK 1.5 on Snow Leopard, see another IDEA FAQ article.