Arunabh Ghosh
Arunabh Ghosh

Reputation: 318

How to set the javac compiler flags to generate 1.7 bytecode?

I am trying to follow the instructions on this page to install Google App Engine on Ubuntu 16.04.

I am stuck on the third point in 'Installing on Linux' which is:

The App Engine Java SDK requires Java 7 bytecode level. You can use either Java 7 or Java 8; be sure to set the javac compiler flags to generate 1.7 bytecode:

-source 1.7 -target 1.7

What I have tried is:

javac -source 1.7 -target 1.7

But this gives me the error

javac: no source files
use -help for a list of possible options

The command given below also give the same error

javac -source 1.7

However javac -target 1.7 gives the following error

javac: target release 1.7 conflicts with default source release 1.8

Any advice on how to tackle this problem would be highly appreciated.

Further information:

javac -version gives javac 1.8.0_92 as output.

java -version gives this output:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Upvotes: 0

Views: 4144

Answers (2)

M Sach
M Sach

Reputation: 34424

You mentioned the jdk version to compile with and jvm version to compatible with but did not mention source file which actually needs to be compiled

  javac -source 1.7 -target 1.7 yourSource.java

see http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html for details

Upvotes: 1

Jesper
Jesper

Reputation: 206846

You use the -source 1.7 -target 1.7 options when you actually are compiling code. For example:

javac -source 1.7 -target 1.7 MyProgram.java

will compile the source file MyProgram.java and produce a Java 7-compatible class file MyProgram.class.

It's not like you execute javac -source 1.7 -target 1.7 once and then some setting is remembered somewhere so that from then on it works in Java 7 mode (which is how you seem to think it works).

Upvotes: 6

Related Questions