0

I am developing Java software using NetBeans 6.5 IDE (Build 090226) with Maven (4.0.5) using Java (1.6.0_06) on a Fedora system.

I am making an update to some legacy code and I wanted to build a test for it (using JUnit). The code is used with Java 1.5. To provide the test data in the quickest, simplest way possible, I wanted to implement a simple mock data set by extending the ResultSet interface. The problem is, despite having my project set up to build and test with JDK 1.5:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
    <source>1.5</source>
    <target>1.5</target>
    <fork>true</fork>
    <executable>/usr/java/jdk1.5.0_14/bin/javac</executable>
    <compilerVersion>1.5</compilerVersion>
  </configuration>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- snip some non-jvm configuration -->
    <jvm>/usr/java/jdk1.5.0_14/bin/java</jvm>
    <forkMode>once</forkMode>
  </configuration>
</plugin>

the editor still wants to make my class abstract because it thinks I am missing methods which exist in Java 1.6 ResultSet, but which use classes which don't exist in Java 1.5 (NClob and RowId and SQLXML).

My compiler plug-ins seem to be set up correctly -- I can successfully build and run this JUnit test, but my whole source tree is showing error icons (effectively masking any real errors). If I use the 'Go To Source' function (or 'Go To Declaration') on the ResultSet import statement, it brings me to the Java 1.6 source zip, but on a method responds 'Cannot perform Go To Source here'.

What did I miss? How can I get the NetBeans editor window to recognize that this code uses the 1.5 JDK, not the JDK NetBeans was started with?

TIA, Ilane

Ilane
  • 484
  • 7
  • 18

2 Answers2

0

Using the Maven Compiler Plugin does not influence the Compiler Settings of your Netbeans Project.

Have a look in the project properties, there you can set the source / binary format to the version you need. But note that this will not hide methods that are only available in the Java platform version which is set in your IDE (which will most likely be 1.6 these days). This can be problematic for example with the IOException constructor accepting a cause, and other API extensions which were introduced with Java 1.6 or later.

Netbeans will happily compile this code when set to 1.5, but it will indeed not run on a 1.5 JVM. So to be absolutely sure you will also have to install a 1.5 JDK, add it to your platforms list (Tools -> Platforms) and use that to compile your project. As an additional bonus, when using the right JDK NetBeans will mark things like the missing IOException constructor right in the editor window.

andih
  • 5,570
  • 3
  • 26
  • 36
  • My Source/Binary setting for my Project is already set to 1.5 (I hadn't known to check it, but it was already set) and the Java Platforms already includes my 1.5 platform. But the editor window is still going to the 1.6 source code. So are you saying that there is no way to make the IDE use 1.5 for the IDE Java Editor other than starting NetBeans with 1.5? – Ilane Nov 01 '12 at 18:17
  • You don't have to start Netbeans with a specific version. You can change the platform JDK / Version of your Project by selecting the desired platform in the project build/compiler settings. You can also check this by expanding folder the Java Dependencies of your Maven Project. It should display your JDK 1.5 not the JDK 1.6 or default JDK. If JDK 1.6 is displayed go to the Project Properties and change the build/compile Platform to JDK 1.5 after that there should be no more references to the 1.6 JDK in your Project. – andih Nov 01 '12 at 18:39
  • Isn't setting Source/Binary to 1.5 "selecting the desired platform"? That was already set to 1.5. Are "project build/compiler settings" elsewhere? I searched and I find no folder called "Java Dependencies" anywhere in my IDE -- is is possible you're referring to a different version than 6.5? I have both 1.5 and 1.6 listed in my Java Platforms list. Version 1.6 is listed as default (isn't that from starting netbeans with 1.6?). The only project-specific configuration I know is in the pom.xml files and the references to java there are listed in my original posting. Can you be more specific? – Ilane Nov 01 '12 at 19:55
0

Adding a 'profile.xml' (menu option under 'Project Files' to the main project with the following, fixed my problem:

<profiles>
  <profile>
    <id>netbeans-private</id>
    <properties>
      <netbeans.hint.jdkPlatform>JDK_1.5</netbeans.hint.jdkPlatform>
    </properties>
  </profile>
</profiles>

Thanks to andih for his encouraging support which kept me searching for an answer.

Ilane

Ilane
  • 484
  • 7
  • 18