When creating a launch configuration you can specify an Execution environment, how is that more specifically used? I assume it ends up as a parameter to Java?
What are the consequences if we have a plugin built with JavaSE-1.8 execution environment, and run an application using that plugin and run it with execution environment JRE-1.1?
Explanation:
It won't run. Execution environment says the code is intended to be executed in a certain Java implementation. This affects both: the bytecode version your sources get compiled into and Java Class Library you're code is intended to use. The setting is used by IDE (not sure all IDEs use it - Eclipse does) to make sure you only write code possible to execute in a give EE.
Bytecode incompatibility example:
Java 8 added lambda support - if you use it your bytecode will have labmda related instructions and it will not execute in older JVMs.
JCL incompatibility example:
Java 8 introduced URLPermission class. If you refer to it in your code and try to run it against older Java Class Library you'll get an exception. Even if you compile your code into older bytecode version. The class is simply not accessible in older JCL.
Links:
Eclipse community has a lot of resources on Java Execution Environments - read about it here.
1.8 to 1.1? so much of discord in versions? Anyways, launch configuration has data about path of jre, depenedency jars and location of files where parameters needed by program are stored.
if you change env, your code may not be source compatible or you may get errors like 'file not found /class not found'.
Related
I have java EE artifacts like .jar , .war, .ear files compiled and running in java 1.6 version. i wanted to run them (.ear file [.jar + .war]) in latest java versions like java 1.8.
Which Option would be the best considering moving to new java version.
1) Recompile Code in 1.8 and deploy to Application server
- to be at a little safer.
2) Just deploy to java 1.8
- No Code Compilation required (means .ear file generated using java 1.6). .ear file can be safely deployed to latest java 1.8 version
- probably we wont end-up having runtime issues ?
As this this is a production code base and no developer. Hence No Code changes in either cases, the only change is java version. I prefer going with Option-1, as compilation in higher version of exiting java classes to avoid any runtime issues.
Any thoughts ! or other useful options in this regard.
Thanks
As #Stultuske mentioned you only telling no code changes possible in either cases then your first case not valid one only.
But anyway as per java(Oracle) compatibility specification Java 8 is backward compatible with previous versions for sure no doubt about this except some very rare cases where binary incompatibilities happened.
For more information about this you can refer below stack overflow link --
Can newer JRE versions run Java programs compiled with older JDK versions?
Recently I did a similar thing but we updated the code/dependencies if needed.
I will suggest recompiling the code base first because this will tell you quickly if it or any dependencies don't support the newer Java version. If compilation is successful, then deploy to test environment and do sanity, regression, etc.
I hope you aren't talking about deploying to Production environment directly :)
I am running into an issue with my gradle build script, build.gradle, for my java project. In this script I need to compile the application with Java 6 in order to comply with the application specifications. However, I am also using a gradle plugin that performs code analysis that needs to be run under a Java 8 JVM. What do I need to do in build.gradle or other gradle settings in order to get this plugin to use a separate Java JVM?
I need to do something like this as gradle tasks fail because the plugin is reporting a Unsupported major.minor version 52.0 Error.
Research
I have done some invesitigation and I did see the following mentioned:
options.fork = true
options.forkOptions.executable = System.getenv('OTHER_JAVA')
Where OTHER_JAVA is an environment variable to the other version of Java. However, I have not been able to get this to work for the plug-in and after some more research, it looks like this may be more limited to compiling with a separate version of java, not executing.
See: How do I tell Gradle to use specific JDK version?
You've pretty much answered your question yourself:
it looks like this may be more limited to compiling with a separate version of java, not executing
Run Gradle under the Java 8 (that would mean specifying your JAVA_HOME as JDK 8), and fork the compiler for your app with Java 6 (as per your research).
I have JRE 1.7 installed on my system. Due to some admin issues I don't have JDK on my system. is there any way I can develop Java programs with JRE only?
No you can't develop java programs only with JRE
You will need JDK for compiling your programs.JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE.You will need javac for compiling your code which is present in JDK.
However for resolving the issue of admin rights you are having, you can download and install eclipse which has its own built in compiler.
You need some program which compiles your sources, but that doesn't neccessarily have to be the JDK.
For example you can download Eclipse which only requires a JRE, it has it's own compiler (built-in) and you can develop with that. Eclipse does not require any admin priviliges, it's a zip file which you can download and extract.
You need to compile them in order to develop and that is why you need jdk
You can't develop any Java application since you need JDK(Java Development Kit) to compile your code. JRE(Java Runtime Environment) provides run time environment only. You can run your compiled code in JRE.
the answer is somehow "yes,but..."
java source code execution procedure is split into 2 steps :
1)compiling the source code into a byte-code,thus generating the .class file
2)interpreting the VM specific instructions from the .class file into native instructions
.java----javac---->.class----java---->native code
needless to mention that the "javac" , the compiler of the java source code is in not part of the JRE!
so in order to develop java programs without JDK you have to skip the first step and keep using exclusively the "java" tool,thus dealing directly with byte-code !
in some extent and if you're acquainted with the JVM internals,it's possible to write some lines of byte-code using hex or text editors and then running the .class file;but you will not go further then that specially when it comes to creating complex applications as this require super-human capabilities :that's a highly daunting task .
nevertheless,todays java frameworks almost all use direct byte-code manipulation and tools like the asm framework or javassit
javassist does not require the JDK and you can generate a class from scratch and then compile/run it
java -classpath .:javassist-x.x.jar test "some arguments"
(no need to compile classes)
but again,that is only for restricted use and in order to develop java applications you have to use some JDK...
finally,you have to strive to acquire full control upon what is running in you machine;recent frameworks are resource-greedy and needs a huge amount of resources(disk space,memory...) and many tools and framworks require full control,i mean administrator right : for instance i remember that once a time borland delphi refused to start and i had to give it full access rights to start...
I request you to resolve admin rights. Else I have two options for you.
1) You cannot do anything without Java Development Kit.
2)You can install a IDE to code Java which makes your work in the current situation simpler. Use Eclipse or NetBeans. I would recommend Eclipse to you anyway. You can download eclipse from this link https://www.eclipse.org/downloads/
Try downloading JDK from this http://www.oracle.com/technetwork/java/javase/overview/index-jsp-138218.html.
Hope this helps you.
JDK is needed to compile your java file into class file. And JRE will execute the generated class file and provides the output.
If you have admin problems in your m/c then you can install the JDK in some other m/c and take the class files into your system and execute them.
Eclipse includes its own compiler and doesn't depend on the JDK compiler. But indeed, the JRE is just the runtime environment and doesn't include the compiler or other development tools.
Do you need this to do you job or not? If it's your job, you should have access or they should install it. If you don't have access because it's not your job, I suggest installing the JDK at home (or on a laptop you can take with you)
Due to some admin issues I don't have JDK on my system.
Install it in your home directory or another directory you can write to. Your admins can't prevent you from installing the JDK if you have enough disk space.
JRE is not just sufficient, without compiling the code for that you need Jdk which have compiler to compile the code.
I am moving from Groovy 1.76 to groovy 2.1 and am having a problem running some Java code.
I have java 7 and Groovy 2.1 all setup on my classpath. Gradle is running and my project can run all its unit tests and execute successfully just as before.
However, I have one java class that loads up one of the groovy classes and executes it (the class can be executed normally in regular gradle/groovy unit tests) and when I try to run this in the new environment it fails with the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/ValueRecorder
at com.covestor.glossary.meta.Entity$_Rel__clinit__closure3_closure4.doCall(Entity.groovy:500)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I have seen in other questions/discussions that some classes were removed from Groovy 1.7, so the general advice seems to be to make sure the classes are re-built against a later version of groovy - but my classes are already being built against the later version (my script that kicks off the java code actually calls gradle clean build first to make sure all groovy classes are properly compiled). There are some jar dependencies as well, but none of them are built from Groovy source (all java jars).
Can anyone suggest what the problem might be? I can't see that I have any code anywhere that is still built against 1.7
The ValueRecorder class is used internally to implement the power assert feature in Groovy. Unfortunately, these classes have been moved to another package from 1.7 to 1.8.
Your error means there is still some 1.7 compiled Groovy code. That's the reason for the NoClassDefFoundError.
I had a similar issue when upgrading, I never created a new GROOVY_HOME to point to the new version of groovy...did you do that and also add $GROOVY_HOME/bin to your path?
The information on this page provides some good hints and general information, but nothing conclusive.
I know that javac.exe basically just launches 'sun.tools.javac.Main' from 'tools.jar' using Java. I also know that the Java API classes are stored in 'rt.jar' in 'jre/lib' under the JDK. Is this where 'javac.exe' loads the Java API classes from?
I'm wondering about this scenario in particular: suppose I installed jdk1.6.0_17, and later on I installed jdk1.6.0_25. If I run 'javac.exe' from jdk1.6.0_17, will it load the Java API classes from 'rt.jar' in 1.6.0_17 or 1.6.0_25?
The reason I want to know all of this is I'm in a situation where I know the code I'm compiling is going to run on a particular (not most recent) version of Java, and I want to compile using the same exact version of javac and the Java API to ensure compatibility.
By default, classes are compiled against the bootstrap(the runtime classes in rt.jar, internationalization classes in i18n.jar, and others) and extension classes of the platform that javac shipped with.So Yes If You run 'javac.exe' from jdk1.6.0_17, will it load the Java API classes from 'rt.jar' in 1.6.0_17 not from 1.6.0_25.
But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation.
See more at : Cross Compilation if you want to use
Set the JAVA_HOME environment variable to the desired JDK. Also change your PATH environment variable to contain the desired JDK bin directory.