Can I use JDK 1.1 for my project?
The IDE does not support JDK 1.1 directly but it can be made to work if you want. Here are some sample
instructions which were tested with a NB 5.0 development build running under JDK 6 on Fedora Core 4 Linux
with an installation of Blackdown's JDK 1.1.8:
1. Make a new Java "class library" project.
2. In the Files tab, open project.properties. Edit the definition of javac.source to read:
javac.source=1.2
(the 1.2 language doesn't really differ from 1.1, so this is just to make sure the editor doesn't think assert or generics are allowed!)
and also add to either project.properties or private.properties the location of your JDK 1.1 installation,
e.g.:
jdk11.home=/space/jdk118_v3
3. Openbuild.xmland add
<target name="-init-macrodef-javac">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute name="srcdir" default="${src.dir}"/>
<attribute name="destdir" default="${build.classes.dir}"/>
<attribute name="classpath" default="${javac.classpath}"/>
<attribute name="debug" default="${javac.debug}"/>
<element name="customize" optional="true"/>
<sequential>
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}"
deprecation="${javac.deprecation}" source="1.1" target="1.1"
includeantruntime="false" bootclasspath="${jdk11.home}/lib/classes.zip">
<classpath>
<path path="@{classpath}"/>
</classpath>
<compilerarg line="${javac.compilerargs}"/>
<customize/>
</javac>
</sequential>
</macrodef>
</target>
<target name="-init-macrodef-java">
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute name="classname" default="${main.class}"/>
<element name="customize" optional="true"/>
<sequential>
<java fork="true" classname="@{classname}" dir="${work.dir}"
jvm="${jdk11.home}/bin/java">
<jvmarg line="${run.jvmargs}"/>
<classpath>
<path path="${run.classpath}:${jdk11.home}/lib/classes.zip"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper type="glob" from="run-sys-prop.*" to="*"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
These Ant targets should suffice to make basic compilation and execution of Java apps work. If your JDK 1.1
installation has a different file layout from Blackdown's, you may need to adjust these targets a bit (update
this Wiki page if so).
3a. If you are using NetBeans 6.0, the macrodef for 'depend' should also be added in <target name="-init-macrodef-javac"> after macrodef for javac, as follows:
<target name="-init-macrodef-javac">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
...
</macrodef>
<macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.dir}" name="srcdir"/>
<attribute name="destdir" default="${build.classes.dir}"/>
<attribute name="classpath" default="${javac.classpath}"/>
<sequential>
<depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
<classpath>
<path path="@{classpath}"/>
</classpath>
</depend>
</sequential>
</macrodef>
</target>
4. Make a new Java GUI Forms / AWT Forms / Applet Form. Build whatever GUI you like, using e.g.
GridBagLayoutas the layout manager (Matisse won't work), and of course using just AWT components (no Swing). (Unfortunately, the form designer will still use constants like BorderLayout.PAGE_START that don't exist in Java 1.1, and these will show up in generated code that can't be hand-modified. Use the source view to check for these errors. You'll have to simply avoid using those features of the form designer that cause problems, or code your app without using the designer at all.)
5. You will need to correct the init() method to call initComponents() directly (EventQueue.invokeLater
does not exist in this JDK, but you do not need it anyway).
6. Press Shift-F6 (or select Run / Run File / Run from the menu) to build and run your applet. The JDK 1.1 version ofappletviewershould start with
your applet.
7. Running a main class should work similarly.
The above setup does not include code completion, i.e. the IDE will show you code completion from your default
JDK (whatever the IDE runs on - 1.4+), even though your project will be compiled by Ant against JDK 1.1. Also,
the background error stripes will not show accidental usage of JDK 1.2+ APIs. To make code completion and
background error detection work is a little tricky since the Java Platform Manager does not recognize JDK 1.1
installations. But you can set it up manually:
1. Close the IDE.
2. In your user directory (available from Help | About), locate the directory
config/Services/Platforms/org-netbeans-api-java-Platform and make a new text file called JDK11.xml
with contents like:
<?xml version='1.0'?>
<!DOCTYPE platform PUBLIC
'-//NetBeans//DTD Java PlatformDefinition 1.0//EN'
'http://www.netbeans.org/dtds/java-platformdefinition-1_0.dtd'>
<platform name='JDK11' default='no'>
<properties>
<property name='platform.ant.name' value='JDK11'/>
</properties>
<sysproperties>
<property name='sun.boot.class.path' value='/space/jdk118_v3/lib/classes.zip'/>
<property name='java.specification.version' value='1.1'/>
<property name='java.class.path' value=''/>
<property name='java.ext.dirs' value=''/>
</sysproperties>
<jdkhome>
<resource>file:/space/jdk118_v3/</resource>
</jdkhome>
<sources>
<resource>jar:file:/space/jdk118_v3/src.zip!/src/</resource>
</sources>
</platform>
Of course replace the three occurrences of /space/jdk118_v3 with the location of your JDK 1.1 installation.
The second two are URLs so you need to use / not \ on Windows.
3. Restart the IDE. You should see an entry JDK11 in the Java Platform Manager.
4. Open the properties of your Java project, and set Libraries | Java Platform to JDK11. The IDE will ask
you to set the source level to 1.1; you can accept this offer (shouldn't matter).
5. Now try code completion on your project - you should see only JDK 1.1 classes. (However, this does not fix the problem noted above with the form designer using constants that are not valid in Java 1.1.)
No comments:
Post a Comment