tags:

views:

256

answers:

7

Hi I am using eclipse 3.2 and i want to change my compiler compliance level from 1.4 to 1.5(i.e 5.0) or higher..using java program?? not manually..means my java program will automatically do it ...can anyone tell me how to do that??

A: 

This seems self-referencing.. how can you choose to compile something in a way that is actually declared inside what you want to compile itself? When javac starts to compile it should already know what compliance level to use..

I think you can do it by using JavaCompiler interface (apidoc here) but you'll have to workout something that is not so simple..

Jack
A: 

I may be interpreting this wrong. So I apologize if I did.

To me it sounds like are trying to make your app only compile with 1.5 or higher, right? In that case you can use maven compiler plug-in to have it compiled only with jdk 1.5 and also set your maven repository accordingly.

CoolBeans
A: 

Are you really asking "how can I compile my program so it can run on both 1.4 and 1.5?"

The -target 1.4 option to the compiler will produce .class files that can be loaded by a 1.4 JVM. However, that is generally not enough. You will also need to make sure you do not use any classes, or call any methods, that are node defined in the 1.4 API.

The -source 1.4 option won't help. It will disable generics and assert as a keyword, but it won't stop you from using new APIs.

The best approach is to build with a 1.4 JDK.

Devon_C_Miller
A: 

Sorry I don't get the questions...

What you are trying to achieve is to change a configuration value in your IDE.

In Eclipse you can set a default compliance level for all projects. If theres a project which needs other settings, you can configure this project specific.

All settings you make are saved in your project folder in a subfolder called .settings. If you are using eclipse, try the "Navigator View" to have a look at it.

The compliance level is stored in a file called "org.eclipse.jdt.core.prefs":

org.eclipse.jdt.core.compiler.compliance=1.4

It doesn't make any sense, that your program has an dependency to your IDE changing any values...

If you want to change the compliance level, you have to do this just once. Even if you move your project in another workspace, etc. Eclipse will recognize your settings.

So where is the need to automate a simple task (just 3 clicks...) you just have to do once?

echox
Actually i have implemented project in 1.4 now i want that when i will import that project in new version eclipse..it should change my compiler compliance level from 1.4 to 1.5(i.e 5.0) automatically and i need java program to do this..without user interference ..it will do it automatically..
Rahul
A: 

"I may be interpreting this wrong. So I apologize if I did.

To me it sounds like are trying to make your app only compile with 1.5 or higher, right? In that case you can use maven compiler plug-in to have it compiled only with jdk 1.5 and also set your maven repository accordingly."

Thanks. yes i am asking for that only..how to do it plz explain it more????

Rahul
Sorry I did not notice this post. Here are the steps:1.First install maven on your pc or server whatever applies.This http://maven.apache.org/download.html has a step by step instruction.2.Then create a pom.xml file yourself or use mvn create artifact to have it created for you.This link http://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project will guide you through that process. 3.Add the following to your pom.xml if it's not there already to add the compiler compliance.You will notice on that page about the maven compiler plugin.4.run mvn install.
CoolBeans
why did you accept your own answer as the correct answer? Does not make sense.
CoolBeans
A: 

Actually i have implemented project in 1.4 now i want that when i will import that project in new version eclipse..it should change my compiler compliance level from 1.4 to 1.5(i.e 5.0) automatically and i need java program to do this..without user interference ..it will do it automatically

Rahul
A: 

Have a look at the ".project" file in the root of each project in your Workspace.

Thorbjørn Ravn Andersen