Reputation: 11691
I want errors popping up in Netbeans and during compilation when using newer features like java.nio.file.* that are not existing in Java 6 yet. Just specifying the source and target versions in the maven compiler plugin configuration does not work: maven compiles the sources and netbeans does not care about using non-Java-6 stuff.
Upvotes: 0
Views: 70
Reputation: 11691
Ok, it seems the only possibility is to force using jdk 6. Configuring the bootclasspath requires a localized pom.xml pointing to a machine-specific directory which is worse.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>(,1.7)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 0
Reputation: 99959
There are two different things affected by setting the source version when compiling with Java 7 and/or 8. Whether or not you install Java 6, setting the source level to 6 will prevent you from using features like try with resources, multi-catch, or lambda expressions. However, this alone will not prevent you from using APIs defined in the newer releases.
To get the latter, you need to also specify the boot classpath. An example of this is shown in the following code.
https://github.com/antlr/antlr4/blob/master/pom.xml#L114-L115
In the example, the use of the boot classpath is restricted to compilations done with the sonatype-oss-release
, which only requires the machine to have the older JRE (not necessarily JDK) installed only for release builds. This setting makes it easier for new users to contribute, although it means I always have to double check pull requests using the release build before merging them. I believe the balance has been successful for the long-term maintainability of the project.
Keep in mind OSX installs Java 6 using a different location and even a different file name than what Linux and Windows use, which explains why the path is parameterized the way you see in the example.
Upvotes: 1