Detecting non-1.5 Java code when developing on mac for 1.6

I am using mac (and therefore java 1.6) to develop a cross-platform application released in Java 1.5. I found that Eclipse can provide 1.5 compliance, and it saved me the trouble of posting code with @Override syntax in 1.6 style. However, eclipse matching is limited in syntax. He will not catch functions. For example, I used the 1.6 String.isEmpty () method, which was created and launched without warning in Eclipse and on my mac command line, but then broke when it switched to our 1.5 Linux machines.

Is there a way, perhaps something that I could run on jar files after the build, or some other way to catch the 1.6-isms that I jumped into without leaving my mac?

+4
source share
8 answers
Good question. My suggestion was to properly configure the project build path in Eclipse to point to 1.5 libraries.

First install 1.5 JDK or JRE. Then go to Properties for your Eclipse project. In the "Java Build Path" section, go to the "Libraries" tab, find the entry "JRE System Library". Edit this entry to point to "Alternate JRE" (you may need to click "Installed JREs" to tell Eclipse where the JRE is first). Select 1.5 JRE.

This should use Java 5 rt.jar, which has only 1.5 APIs.

+3
source

If you are using Maven, this is exactly what animal trapper means.

If you are developing a project that should support the launch of JDK version 1.4, but your development system does not have an available version of JDK version 1.4, it can be quite easy to accidentally use methods or classes that are available only in the newer version from JDK. For example, if you are developing a plugin for Maven 2.0.x on a newer version of Macintosh .

The animal killer can check the classes and method signatures that your compiled code uses and make sure that you only use the classes and signatures that are available in the API you are using.

+2
source

What prevents you from using the 1.5 java version in the Mac Box. I have a Mac machine and it has Java versions 1.5 and 1.6. If you cannot find its location, you can: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home

+1
source

This answer is hacked and completely untested, but it should work.

When Eclipse compiles your code, it uses rt.jar and tools.jar , which belong to the current and / or specific JRE. You can copy the “normal” JDK to a new directory and replace the JAR files from the Linux / Windows 1.5 distribution. Add a JRE to Eclipse (in settings) as an alternative and switch to it when you want to test your code.

0
source

The only thing, in fact, would be to install 1.5 JDK and compile with this. If you cannot install the old version of java on OS X, install VirtualBox, install Linux in it and install java on it. It sounds like a mental thing - it's probably a mental thing, but it's actually quite simple, and it gives you an absolutely waterproof build.

0
source

If you compile through javac as usual, there is a command line option -source release Java Oracle doc that determines the version of the accepted source code.

Thus, to build only using 1.5, use source 5 or source 1.5

0
source

Assuming you upgraded to OSX 10.6 from 10.5, you should have JDK v1.5 installed next to JDK 1.6, otherwise you can download it from Apple .

You can then create the application using ant and JDK 1.5. Note: ant relies on the value set for the JAVA_HOME environment variable.

You can, for example, edit your /Users/name/.bash_profile to include these values ​​based on the actual path to the installation location of your JDKs:

 JAVA_HOME_14=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home JAVA_HOME_15=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home JAVA_HOME_16=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home export JAVA_HOME=$JAVA_HOME_15 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin 

So when you need to switch to JDK 1.6, just replace

 export JAVA_HOME=$JAVA_HOME_15 

with:

 export JAVA_HOME=$JAVA_HOME_16 
0
source

I am using DependencyFinder for this purpose. First, the bytecode of all classes in my jar file is analyzed and all dependencies are retrieved. As a result, an XML report is created that contains all the classes, constructors, methods, and member attributes that my application refers to.

This XML report is then filtered in two steps:

  • Only store classes, constructors, methods, and member attributes in the namespaces I want to test. In my case, java.* And javax.* .
  • Exclude all classes, constructors, methods, and member attributes that appear in the whitelist that lists all valid characters for this version of the JDK (for example, 1.5).

If the final report after filtering contains an attribute of a class, constructor, method or member (i.e. if it is not empty), then the assembly is interrupted - this means that you are using APIs that are not supported by your goal JDK Release.

It sounds a bit verbose, but in practice it works very well and does not depend on the IDE settings (which is impractical when several developers are working on the same project). I have an ant macro that automates this task, although of course, this solution does not require ant.

0
source

All Articles