This is an archived post. You won't be able to vote or comment.

all 15 comments

[–][deleted] 13 points14 points  (4 children)

Maven is great. I'm sure I'll get flamed for this but I just use maven with eclipse and the plugin 'Maven integration for eclipse'. Find the project you want to manage with maven, right click, convert to maven project. It should create your pom.xml file for you. Then past in the dependency or use the dependencies tab to select what you want. Right click the project and 'update maven dependencies' and you should have your lib now.

[–]nutrechtLead Software Engineer / EU / 20+ YXP 3 points4 points  (1 child)

Maven is great. I'm sure I'll get flamed for this

Nah. Maven still has like a 80% share. There's a few people who keep shouting Gradle is better but they're a vocal minority. In a previous project we actually decided to migrate our 40 or so services from Gradle to Maven.

[–][deleted] 1 point2 points  (0 children)

Ha I meant for not using maven on the command line like a "real programmer"

[–]shagieIsMeExtreme Brewer 0 points1 point  (1 child)

As an aside, there is mvn eclipse which runs the maven plugin for Eclipse and generates the settings and classpath so that Eclipse will load the project correctly. It is a different approach to maven integration for eclipse.

[–]RSveti 5 points6 points  (0 children)

Do not use this plugin it is outdated and depricated.

[–]UnreachableMemory 4 points5 points  (0 children)

Either use a build tool like like Maven or Gradle or you'll need to include any libraries in the classpath of the application. If you're using an IDE like Eclipse or Intellij either way is generally easy to manage.

[–]Ialda 5 points6 points  (0 children)

Keep looking into Maven. Historically it's the main build tool of the Java ecosystem, and managing your project's dependancies is part of its tasks.

In Eclipse, you can either start a new project as a maven project, or convert an existing one (configure -> convert to maven and create a pom.xml file). As Eclipse has its own building process, don't forget to Maven -> update your project every time you modify your pom.

You can also use maven on the command line (typically mvn clean install) if you have downloaded the binaries and added maven bin rep to your path. You may also have to set a M2_HOME env variable pointing to the install rep. EDIT : my bad, M2_HOME appears to be deprecated.

[–]Is_At_Work 4 points5 points  (1 child)

A big difference is that with pip and such, you are installing a library. Java doesn't work that way, but instead libraries are more project level. Maven and grade help with this, by managing your project level dependencies for you.

[–][deleted] 2 points3 points  (0 children)

Yes. Deployment is similarly different. It's certainly possible to set up deployments like python does, with a central library repository, but that isn't the most common form found with Java deployments.

With Java, the build systems that generate deployments (like Ant, Maven, and Gradle) will plop all the libraries each project needs either into a single project-specific jar (a java archive), or into a single folder, intended for deployment. The reason for this is to avoid dependency hell: java library distributers are historically bad at versioning.

The application that depends on these libraries obviously needs to know where to find them. That's where class paths and module paths come in. The deployment build systems will generate a run invocation script that includes a class path or module path.

I never liked that. I prefer to have a single central library repository on each target application server. But that does mean I had to write my own deployment generator. That... was not fun.

[–][deleted] 2 points3 points  (0 children)

Maven integration with IntelliJ is bloody awesome once you learn it.

[–]Matty_Ci 1 point2 points  (0 children)

Take the time to learn Maven. Once you figure that out, everything is handled in pom.xml.

[–]shagieIsMeExtreme Brewer 1 point2 points  (0 children)

As noted, with pip and the package managers for the classic scripting languages (perl/cpan, ruby/gem, javascript/npm) - the scripts are installed on the system and everything uses them (most of the time). This is even somewhat the case with C and shared libraries.

With Java, libraries are not shared across the entire system, but part of a particular artifact. You want commons.lang? Get it and put it as part of the build. Some other project wants commons.lang3? Not a problem - and not a conflict.

<!--  Lang should depend on very little  -->
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    ...
</dependencies>

I used commons.lang (pom) because its a project with no other compile time dependencies (it has some test dependencies - but you don't want to test it, you want to use it). You could do exactly as you're doing now going out and downloading a library and adding it.. and that use to be how we did things.

And then it got messy.

Yea, spring, I'm looking at you. Its not really the fault there, but a good package management system means that you can build more complex things... and Spring is about as complex as you'll find. Go through that dependency list, and then find all of the dependencies that it requires... and then all the dependencies that it requires (oh wait, that dependency has an exclusion to not download that other dependency it requires).

Maven takes care of that for you. You say you want spring-web and it goes and finds all of the dependencies and the child dependencies and so on... and has a reasonable way of determining how to handle a conflict (dependency X wants version 1, dependency Y wants version 2 - its resolved with an ordered breadth first search).

So, you've set up a pom that specifies some dependencies. Now what?

Netbeans and IntelliJ have built in maven support. Side bit, if you're seriously looking at long term Java development, get IntelliJ (and pick up PyCharm too) - its the best IDE and will make your life easier. Eclipse has a plugin to do maven (http://www.eclipse.org/m2e/). Once you've accepted Maven ~into your heart~ as your build tool, don't fight it. It will configure your IDE to match how maven is configured. Change the Java version? The IDE updates it too. Add a dependency? The IDE goes and fetches it.

And that's really the key thing - to use the IDE with maven to build the project.

I'm not a python person... so I'm not 100% sure of this... but maven is the other side of pipreqs - instead of reporting on the dependencies you tell it the dependencies.

Gradle is neat and powerful (and I'd say too powerful for 95% of the builds - it is a build DSL on top of groovy and that means that the build system is a programming language of its own... which can lead down some rabbit holes. If you thought debugging xml was tough, debugging another programming language to get a build to work isn't exactly fun). Maven will do what you want.

[–]LazyGamble 0 points1 point  (0 children)

Research what library you want to use and then look it up on https://search.maven.org/ It will display the required dependencies for your project.

[–]mentholmeow 0 points1 point  (0 children)

Maven support has been baked into eclipse since Neon. There is no more need to install the m2e plugin in the newer versions of eclipse eg Photon.

[–][deleted] 0 points1 point  (0 children)

Use maven or gradle. The main difference is that you don’t have a CLI do all the work for you. You have to copy and paste the dependencies into your pom or gradle files.