Friday, July 28, 2006

How to setup some plugins to use java 1.5 in a java 1.4 workspace?

Most of the eclipse projects use and require java 1.4. Sometimes you want to create a new project to use java 1.5. If you simply install and select a java 1.5 in the Preferences->Java->Installed JREs, that would work, but cause potential problems. One problem is that you might accidentally use 1.5 features in 1.4 projects. A simple statement like:
string.replace("foo", "bar")
complies in this setup but will not run with a 1.4 jre, because
replace(CharSequence target, CharSequence replacement)
is new in 1.5.


The solution is to setup only the plugins that really need 1.5 to use 1.5 Eclipse has the concept of Execution Environments to specify which java JREs a plugin is compatible with.



1. set in the preferences an 1.4 jre as default and have an 1.5 installed:



2. In the project properties set the java compiler 1.5 (which is Compiler complience level 5.0 -- how I love the ever changing java version naming...):



3. Set the execution environment in the build path to J2SE-1.5:



4. In the plugin MANIFEST.MF, set the execution environment to J2SE-1.5 as well:


You could also directly add the following line to the MANIFEST.MF file



That's it :-)

2 comments:

  1. You could also read http://wiki.eclipse.org/index.php/Execution_Environments.

    ReplyDelete
  2. Niel, I just checked it and it is not true. If you are not applying step 3 then 1.5 functionality is not available. Simple test: "a".replace("a","b"); does not work, unless you apply step 3. (Assuming your default execution environment is 1.4!)

    ReplyDelete