This sounds dumb but is there anyway for me to specify dependencies for my Java project like how I would in a package.json file so that someone else who was to download the project code from my GitHub repo, would be able to run it without any errors or missing libraries?
I have never tried using external Java libraries before, such as apache commons. The most I ever used was JavaFX but on a personal project level. My main concern is that if I were to push my code up to the repo and have someone else clone it. It might not run properly as the imported libraries are not downloaded.
Is there something similar to package.json dependencies where the person who runs the code would automatically download all dependency libraries and have it run on their system?
You can use Maven or Gradle for this purpose. Maven has pom.xml where you can specify all your dependencies. Similarly gradle has build.gradle which does the same job.
I have been trying to use the vget library/api to make my own youtube video downloader. The vget library can be found here: https://github.com/axet/vget
I have downloaded the zip on github and I imported the project into eclipse. However, I am confused to how I am supposed to properly use this API. Should I make a completely new project, and import the classes that I need or do I put my own source files in the project of the api?
I have read other threads concerning this problem. However, they all mention how a api is typically packaged in a JAR file, but in my case it is just files and classes. So I am confused to how I should properly use this api.
The vget project is a maven project. You can see that because it has a pom.xml file in the root folder of the project.
To use it, you don't even need to download the source, because the compiled jar files are already stored in the central maven repository. You can find more information about this here:
http://mvnrepository.com/artifact/com.github.axet/vget/1.1.23
(in general, you can use the http://mvnrepository.com/ site to search whether your library is available on the maven central repository. If it's even a mildly popular library, then chances are that it is)
What you need to do is to make your own project a maven project.
Here's a "5 minutes" starter guide that describes how to do that.
When you've done that, you just add the dependency on vget to your pom.xml file in the <dependencies> section:
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>vget</artifactId>
<version>1.1.23</version>
</dependency>
Since you are making use of a 3rd party software, and not extending it with your own logic, the way to go is to create a new project, which references the 3rd party software.
You then construct your application and make it do whatever you need it to do. When it comes to using logic which is available within the 3rd party logic, you would then simply delegate that call to the 3rd party library.
I have seen on the link you have provided, that this is a maven project. You have to execute a maven package command, or maven install, so that the jar file will be generated.
With this jar follow the Bill's instructions, and add it as external library to your claspath.
When you do this, you will be able to invoke methods of that api.
Let us know if you need some help doing this in eclipse.
If your project is a maven project, you can solve dependencies problems just adding the dependency written on Readme file to your pom file.
The easiest and most automatic way is to use something like maven, ant, or gradle, that will automatically download and put the jars in to your classpath if they are in the central repositories. For example, in the maven configuration file(pom.xml) you can add this to the dependency list:
VGet Maven Repository
These build tools also allow you to add external jars if needed.
If
I would suggest you get familiar with Maven. At the bottom there is a Maven dependency you just have to include into your pom.xml, and then you can use the extension immediately.
Maven is a build platform which organizes your project in a technical way (convention over configuration, e.g. code is in /src/main/java, tests are in /src/test/java). The proper way is it to create a Maven project in Eclipse (you have to install the plugin and download Maven as well) and put the dependency
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>vget</artifactId>
<version>1.1.23</version>
</dependency>
into your <dependencies> inside your pom.xml. After adding it, you project recognizes the additional package automatically.
Nobody tinkers by adding libraries manually. It's actually not professional to work without a build platform like Maven or Gradle.
I'm trying to use MaxMind's GeoIP2 database, I've added the jar to my Java build path and configured it with Javadoc and source but when I run the program I get a NoClassDefFound error, which according to this stack overflow answer is because I need to add the dependencies, but I have no clue how to add them in eclipse, I tried extracting the jar files and adding them to the build path but that didn't work, how do I do this in eclipse?
Thanks for any help.
In eclipse you have to create a new maven java project. If you dont know maven you can get informations here:
apache maven startsite
how to install maven
Afer that you are able to configure your dependencies in your pom.xml file. Which is the configuration file for maven.
You can find some dependencies for your usage here:
maxmind documentation
The include of the dependency would look like this:
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>v2.3.0</version>
</dependency>
But first, you should look at maven installation and using. It will make your life easier by handling all the necessary dependencies you will need in this project and in all of your other projects in future.
You don't need to use Maven
For Eclipse, you may use Rightclick on Project > Properties > Java Build Path > Add External JARs. Select the JAR file you downloaded.
There is standard Java WebApp project. I need to use Maven to build/compile/deploy project to online server. There is an option to create new maven module module or to import project using pom.xml. Following probaby won't work because:
Project doesn't have maven project and pom.xml
Creating new maven module probably would mess up my existing project structure.
How to add Maven support to existing Java WebApplication in IntelliJ 12?
UPDATE:
I selected Add framework Support... > Maven. Generated pom.xml at project's root. Added maven-war-plugin. The following structure I have got. Is it any good / correct?
You should use maven standard project structure for maven applications. However, if you cannot change it, then you have to tell Maven where to look for specific files. Consider:
Using maven using non standard directory layout
Standard Maven structure
Also here are some interesting things to remember: http://wiki.jetbrains.net/intellij/Maven_FAQ
I'm trying to use JNI, and I'm using the maven-nar-plugin to package up the C++ code into a NAR. Now, I want to include this code in another Java project. How do I go about doing this properly?
It depends on how you want to use the dependencies created by maven nar plugin. From the documentation,
Other maven projects may specify
dependencies on these nar files using
the standard maven dependency
declaration. Nar files get downloaded,
unpacked and installed in the local
maven repository, just like jar files
are (apart from the unpacking).
The FAQ has a section on how to load the native library from java code.
Hope these help.