Packaging a particular version of java with my code - java

I've built a standalone Java Maven app. I need a particular version of java for running my code e.g. 1.8.0.155. My target environment has an older version. E.g. 1.8.0.45.
For various reasons I'm unable to get the target system to update their version of java.
How do I just bundle a version of the jdk along with my jar?

What you're looking for is how ot create a self-contained application, this link is how you do it without any third part assistance. Another option is Launch4j, a third party wrapper.

Related

Testing for Java SDK

I am writing an application in Java. Does a Java SDK have to be installed to run the application from the command line? If so, can I package the SDK with the application to be installed when installing the application?
From Java 9 onwards you can use jlink to produce a custom JRE for your application. The JRE includes a copy of the java command and (only) the libraries / classes that your application needs. It will be platform specific.
From Java 14 onwards, you can use jpackage to produce (platform specific) native executables for Java applications.
There are also 3rd-party tools that can generate executables, and third party installer generators that (in some cases) can install Java for the end user.
Note: if you take the approach of distributing your application as a self-contained JRE or native executable, the user no longer has the option of updating their Java to address security related issues. It becomes your problem / responsibility ... as the supplier of the software ... to make available in a timely fashion application updates that incorporate the new Java releases with important security patches.
If you use something like GraalVM to compile a native binary, then there is nothing more you should need for a simple application (meaning, nothing is tried to dynamically load classes at runtime with reflection)
Other than that, the Java JRE is required, and can be included as part of an application package; for example, IntelliJ or Eclipse IDE come with their own JRE.
Thanks everyone for your input.
After doing more research I found that by using a jdk greater than 8.?, it is possible to bundle everything an application needs in the deployment process.

Java-Maven-IntelliJ: How to define a "portable" JDK that is bundled with the project as the SDK/JRE to compile and run?

UPDATE: Looks like it's not possible yet: https://youtrack.jetbrains.com/issue/IDEA-240044
I'll update the question with an answer, once this issue is resolved (this way or the other)
I have a super-special version of the JDK customized to compile and run a desktop client I am providing as an IntelliJ project (with source).
Users of my client can't get it to work with the Java they have installed on their work stations by our corporate IT.
On the other hand, they need that standard Java to run other things. The custom JDK is not good for running the other Java applications our corporate requires (so, I can't just have my JDK as their system-wide JDK).
Also, the work stations of my users do not support containerization.
So, I am thinking to bundle my JDK with the project and configure it to use that SDK. This is going beyond just preparing a "setEnv.bat" script with "JAVA_HOME=/xjdk" for many reasons, like being able to debug using the IDE, when the IDE is debugging code compiled with the special JDK...
I know IntelliJ has places to set up the JDK and JRE but not sure how to do this in a "relative path" way and such that will run on both Mac/Win without them having to configure the project for the absolute path of the bundled JDK?
Assume the project structure is something like this:
ProjectFolder
|_ src
|_ xJDK
What IntelliJ/Maven elements do I need to set to get both compile and run using xJDK?

Is it possible to configure part of an Eclipse Java project to use a different JDK than the rest of the project?

I have a Java project in eclipse 4.5.2 that is compiled using the Java 1.7 JDK. I want to change part of this project (one package nested roughly 6 levels deep) to compile using the Java JDK 1.8. Is this possible?
I wish to do this because the branch of the product this project represents has already been released, but we want to update part of our testing code so we can use a more recent version of Selenium.
You can not use different Java Versions in one Project. the only way is to make different Project.
You cannot do that through eclipse. Because Eclipse has option to select JDK by default or you can use it project wise only.
Since Java has full backward compatability, therefore you can use newer version on whole project without any problem.

java.lang.NoSuchMethodError: jodd.Jodd.init(Ljava/lang/Class;)V

I am trying to use the Jodd-http version 3.6.6 library in a simple application. The application runs fine on a test machine which has java 1.8 installed but when I try to run the same application on another machine with java 1.7 it throws this excption.
java.lang.NoSuchMethodError: jodd.Jodd.init(Ljava/lang/Class;)V
is this version of jodd-http is not compatible with java 1.7?
Jodd modules are distributed in two flavors:
1 .as a single bundle jar, that contain all Jodd modules in one distribution archive.
separate jar for each module.
So Jodd may be used on any platform where there is a suitable Java 7+ runtime environment.
This shouldn't be related to java version, but to existance of jodd libraries - are you sure you have jodd-core jar in your classpath?
Because jodd-http can't work without jodd-core:) And from your exception it looks like only jodd-http jar is present in the classpath; but not jodd-core.
Can you check this please?
I don't know if you use maven repo (jCentar or Maven Central), but it would be good so all this dependencies can be loaded automatically.
EDIT:
Check httpclient example in the https://github.com/oblac/jodd-quickstart
EDIT:
Check the classloaders - if they see the Jodd class (or any class from jodd-core); maybe the classloader for some reason dont see it; or there are multiple different versions of jodd-http on the classpath.

How do I control what JRE version is bundled with my application?

I'm considering bundling a JRE with my Java application. I'm using Launch4J. Looking around stackoverflow this seems easy enough to do. What I've not seen any information on is where I get the JRE from in a controlled manner.
I'd like to be able to control from a single place what version of the JRE is bundled. I don't want to be manually updating/installing JRE's on n number of build machines each time we decided to use a different JRE. Placing the JRE under source control seems the most logical option. Our build is done using maven, I assumed there would be some kind of maven plugin that would download a configured JRE version and put it in the target folder for you.
So, what is best practice to control which JRE is bundled with my app?
check the Maven enforcer plugin http://maven.apache.org/enforcer/enforcer-rules/ and in that check for requireJavaVersion http://maven.apache.org/enforcer/enforcer-rules/requireJavaVersion.html . this will add checks to the build that fail when the inapproriate JRE is used.

Categories