简体   繁体   中英

How to run two java versions in the same project?

I have created a project in Java Eclipse which uses java 1.7. But I need to run some specific modules in it using java 1.8.

Is it possible? How?

Simply spoken: you shouldn't do that.

If you are really talking about one project; then you have to make sure that all "components" within your project are on compatible levels.

In your case: if component A requires Java 1.8; and others are fine with 1.7 ... then you should go forward and use 1.8 (you still can use libraries that were compiled for older versions of Java; no need to update/recompile them). And well, if one part needs 1.8; and another only works 1.7 ... then there is no easy solution to that.

The point is: if you deviate from this practice, you will have to use multiple JVMs later on to run your "single" project - and that is of course a contradiction in itself.

The alternative is to dissect the one project you have right now into smaller parts (nowadays you would call them microservices ) and define an architecture that allows you to run different parts of your application using different technology. But as others have pointed out: that adds a whole new layer of complexity to your setup.

you can set the Java compiler level only project wise not the module wise. So in your case you should set the compiler level 1.8 which will support both the version. In eclipse you can set the compiler level by below option. Right click on Project->Properties->Java Compiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM