FaqJdk11

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.)


Using Microsoft's 1.1 JVM

If you are using a Windows machine with the Microsoft VM installed (jview launcher) you can use NB to develop applications and applets, with some work to set things up.

1. Install MSJVM (from msjavx86.exe, gotten wherever). Remember to check for Windows Updates after doing this, as there may be security fixes you need.

2. Install Sun JDK (not JRE) 1.1 from

http://java.sun.com/products/archive/index.html

and ask to include Java sources during installation. Really you just need a dummy folder to give as the location of your "JDK" (below), so that the IDE doesn't complain that it cannot find javac.exe, so you could use any Sun JDK for this purpose. Make sure you install a "real" JDK usable with NetBeans (1.4+) later than 1.1, so your Windows registry shows the recent JDK as the default; or adjust the JDK home in thenetbeans.conffile in your IDE installation to point to the recent JDK.

3. Locate or create the folder %NETBEANSUSERDIR%\config\Services\Platforms\org-netbeans-api-java-Platform and use Notepad to make a file in it called msjvm.xml with contents:

<?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='msjvm' default='no'>
  <properties>
    <property name='platform.ant.name' value='msjvm'/>
  </properties>
  <sysproperties>
    <property name='sun.boot.class.path' value='C:\WINDOWS\Java\Packages\7ZFNPJNP.ZIP;
C:\WINDOWS\Java\Packages\AHZV3D39.ZIP;C:\WINDOWS\Java\Packages\DFBX7DV9.ZIP;
C:\WINDOWS\Java\Packages\LFNXVZFP.ZIP;C:\WINDOWS\Java\Packages\LVTJVLZP.ZIP;
C:\WINDOWS\Java\Packages\RLNXF3BP.ZIP;C:\WINDOWS\Java\Packages\TRJJ1FVB.ZIP;
C:\WINDOWS\Java\classes;C:\WINDOWS\Java\trustlib'/>
    <property name='java.specification.version' value='1.1'/>
    <property name='java.class.path' value=''/>
    <property name='java.ext.dirs' value=''/>
  </sysproperties>
  <jdkhome>
    <resource>file:/C:/jdk1.1.8/</resource>
  </jdkhome>
<!--
  <sources>
    <resource>file:/C:/jdk1.1.8/src/</resource>
  </sources>
-->
</platform>

(that classpath should all be one line, just wanted to break it up for the web page!)

Edit locations of the *.ZIP files if they differ from your computer's installation - seems to be random?

Note that the "JDK home" here points to some random Sun JDK. The exact location is irrelevant so long as it has a bin\javac.exe file.

You can uncomment the entry giving sources if you have installed a Sun JDK 1.1 with sources and you do not care about using Microsoft proprietary extension classes.

4. Start the IDE.

5. Make a new Java project.

6. In the project's properties dialog, change Java Platform to msjvm to use the MS JVM.

(Seems there can be a bug at this stage: InvalidObjectException or similar. If it happens to you, just shut down the IDE, delete %USERDIR%\var\cache, and restart.)

7. Now you should be able to edit code in the editor. Code completion will not work on MS-only classes if you have specified <sources> in msjvm.xml; however if you do not specify some sources, you will have no popup Javadoc, and you cannot add it through JDK 1.1 documentation (the IDE only recognizes 1.2+ format); so you have to choose between having full code completion for Java Platform classes only (use of MS classes will not break background compilation but may break Fix Imports), or having code completion with no Javadoc for all classes including MS extensions. This is because the IDE (in 4.1+ versions) ignores binaries for purposes of code completion when sources are specified: issue #70220. (But see note at end.)

8. To set up compilation and running, open build.xml from the Files tab and 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>
                        <pathelement location="C:\WINDOWS\Java\classes"/>
                        <pathelement location="C:\WINDOWS\Java\trustlib"/>
                        <fileset dir="C:\WINDOWS\Java\Packages\" includes="*.ZIP"/>
                    </bootclasspath>
                    <classpath>
                        <path path="@{classpath}"/>
                    </classpath>
                    <compilerarg line="${javac.compilerargs}"/>
                    <customize/>
                </javac>
            </sequential>
        </macrodef>
    </target>
    <target name="run" depends="init,compile" description="Run a main class.">
        <exec executable="jview" dir="${work.dir}">
            <arg line="${run.jvmargs}"/>
            <arg value="/cp"/>
            <arg path="${run.classpath}"/>
            <arg value="${main.class}"/>
            <arg line="${application.args}"/>
        </exec>
    </target>
    <target name="run-single" depends="init,compile-single">
        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
        <exec executable="jview" dir="${work.dir}">
            <arg line="${run.jvmargs}"/>
            <arg value="/cp"/>
            <arg path="${run.classpath}"/>
            <arg value="${run.class}"/>
        </exec>
    </target>
    <target name="run-applet" depends="init,compile-single">
        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
        <exec executable="jview" dir="${work.dir}">
            <arg value="/a"/>
            <arg value="${applet.url}"/>
        </exec>
    </target>

Note that you are cross-compiling with the version of javac that came with the JDK you are running NB on, but it should work fine.

9. Now you should be able to compile, run main classes, and run applets.

Note: if you run an applet, and you want to run a main class afterwards, you must go into the Run panel of the properties dialog and change

-Djava.security.policy=applet.policy

to

/d:java.security.policy=applet.policy

to work with jview.

10. If you want to test applets in Internet Explorer, try replacing the last target with

    <target name="run-applet" depends="init,compile-single">
        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
        <exec executable="C:\Program Files\Internet Explorer\iexplore.exe">
            <arg value="${applet.url}"/>
        </exec>
    </target>

(If IE blocks the applet from displaying, just click on the warning message and confirm that you really want to run it.)

Finally, some sample classes to help you sanity check your configuration:

package testmsjvm;
public class Main {
    public static void main(String[] args) {
        System.out.println("I am " + System.getProperty("java.version") +
                           " from " + System.getProperty("java.vendor"));
        System.out.println(com.ms.wfc.app.Application.class);
    }
}

(Note in the above that it does work to both compile and run against proprietary MS Java classes. Add some tips to Wiki if you know what to do with them!)

package testmsjvm;
public class TestApplet extends java.applet.Applet {
    public void init() {
        System.out.println("Hello! (see applet console, not output window)");
        initComponents();
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        label = new java.awt.Label();

        setLayout(new java.awt.BorderLayout());

        label.setText(System.getProperty("java.version") +
                      " from " + System.getProperty("java.vendor"));
        add(label, java.awt.BorderLayout.CENTER);

    }// </editor-fold>
    // Variables declaration - do not modify
    private java.awt.Label label;
    // End of variables declaration
}

Good luck!

Stuff to add to the Wiki if you figure it out:

  • building ActiveX controls and running them in IE
  • configuring the MS Java SDK or tools from MS VJ++ 1.1 (e.g. to get full sources to proprietary extensions, or to use proprietary language features like closures with the special compiler)
  • You could probably add sources for MS-only classes if you had them available e.g. through the MS SDK for Java.
  • Or, even without any extra downloads, you might be able to get code completion on all classes including Javadoc for standard classes by running a Java decompiler on the non-Java-platform ZIPs, then specifying sources for the platform as the Sun JDK's src.zip plus the "fake" sources for the MS classes... but do not do that as you would probably be violating the license agreement for the MS JVM. It might even work to specify the "sources" for the platform as the Sun src.zip plus the original MS-specific compiled binary ZIPs.

Applies to: NB 5.0 (maybe 4.1 and 4.0?)

Platforms: Linux, Windows

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo