Portable App with Maven launch4j and NSIS - java

I would like to be able to use Maven to automatize the building process of my application.
The application is a runnable jar that is wrapped with a local copy of a jre using launch4j, which is then included in a NSIS script I have to build an installer.
I found a launch4j plugin for Maven that makes me able to wrap a jar with a local jre like I want to, but the thing is that I'd like to download the proper jre in a local directory when running the Maven build process.
The reason is that for compatibility reasons, the application will be using the jre 1.6 but that could change in the future.
Is there a way to make Maven download the jre corresponding to the application setting like it would download a dependency ?
Like if I change the configuration to use the 1.8 jre, Maven would download automatically the jre 1.8 in the directory I want.
Is this something possible to do or do I have to download it manually and add the jre directory to my project (or something else that I didn't think of) ?

I found a launch4j plugin for Maven that makes me able to wrap a jar
with a local jre like I want to
How did you achieve this, since launch4j doesn't wrap the jre, nor bundle/embed?
It only lets you specify a
<path>relative_jre_path_to_your_jar<path>
to a jre. You need to zip your *.exe(which results from launch4j execution) with the jre, and distribute it.
Regarding the controlling of jre versions, you can deploy jre artefacts(different versions) to your maven repository and use the dependency mechanism.

Related

How to specify Java version for Gradle buildSrc?

My build.gradle uses a custom task, which I defined in the buildSrc/src/main/java directory using Java 11. Now, I need to build on a different machine which only has Java 8 installed, so the Gradle build cannot even configure because it complains of errors in my custom task. Of course, I could install Java 11 in my home directory (since I don't have root privileges on this machine) and run Gradle with a custom JAVA_HOME, but is there a way that Gradle could automate this process. That is, could I somehow declare the Java version required for buildSrc so that Gradle will download and use that version?
Gradle toolchains looks somewhat promising, but it is not obvious how this should be applied to buildSrc.

What is a possible, handy way to build a project with Maven which uses an embedded JRE?

I want my program to be usable by systems which do not have a JRE preinstalled.
What I'm a little bit struggling with right now is how can I tell Maven to use an embedded JRE and not the system JRE? Right now to build my application I'm using the maven-assembly-plugin along with the maven-nativedependencies-plugin to resolve native dependencies and the maven-jar-plugin.
My understanding in theory is somewhat of the following:
Copy(?) JRE into my project folder (e.g. a folder with java8)
Zip everything up (Somehow included in my build process)
Tell Maven to use the included JRE
User can unpack and does not need a preinstalled JRE
I assume that I somehow need to tell maven/my application to unpack that shipped JRE and use it? I already read about the Java 9 Deployment guide (I'm using Java8 though) and jlink'ed images, however all of it seems a little bit tricky and I'm not build process expert.
Could anyone share their experiences / thoughts on that topic?
There are few ways to build an executable image:
If you are on Java 9 you can use jlink to build an executable runtime image.
Use launch4j tool to include JRE e.g. as shown in this answer.
Include JRE as a Maven dependency and repackage with assembly plugin. Do note that this dependency is quite outdated.
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>

Create a distributable Eclipse bundle on MacOS

our company uses the Eclipse IDE with some plugins that are required to start our platform. I want to create a bundle for our Java developers that contains the latest Eclipse Java (Oxygen) with the plugins already installed.
So far I've installed Eclipse with
sudo cask brew install eclipse-java
which created an /Application/Eclipse Java.app.
After installing the plugins within Eclipse with Help->Install New Software the ~/.eclipse/ was created in my home directory.
Is there some way to zip these folders to create an distributable package of eclipse or am I missing other files/directories?
Is it possible to move the plugins in the installation directory as well?
Thanks for your help!
It is not advisable to use any Eclipse distribution that's produced by packaging tools. It's best to download directly from eclipse.org, for various reasons.
As for customizing an Eclipse "package" for distribution yourself, have a look at the Oomph project, which is designed for that exact purpose (and others). Oomph is what produces both the installer and the downloadable packages of Eclipse IDE releases. You can read specifically about Oomph authoring here.
You can use the official eclipse installer. There is an advanced mode to disable the p2 pooling. Then using this mode, everything will go into the eclipse folder. Afterwards you can zip it and give it to others. Of course you are always bound to the CPU Arch still.

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.

Do I need to install Java SDK if I have eclipse

I have been using Eclipse for 2 weeks and all programs are working fine.
But I have realized that I have not specifically installed Java SDK.
Is it normal or does Eclipse have its own compiler?
I need to test the JDBC MySQL connector and now I don't know where to copy that file because in my:
C:/programfiles/java
I have only one directory that is JRE 6.
Yes you're right. Eclipse has its own compiler so you don't need JDK if you are working with Eclipse.
There is some cases/plugins that are only working with JDK such as Maven. So if you are planning to use Maven (either from Console or from Eclipse) you will need to download JDK.
For your mysql connector, a common practice is to copy the jar to your project directory (or maybe under lib directory) and add it to the build path. Once the jar is in the location, you can refresh the workspace, right click, and select Build Path, add to Build Path.
You can download Eclipse with a bundled JRE, which is probably what you've done. But since it has its own compiler etc, it doesn't need the full JDK.
You don't need the JDK to use the mysql driver, though, you just need to add it to your project classpath in Eclipse. Some documentation suggests putting JAR files in the JRE/JDK's extensions directory, but this is a profoundly bad and outdated idea - don't do that. Use the classpath, via Eclipse's environment.
Eclipse has its own compiler and can run on a non-JDK JRE.
The usual approach to use a library jar, is to copy it into your Eclipse project inside Eclipse, and right-click-add it to the Build Path. The classes are then accessible to your own code.

Categories