1

I am a .NET developer who decided that mono is a little too buggy and not right for my project. So I started learning Java...

One of the problems I face at the moment is not knowing how to add references to external libraries. Like how you add references to dlls in .NET.

I realise this may vary depending on the IDE... I am using Eclipse at the moment.

I also wanted to know if Java/Eclipse has a package manager like NuGet for .NET?

Thanks in advance.

K-Dawg
  • 3,013
  • 2
  • 34
  • 52
  • You need to learn JNI... – Juned Ahsan Jun 20 '15 at 12:47
  • Fantastic... thank you I will look at that now! – K-Dawg Jun 20 '15 at 12:48
  • have a look at http://stackoverflow.com/questions/2824515/how-to-add-external-library-properly-in-eclipse – SSH Jun 20 '15 at 12:48
  • Thanks SSH... I wasn't sure about reference as a terminology for Java. I mean I thought that it may have a different meaning in Java than it does in .NET. That is why I didn't look at existing questions. Thanks for confirming this for me... I will have a look at the question now. – K-Dawg Jun 20 '15 at 12:51

2 Answers2

3

Use Gradle!

Gradle is a lot more light weight than maven and incredibly more flexible. In fact, the configuration files are Groovy code! No verbose XML, you can add custom functions and more. I used it for a large web app and it was light years from Maven (which I had previously used extensively). It uses the Maven repositories to fetch dependencies and it works with multi-language projects in case you ever wanted to do that. Gradle is also the default build tool for Android.

Here's an example config (pasted from this, untested!):

apply plugin: 'java'

repositories {
  mavenCentral()
}

dependencies {
  compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
  testCompile group: 'junit', name: 'junit', version: '4.+'
}

If you are using Eclipse, just add the line apply plugin: 'eclipse' at the top and Gradle will integrate perfectly with Eclipse by generating Eclipse project files (I haven't used Eclipse in years but I believe there are also Eclipse plugins to monitor changes to Gradle files and update Eclipse config on the fly). Gradle also has integration with IntelliJ in case you decided to switch.

Giovanni Botta
  • 9,626
  • 5
  • 51
  • 94
  • Grazie Mille Giovanni, I really like the sound of Gradle however at this point I'm going to look at Maven purely because the job sites here in the UK have more contracting roles for Maven at the moment. However I will certainly be looking at Gradle next as I think that it could replace Maven in the near future. – K-Dawg Jun 20 '15 at 13:51
  • Honestly I'm surprised anybody still uses Maven. XML config is a nightmare and it's very inflexible. Anyhow, once you understand Maven concepts it's easy to migrate a Maven project to Gradle later (I can't say the same for the opposite). – Giovanni Botta Jun 20 '15 at 13:57
  • I've put Java down for a moment to focus on C++. I'm making a multi teir hobby project that will use C++ for core (for performance). I want to host a web service using Java which will report the status of the C++ application. I will take a look at both Maven and Gradle when I revisit. – K-Dawg Jun 20 '15 at 22:37
2

Use maven

it's similar to (and for my opinion better than) NuGet. it's based on a public repository, and you manage your references in an xml file

Each project of yours (similar to .net project) will have a pom.xml file that going to look like this:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-module</artifactId>
  <version>1</version>
</project>

And in this file you manage the references (a.k.a dependencies)

for instance, if you wish to add this dependency - http://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.4

you will need to modify your pom.xml like so:

<project>
  ...
  <dependencies>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>

  </dependencies>
  ...
</project>

and that's it (probably the eclipse plugin will look up for you and you will be set)

One more thing ...

Iv'e also moved from .net to java about 1.5 years ago, what i can honestly recommend you to use intellij idea instead of eclipse

  • fully supporting maven, 0 configuration required
  • best learning curve (it literally ask you from which IDE you came from and adapts the keyboard shortcuts!)
  • simply awesome
Community
  • 1
  • 1
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129