Download project via Maven - java

All I want is the project file/jar for this project: http://thiagolocatelli.github.io/parse4j/
It says I need to do the following to obtain it:
Getting Started
Download the library manually
Maven
<project ...>
...
<dependencies>
<dependency>
<groupId>com.github.thiagolocatelli</groupId>
<artifactId>parse4j</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
...
</project>
I have never used Maven, do not really know what it is. Can someone advice me how I obtain the project file?

Maven is a dependency manager. Lots of information about it if you're interested - just use your favorite search engine.
You can also download the jar file directly from http://search.maven.org/remotecontent?filepath=com/github/thiagolocatelli/parse4j/1.3/parse4j-1.3.jar

Related

How to resolve import in Eclipse?

Im new in Java development and not familiar with various kinds of import (Maven, Git, etc), so I make it simple:
import com.google.common.collect.*;
import com.google.gson.*;
These two is not resolved in code Im inspecting, and I have no idea what kind of actions I should take neither what I should import to resolve it but it is probably some popular library.
Is there complete guide how developers import packages in eclipse (for example C# developers use Nuget, despite there is a ton of hand made ones), or they really use all this enormous import selector?
First of all Mavenise your current project and add the following dependency to it:
Goto: POM.XML after converting your current project to Maven project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
------Properties Here----
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0-rc2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
--------Add your Dependencies here, remember you have to add dependencies under <dependencies> here </dependencies> ----------
</dependencies>
</project>
Search for all dependencies here: https://mvnrepository.com/ , incase you need more dependencies to import.
How to mavenise your current Java Project:
In your eclipse just right click on Java Project and click Configure and you should see “ Convert to Maven Project ” option.
What is POM.XML
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Now, you can add a dependency in pom.xml.
If you use no dependency management tool like maven the simplest way is just download corresponding JARs and add them manually: http://www.oxfordmathcenter.com/drupal7/node/44
For GSON use this: https://mvnrepository.com/artifact/com.google.code.gson/gson/2.3.1
For the second dependency I suppose you should use GUAVA:
https://github.com/google/guava/wiki/UseGuavaInYourBuild
or this: https://mvnrepository.com/artifact/com.google.collections/google-collections/1.0-rc2
But actually better to convert your project to Maven project (as described for example here: https://crunchify.com/how-to-convert-existing-java-project-to-maven-in-eclipse/) so that you'll be able to use pom.xml for dependency management or Gradle (see configuring existing eclipse java project to build using gradle) and avoid manual JAR download

how to download dse.jar

I am trying to use DataStax Enterprise 4.6 to write a Spark application in Java and run
it in DSE's Spark analytics mode.
The code for creating a Spark context using DSEConfHelper:
SparkConf conf = DseSparkConfHelper.enrichSparkConf(new SparkConf())
.setAppName( "My application");
To use DSEConfHelper we need to import com.datastax.bdp.spark.DseSparkConfHelper
which is located in dse.jar.
In my pom.xml I have included the dependency:
<dependency>
<groupId>com.datastax</groupId>
<artifactId>bdp</artifactId>
<version>4.6.0</version>
</dependency>
But Maven cannot download dse.jar.
Please help me.
The reference for code for creating a Spark context is taken from:
http://www.datastax.com/documentation/datastax_enterprise/4.6/datastax_enterprise/spark/sparkJavaApi.html
Edit: This has been entirely superceded by the com.datastax.dse.dse-spark-dependencies artifact. Add it to your pom.xml:
<dependencies>
<dependency>
<groupId>com.datastax.dse</groupId>
<artifactId>dse-spark-dependencies</artifactId>
<version>${dse.version}</version>
<scope>provided</scope>
</dependency>
<dependencies>
<repositories>
<repository>
<id>DataStax-Repo</id>
<url>https://repo.datastax.com/public-repos/</url>
</repository>
</repositories>
See https://github.com/datastax/SparkBuildExamples for Maven, SBT, and Gradle example projects.
Original, outdated answer:
You have to manually install dse.jar as of right now. There are two ways of doing this.
Option 1
Install the JAR file using mvn install:
$ mvn install:install-file -Dfile=<path-to-dse.jar> -DgroupId=com.datastax -DartficactId=bdp -Dversion=4.6.0
Option 2
Manually copy dse.jar from your install location to ${project.basedir}/lib/. Then modify your pom.xml:
<dependency>
<groupId>com.datastax</groupId>
<artifactId>bdp</artifactId>
<version>4.6.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/dse.jar</systemPath>
</dependency>
I don't really know why you're calling the artifact "bdp", but for these purposes it doesn't matter, and I just used it as well.
dse.jar is part of DSE installation. If you are working in windows environment, you can find it here dse.jar
register,download and extact to find the jar in lib folder. The use the above answer to add it in your maven project.

How to use Json library in web application

I am working on a web application in JAVA, and I used org.json. in the project for some computation, but I get the following error message when I run the application from localhost.
java.lang.NoClassDefFoundError: org/json/JSONObject
I specified the dependency in pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloudera.oryx</groupId>
<artifactId>projectname</artifactId>
<version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
</dependencyManagement>
EDITED: Full Pom.xml content
What other thing should be done to get this to running? Thanks.
There may be various reasons, you get NoClassDefFoundError even after adding the dependency
The following are the checks you can do to get.
Add the dependency in <dependencies> section of your main pom.xml. If you feel like I dont require JSON library in service layer in an application like Rest --> service --> DAO, then add in <dependencyManagement> section and add the dependency with out version - in which ever module you want.
You need to make sure that your settings.xml is configured right enough to get the jar files downloaded for you.
Another possibility is refresh your workspace if you are using some IDE - eclipse, IntelliJ to get the dependencies updated.
You can check .m2 --> repository --> org --> json --> <version> folder is available or not. This confirms that the jar is downloaded and you can tick point 2 as confirmed.
You can unarchive the war file and check in the libraries whether the json jar file is added to your end packaging or not. This is the final place to check.
You can use mvn -U clean install to update the dependencies.
I think the problem is your POM's "packaging"
The normal way to build a webapp is to specify the packaging as "war" so that Maven will build a WAR file containing your code and the dependent JARs. You then deploy the WAR file to the web container.
But you are using packaging "pom".
I'm assuming that means you've got another (child) POM file to build your application JAR.
I'm also guessing that you are using "jar" as the packaging in that POM.
I'm also assuming that you are then deploying the JAR to web container; e.g. by hand or using some IDE integration thingy.
I think that the problem here is that while you are deploying your JAR file to the web container, and you don't need to deploy the Jersey dependencies ('cos they are already there!!), you are NOT deploying the "json.org" JAR file.
At any rate, the reason that you are getting the exception is that the web container classloader cannot find that JAR file. If you are deploying without using a WAR, something has to copy the file to the place where the web container's classloader is going to look.

specifying dependency in maven

I have a jar file present in location
/path/to/foo2011020.jar
I am importing this jar as
import org.foo.FOOException;
import org.foo.FOOObject;
How do i specify this in my maven build file??
Is there any good tutorial for learning maven.
Will there be two instances in build file
I have tried various permutations and combinations but it is just not working. I bet this is something fairly straightforward.
Any pointers..
Thanks
if you don't want to publish the jar to some private/public nexus and you just want to have it on your disk then use <system> scoped dependency
for example:
<project>
...
<dependencies>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>your-artifact.id</artifactId>
<version>your.version</version>
<scope>system</scope>
<systemPath>/path/to/foo2011020.jar</systemPath>
</dependency>
</dependencies>
...
</project>

How to add maven dependencies for mahout and hadoop?

I am doing a project that has dependencies on some classes from the mahout and hadoop core jars. I was using javac with the classpath option to include them before, but someone suggested to me that I should use maven to build my project instead. However, I am not sure how to add the dependencies to these jar files which are located in my /usr/local directory.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.205.0</version> <!-- or whatever version -->
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
Add this to your pom:
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>hadoop</artifactId>
<version>some.version</version>
</dependency>
</dependencies>
If you have a copy of the jar to be used for say the hadoop example above, execute this command:
mvn install:install-file -Dfile=/some/path/my-hadoop.jar -DgroupId=some.group -DartifactId=hadoop -Dversion=some.version -Dpackaging=jar
Have a look at the maven documentation, especially the part on dependency management. If you want to use Maven you should get to know the basics (one of which is dependency management).
Basially you define your project's dependencies in the <dependencies> section of your pom. Look up maven central (the most common online repository) for the dependencies you want or search for other online repositories that might contain them.
If you can't find them, add the dependencies you want anyways (think of a sensible group id, artifact id and version) and try to compile. Maven will complain about the dependencies missing and provide a basic command to put those dependencies into the local repository. Copy those commands and fill in the appropriate path to the jar file and maven will deploy that dependency in your local repository.
Note that you should first look for the dependencies in an online repository since otherwise you'd have to manually deploy each new version in your local repo.

Categories