6 Replies Latest reply: Jan 24, 2014 7:43 AM by gimbal2 RSS

Question about javac -source -target

795530 Newbie
Currently Being Moderated

Hello:

 

I am using JDK 1.8.0-ea and I want to compile my sources for 1.7 (compatibility with previous VM: 1.7 is the latest official release)

 

C:\Users\admin>javac -target 1.7 prg.java

javac: target release 1.7 conflicts with default source release 1.8

 

C:\Users\admin>javac -source 1.8 -target 1.7 prg.java

javac: source release 1.8 requires target release 1.8

 

Is there some way I could compile for previous VM or will 1.8 classes NOT be compatible  with previous VMs?

  • 1. Re: Question about javac -source -target
    rp0428 Guru
    Currently Being Moderated
    I am using JDK 1.8.0-ea and I want to compile my sources for 1.7 (compatibility with previous VM: 1.7 is the latest official release)

    Ok - but you know that can't possibly work if those sources include features that were NOT in 1.7 don't you?

     

    You will get that same message if you try to target an older version that has a different class file format.'

    That's all the help we can give since you didn't post any source code.

  • 2. Re: Question about javac -source -target
    795530 Newbie
    Currently Being Moderated

     

    Ok - but you know that can't possibly work if those sources include features that were NOT in 1.7 don't you?

     

     

    Thanks: Actually the code was compiled for JDK7, (it can be compiled even with jdk6).

    The main problem is that when JRE 8 is available for public,  many systems will still have older JREs, thus JDK8 bytecode would not run in them.

    Although I can compile it with JDK7 tools, I thought that JDK8 could compile for backwards compatibility, if new features were not used in code.

  • 3. Re: Question about javac -source -target
    rp0428 Guru
    Currently Being Moderated
    Thanks: Actually the code was compiled for JDK7, (it can be compiled even with jdk6).

    Huh? I read your post to mean that you can NOT compile it for JDK7 using JDK8. But my point was that if you use JDK8-specific features then the code isn't backward compatible.

    The main problem is that when JRE 8 is available for public,  many systems will still have older JREs, thus JDK8 bytecode would not run in them.

    Although I can compile it with JDK7 tools, I thought that JDK8 could compile for backwards compatibility, if new features were not used in code.

    Normally new versions support some limited number of previous versions using the -target and -source parameters.

     

    You may have found a bug - you can report it using the 'Report Bugs' link on the JDK8 download page.

    https://jdk8.java.net/download.html

  • 4. Re: Question about javac -source -target
    gimbal2 Guru
    Currently Being Moderated

    Am I just dumb when I look at this thread and then think: why is -source 1.7 not being used then?

  • 5. Re: Question about javac -source -target
    795530 Newbie
    Currently Being Moderated

    gimbal2 escribió:

     

    Am I just dumb when I look at this thread and then think: why is -source 1.7 not being used then?

    Good point:

     

    C:\Users\admin\>javac -source 1.7 -target 1.7 cl.java

    warning: [options] bootstrap class path not set in conjunction with -source 1.7

     

    Unless this warning is innocuous,  I would need JDK7. But If I have JDK7, I would compile with it.... and forget JDK8.

  • 6. Re: Question about javac -source -target
    gimbal2 Guru
    Currently Being Moderated

    Seems like the only reasonable option anyway. I mean Java 8 isn't even final yet (notice that -ea extension? Early Access)! Why the heck would you want to compile stuff with it, assuming it is for production usage and not because you're doing tests with Java 8 for future deployment.

     

    And besides: no matter what you do, with warnings or without, how can you go into the weekend without feeling ashamed if you don't actually test this out on a Java 7 runtime at least once? Until then its broken because it is untested.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points