How to properly reference JRE in Maven? - maven

In our application, we're going to package the JRE as an embedded DLL (to avoid typical Windows issue).
As our project is a typical Maven citizen, I would like to include that JRE as a Maven dependency, to use it later. But is there such an artifact available? And if not, what could be the preferred way to package it?
zipping the whole JRE folder and uploading it to our Nexus?
use a "magical" artifact?
any other solution?

I think this was already touched here
Also if you are on Linux, then you can use RPM solution for application/server, but it is the solution more for deployment and not development.

Related

Is there a way to put all external libraries into one folder?

For example, in the picture I have a 1.8 folder and a separate maven folder. Is there anyway that I can put the jsoup.jar in the maven folder into the 1.8 folder in Intellij? In other words, is there a way to have ALL my external libraries only in that 1.8 folder? Thanks!
Do not manually manage the dependency in IDE when using a build tool like Maven or Gradle etc.
Regarding the two folders of libraries displayed in IntelliJ
<1.8> folder is from the JRE which is required to run any Java application.
Maven is generated based on the dependencies from the pom.xml.
Note: The folder displayed in IntelliJ is a logical representation not an actual folder in the filesystem.
Is there a way to put all external libraries into one folder?
Technically you can put all the dependency in a single folder and configure your IDE to load the libraries from that folder but in your case you don't need to do that maven will take care of that.

How configure Maven to Work Offline? Complete solution

I need to configure maven to download the dependencies to a directory within my project so that I can copy my project to another PC without internet access. I have found the -o option and the "dependency: copy-dependencies" plugin, but nobody explains how to consume those dependencies later. What would be the way to download the dependencies and then consume it on a PC without an Internet connection?
Maven caches downloaded dependencies (and plugins -- just having the project's dependencies won't necessarily be enough depending on the pom structure) in ~/.m2/repository. If you build your project, then clone the ~/.m2/repository directory as well as your project to another machine, you should be able to build in offline mode with all dependencies available to use.
The dependency:copy-dependencies is pretty useless for the task you try to solve. You usually need much more to successfully build a project.
You can use a dedicated local repository for you project (this can be set on the command line), so that you can copy that (without the content coming from all the other projects).
But if you are in a company, the recommended way is to set up a Nexus/Artifactory server that manages your dependencies. Then you don't need internet access to build, but just access to that server.

Can I force Maven to verify downloaded jars?

I'm having a lot of problems lately with Maven 3.5.0 downloading corrupted JARs.
I don't know why, it could be a problem with my workplace's network, the repos we use, or just my computer. Anyway, usually it's easy to solve them, I just need to delete the jar from .m2/repository and force a new download. But it's making me waste a lot of time, specially because sometimes I can't tell there is a problem at all until I'm already deploying the war to the server.
Is there any command prompt, or a parameter I could add to my settings file, so that Maven would check the integrity of each downloaded jar and pom, and redownload them automatically if needed?
As far as I know there were some bugs in Maven 3.5.0 that causes corrupt jars to be uploaded to your Maven repository. I would suggest you update to the latest Maven 3.5.x version and look if that fixes your problem, because I think Maven always verifies the downloaded jars.

Opencv in Maven Project

I have a question please,when using opencv in a Maven project,do I need to install opencv in my computer ?
I've added the dependency in pom.xml and the dependency was added but when running the code it said no opencv in java.library.path. It needs to specify the dll path
Thanks for your help.
"When using opencv in a Maven project, do I need to install opencv in
my computer?"
Yes, you do.
When adding dependencies you are telling the compiler where to find the library you want to use. You may not need the library to be accessible from your computer, but the files definitely need to be accessible from your project directory.
Links that may help:
Maven: Introduction to the Dependency Mechanism
Understanding Dependencies

Maven: Include 3rd party jar with bundled libraries that conflict with other dependencies

I've been looking for the answer to this for a few days and have turned up empty.
I'm devving a Confluence plugin that integrates with a 3rd party app. This 3rd party app has a nice REST API and they even provide a Java SDK (yay!). Except.....the Java SDK has bundled a version of Jersey (1.18) that conflicts with Confluence's forked version of Jersey (1.8-atlassian_15). The SDK was not released as a Maven jar (or at least there's no pom.xml included). There ARE other pom.xml in the jar's META-INF for the dependencies it uses, but the SDK itself is just released as a jar download by the vendor.
So as I've done in the past, I mvn install:install-file the sucker with my own groupId and artifactId, thinking it'd be fine. Intellij recognized the library, everything compiled nicely, and then I tried my test call to the REST API. This is when it threw an error that made it evident that there's a conflict between the versions.
SOOOO. Is there anyway to get around this? Can I "sandbox" the SDK jar in a way the executes code in its own deal without being exposed to the nasties of Confluence's builtin version of libraries the SDK uses? I have a feeling that even after the Jersey dependency is resolved (if that's even possible) there will be other issues....The SDK also bundles the specific version of Jackson, Swagger, etc. with it.
I attempted to decompile the jar and include the decompiled code in my project, but that just had all of issues I'd rather not deal with ever again.
I have reached out the SDK devs to see if they could release a more maven-friendly release, but I'm not hopeful this will be done at all, and even it is, their release cycle is much different than my own requirements (read: I need a solution now). This is my last-ditch effort before rewriting the REST client from scratch.
Can I "sandbox" the SDK jar in a way the executes code in its own deal without being exposed to the nasties of Confluence's builtin version of libraries the SDK uses?
Sure you can. Often-used way to do this is to use Maven shade plugin that transforms an existing jar to a shaded jar, using another package hierarchy and getting rid of the package naming conflict. See also the documentation about relocating packages. I suggest you use that - that's what I've done in cases like this (though I haven't done confluence plugin development, but it should be the same thing as with other platforms).

Resources