很簡單:您使用更高版本的Java編譯器編譯應用程序,而不是使用Tomcat下的Java運行時。
更新
Java編譯器,javac的,支持的選項
-source release
Specifies the version of source code accepted. The following values for release are allowed:
1.3 the compiler does not support assertions, generics, or other language features introduced after JDK 1.3.
1.4 the compiler accepts code containing assertions, which were introduced in JDK 1.4.
1.5 the compiler accepts code containing generics and other language features introduced in JDK 5. The compiler defaults to the version 5 behavior if the -source flag is not used.
5 Synonym for 1.5
...更重要的是,
-target version
Generate class files that will work on VMs with the specified version. The default is to generate class files to be compatible with the JDK 5 VM. When the -source 1.4 or lower option is used, the default target is 1.4. The versions supported by javac are:
1.1 Generate class files that will run on VMs in JDK 1.1 and later.
1.2 Generate class files that will run on VMs in JDK 1.2 and later, but will not run on 1.1 VMs.
1.3 Generate class files that will run on VMs in JDK 1.3 and later, but will not run on 1.1 or 1.2 VMs.
1.4 Generate class files that will run on VMs in JDK 1.4 and later, but will not run on 1.1, 1.2 or 1.3 VMs.
1.5 Generate class files that are compatible only with JDK 5 VMs.
5 Synonym for 1.5
...這將讓您編譯特定版本的JVM的代碼。
換句話說,您可以繼續使用1.6編譯器,只需將這些選項放在它上面,並且可以生成1.5個Tomcat將能夠處理的代碼。
如果您使用相同版本的Java進行開發和生產,您的生活將會變得更加輕鬆。 – 2009-12-15 15:41:18