Dependency management in java - java

I implemented a tool and I want to make it open source.
The problem is that my tool has some dependencies (binaries/. jar files).
How can solve this problem, so that the person who downloads my source code, for example to extend it to a new feature, doesn't have to care of the dependencies?
Should i write the dependencies in the MANIFEST as relative path, relative to my source code or something like that?

You can convert your project into a maven project and then put your source code to githup or something similar. If your dependencies are not available on the web but instead your other projects, you should also place them on the web so maven can download them for anyone who wants to use.

Related

How do I make use of a third-party java library github project?

When there's no obvious compiled jars provided on a github project page, I've been downloading the clear code and kludging them into subdirectories in my codebase to make use of third party code (or, most of the time, just not using the code at all). I know that's not the right way to go about this; what is?
There's a popular post about importing github projects into Eclipse:
Importing a GitHub project into Eclipse
...and I've recently learned how to make my own projects depend on one another. Is this the practice, then, to fill up your workspace with projects you're not actually going to work on, so that you can declare dependencies? I remember making dependency references to web resources in the past (itch.io, maybe?) in some configuration, where I didn't have to go download the code. Is there a more elegant solution like that for github?
I'm using Eclipse, and the current library I'd like to use is: https://github.com/FasterXML/jackson
If you're trying to just use FasterXML, the jars are hosted on MvnRepository as well as a lot of other projects.
If a github project's artifact isn't available on MvnRepository or some other online repository you could potentially clone, build the war/jar file yourself, and then manually import it into your project instead of copy and pasting code directly into your project. This would give you access to the library.

Import Java source code as library in IntelliJ IDEA

I've just started Android development coming from a strong web and iOS development background. One thing I don't really understand is how to best import third party open source projects in my source.
In web development most projects has a bower package and in iOS most open source projects has a podspec that makes it really easy to import. But I don't see this as much in Java projects.
So, now I want to use jess-anders/two-way-gridview. What would be the best way to get this into my own app. I would very much like to avoid having to mix the third party source code and res files with my own.
I use IntelliJ IDEA.
If I understand correctly, then what you need is Maven, which is used for dependency management in Java projects.
You define your dependencies inside a pom.xml file. Here is an example of such pom file (see the < dependencies > tag ).
Generally, when you need to use a 3rd-party library, you look it up in the Maven Central Repository, from which Maven looksup by default when you specify a dependency, and copy the < dependency > element into you pom.xml file.
NOTE: I don't know why, but right now the Maven site is down. You'll have to check back later. In the meantime try looking for some tutorials on google.
If you need to import libraries which aren't in the Maven Repo, then you need to go to File>Project Structure>Libraries and click on the '+' symbol and add your .jar files from the your filesystem.
You need to do this on every machine that needs to work on this project, and also include the jars in your final apk. I do not konw how to do the latter.

How to deploy jar in eclipse maven remote repository?

i am working with others developers on eclipse project. The project is hosted on SVN. I wonder how I can add JAR file to the dependencies.
Thank you.
Could you be more specific...
What do you want to do? Add some jar files to your SVN repository?
This is strange...cause you have to share on SVN just the project not compiled, to be able to evolve the code line wit your team...but not the jar files...they could be published on a remote repository like Artifactory or Nexus but no under SVN, for me, it does not make sense.
Not on SVN...but maybe, simply, i don't understand your question...
Try see this -----> Java jar files into a repository (CVS, SVN..)
First, what do you mean I wonder how I can add JAR file to the dependencies.?
Do you mean that you need to add a jar to the compile classpath in Eclipse? Do you mean there's a jar that you need to access whether locally built or from some open source project somewhere on the web?
Is this a jar that Project "A" builds and Project "B" needs?
You can simply check the jar into Subversion. That way, when someone checks out the project, they have the jar. This is a common way to handle this issue, and it's known as the wrong way.
The right way is to use Ivy or Maven, and then use a third party Jar repository like Nexus or Artifactory to host your locally built jars that your projects need. Then, use m2eclipse or IvyDE to connect your repo to your Eclipse project.
Doing things the right way is a bit more difficult, and you and your developers will have to learn Maven or Ivy and how it works. In the end, it makes your development faster and easier. Plus, knowing something like this can help your future career.

how do I add open source API code to an eclipse project?

I have to write a java application which I'm putting together using eclipse and it relies on open source code. This application needs to be self-contained, meaning that I'm supposed to create a jar file that has no external dependencies.
I can use the open source code when I reference the jar files in the project's build path, but the idea is to have the actual source code as part of the eclipse project, side-by-side with my code.
The source code can be found here: http://hc.apache.org/, but when I import an existing file system into my project I can't quite get things to work. The packages end up with the wrong names, breaking references, and I can't do anything. Notice that the folder containing the source code has this structure:
httpcomponents-client-4.2.3\
src\
httpmime\
httpclient-osgi
httpclient-contrib
httpclient-cache
httpclient-benchmark
httpclient
fluent-hc
each of those subfolders has src/main/java/org/apache subfolders.
Can someone please explain how to do this? Am I supposed to import everything one java file at a time?
Use a tool like OneJar, FatJar, JarJar, etc. to create a single-jar application.
As Charlie mentioned, the Maven Shade plugin is another choice, particularly if you're already using Maven. If you're not, consider it or another transitive dependency management tool.
Some tool should be used, IMO, and it's more important the more dependencies you have.
Alternatively you could use a jar class loader and include the jar file in your artifact.
I would most definitely not include the source of dependencies in your own project.

Resolving Netbeans Library conflict, when using Subversion

I have a Netbeans Java Project under Subversion (svn). This is shared with another guy working on the project.
The project requires an external library that we have as a jar file. Now, when either of us makes a change and commits it, the project's library dependencies fail as we have different paths for the library ( as we are working on different machines the location of the jar file is different ).
This means that every time I update my repository, I have to resolve library dependencies.
Is there a way I can prevent this?
1st way: You can use NetBeans Library support.
Go to Tools->Libraries, and new Library with your jar. Name it the same way on both machines and include to your NB project as Library rather then direct path to jar.
2nd way: use relative path.
Agree on having jar located at ../lib/foo.jar and use this path in NB project
3rd way: use property file.
Add file named, for example, build.properties but don't commit it to svn. So both of you will have different local version of that file.
Content should be something like next:
myproject.library.foojar=C:/foopath/foo.jar
In your build.xml include this file:
<property file="../build.properties"/>
In your nbproject/project.properties find a reference to the jar -- it will look like:
file.reference.foo.jar=C:/foopath/foo.jar
change it to
file.reference.foo.jar=${myproject.library.foojar}
Also you may want to add build.properties into ignore list for svn to avoid commiting it.
I recommend you to use Maven to control library dependencies(jars). It is easy to use and NetBeans has a module to use it easily.
Maven download all the dependencies you declared into a local repertory so you don't need to worried about managing libraries, Maven do it for you.
Also with this module you can search libraries in the Maven repertory(Has a lot of java librarys) only you need to type the name and maven download it for you.
Here there are some links for how to use Maven With NetBeans:
http://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
http://today.java.net/article/2009/10/14/working-maven-netbeans-671

Categories