Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Java compiler compliance level

I need to compile a Java program on the command line, and I am trying to set the compiler level to a lower one (1.6). I tried like this but it didn't work:

javac -1.6 Hello.java
like image 424
georgiana_e Avatar asked Aug 10 '13 13:08

georgiana_e


People also ask

How to change compiler compliance settings in Java?

Step 1: Go to Window -> Preferences. Step 2: Go to Java -> Compiler . Find the print screen. Step 3: Select Compiler compliance level. Step 4: To change default compliance settings, we need to uncheck Use default compliance settings and set the compiler java version for .class and source compatibility.

What is the compiler compliance level available in Eclipse?

The compiler compliance level in eclipse is available only up to that level of java version for which our eclipse version supports. In our demo we are using Eclipse Luna 4.4.2 version which supports compiler compliance level up to Java 8 i.e 1.8.

How to change Java compiler version in Eclipse IDE?

To summary, here are the steps to change Java compiler version for a project in Eclipse IDE: Install JRE/JDK that supports the Java version you want to use. Update Java Build Path for the project, pointing to the new JRE/JDK Change Java compiler compliance level.

How do I select the compiler level for my application?

In the Compiler compliance field, select the compiler level that you want to use for your application. Note: You must select the compiler level that is supported by the version of the WebSphere Application Server that you are deploying to. For example, If you are using WebSphere Application Server version 6.0, select Java 1.4 compiler compliance.


2 Answers

Use -source and -target options:

javac -target 1.6 -source 1.6 Hello.java
like image 104
Rohit Jain Avatar answered Nov 15 '22 15:11

Rohit Jain


Use: javac -source 1.6 -target 1.6 Hello.java


This information comes from running javac -help:

Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...]Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
like image 27
Nayuki Avatar answered Nov 15 '22 16:11

Nayuki