Maven and regular Java can be used in single eclipse project - java

In Eclipse IDE, it is displaying as a Maven project and Java project. How different are they from each other. Can we make use of regular jars and maven jars in a single project? Else, have to use maven and regular java jars separately?

A maven project is a java (or scala) project which uses apache maven as dependency management and build tool. Normally, you don't need to add "regular" jars as almost every dependency is on the maven central (https://search.maven.org/) which you just add to your pom.xml, the actual jar is then automatically downloaded from the remote repository.
If you have a jar which is not on the maven central (i.e. e third-party jar or a jar from an own project), you can install this jar in your local (or enterprise) maven repository, see e.g. https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Related

Consume / import local fat jar as plugins in maven

I have recently used the Maven Assembly Plugin and also the Maven Shade Plugin in order to create a FAT JAR containing a specific plugin and its dependencies.
I did this because during the build phases our company uses private servers with no access to the internet so I can't depend on public repositories.
So I have this FAT-JAR-WITH-DEP.jar and to test if it works with my module, I removed the original plugin jar from the maven repo and pasted this instead.
I also removed its dependencies. the POM file remained the same.
What happens is that it still tries to download the dependencies because of the pom file.
How do I use a FAT JAR as a plugin that already includes it's dependencies?
Sorry, but building such a fat jar is not a good idea. You are trying to manipulate the "inner structure" of Maven.
If you want to use Maven in an offline environment, copy all the relevant plugins and dependencies to your company Nexus/Artifactory. The easiest way to do this is run a build once against a public repository and then copy all the stuff that was downloaded through Maven.

Quickest POM settings to turn an existing Eclipse web project in a Maven-managed project?

I'm converting an existing Eclipse-based web project to a Maven-managed one.
Since the project has lots of dependencies, many of which are custom (they're either internally made or they've been taken from sources that have no public repository), is there some 'magic' Maven POM setting that will let me load every jar from WebContent/WEB-INF/lib and make the project work as before right now, so that I can configure each dependency and do the necessary refactoring to turn it to a proper Maven project with a little more time and care?
I have already seen this question, but the project must continue to compile inside Eclipse, so - or at least I guess - it is not just a matter of using the Maven war plugin
What you want to do is called "installing" your non-mavenized JARs into your maven repository. This can be a local or remote repo that you host.
The command to install to your local repo is something like this: mvn install:install-file -Dfile=My-lib.jar -DgroupId=com.mycompany -DartifactId=My-lib -Dversion=1.2.3 -Dpackaging=jar
You'll want to review the various options for install to suit your project.
Once the non-mavenized dependencies are installed to your repo you can add them to your pom like any other maven dependency. They will be fetched from your local repo.
You will have to set up your own remote repo (like Artifactory) or install each plugin for every developer and CI server in your environment for others on your team to build the project. I strongly reccomend Artifactory, it makes it easy on your and your team to use maven and get dependencies.

how to use maven (eclipse keppler) on imported non-maven projects

I have existing projects that I wrote using Eclipse Juno on another machine, on that machine I downloaded the jars I needed (selenium, jxl, sqlite etc.) from the internet manually and then edited the build path to point to them. I need to move these projects over to a different machine which has Eclipse Kepler loaded. I thought I'd use maven to link everything up (with a view to retro-fitting the machine with Juno to use maven) so that as I jump between the two machines everything will be kept in order automatically.
I installed maven from the marketplace and ran the install:install-file command, but it won't run the program as it insists the jars it's looking for aren't installed (which of course they aren't, that's what I thought maven did).
Is it not possible to use maven in this way (get it to download and link up missing jars) for an existing project? Do I need to do it manually, and if so will I have created problems that I'll have to unpick by having tried this with maven?
If you're using the m2e plugin, you can turn on Maven dependency resolution by just right-clicking on the project and choosing Configure->Convert to Maven project. Make sure your project has a valid pom.xml file and set everything up properly in Preferences->Maven (proxy, user settings, maven installation, ...)
If you're not using m2e, you can use the eclipse maven plugin like this:
mvn eclipse:eclipse
This will call the eclipse goal of the eclipse plugin, and it will generate .project and .classpath files for you with all dependencies pointing to your Maven local repository.
As a side note, the install:install-file goal doesn't have anything to do with what you want to achieve, it's used to install an artifact (a .jar file) to your local Maven repository.

Library (jar) dependencies between github repositories

I can't figure out an appropriate way to structure git repositories to handle library dependencies between git repositiories.
I have a number of Java projects that rely on another, frequently updated project that's included in them as a .jar library. I now want to migrate them all to github.
Can I set up the projects in github so that whenever I push project A, then all other projects can pull the new version of projectA.jar automagically? They don't rely on any source files, they just need the latest libraray jar. Currently it's done by an ant script that tries to copy the latest jar from the other project at each build.
Changing your project over to Maven may be a big help; .jar files would no longer be stored in version control.
You would need to open project A, run 'mvn install' to produce the library files on your PC, and then you could use project A's libraries from project B.
Another alternative is to run your own Maven artifacts server, such as Artifactory, Nexus, etc... Project B would look at the artifacts server to see if project A's files are available.

Integrating a maven project into Eclipse

I have a maven module for validation which I must pass to a old version of Eclipse which has the Jrules API within. However there is not a maven plugin for this eclipse IDE. So I figured I would do a maven:install on the module and move over the created jar.
However when I try to import->Existing Projects into Workspace->Select archive file:
and point it to the jar no projects appear. I'm at a loss as to how I can move my maven module to the outdated eclipse, without having to grab the 101 jars required for the project and non mavenise it...
Surely their has to be an easy way to this or is maven will monolithic
Use the maven-eclipse-plugin to generate the .project and .classpath files for you:
mvn eclipse:eclipse
This will create the IDE metadata files which reference all of the JARs your project depends on from within your local maven repository folder.
Attempting to import the JAR that is built by the Maven build process into Eclipse using the " import->Existing Projects into Workspace->Select archive file" doesn't work because Eclipse expects to find a .zip/.jar file with the .project metadata files and the source code. Your compiled JAR likely contains neither.
I would recommend using the M2Eclipse maven plugin. Right click the project -> Enable Dependency Management -> Update Project Configuration
I have used eclipse:eclipse extensively and my experience is that M2Eclipse is not only better supported but works better overall.

Categories

Resources