How to build a project on github with pom.xml - java

This might be a naive question, so pardon me but I am new to maven.
I want to build a jar of project present on github. The project has a pom.xml file and additionally mentions in
Installation Note:
Releases are distributed on Maven central:
<dependency>
<groupId>some_grp_id</groupId>
<artifactId>all</artifactId>
<version>1.1.2</version>
<type>pom</type>
</dependency>
Am I suppose to add above in the existing pom.xml file ??
I an cloning the project on my desktop and then executing "mvn package".

If you want to simply use the library then you only have to add the above dependency to your pom.xml. Maven is doing all the rest for you (downloading the .jar-file).
If you really want to use the source code you have to do a
mvn install
on the checked out code. And also have to include the dependency in your own pom.xml.

Related

How to import a .jar in a Java's file without IDE and with Maven?

I can't compile the files directly. I use mvn package.
I can't run the files directly. I use storm (Apache).
I don't know much about Maven.
I tried to just put the .jar in the same folder as the code and use import com.path.of.jar. It did compile, but when I tried to run, gave a NoClassDefFoundError.
Try this way to add dependencies directly, like this:
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
When you work on a maven based project, you manage dependencies through the pom.xml file at the root of the project. POM stands for Project Object Model and contains information about the project and configuration details used by Maven to build the project (Introduction to the POM).
A maven project produces an artifact uniquely identified by its coordinates: The <groupId>, <artifactId> and <version> that you normally find at the top of your pom.xml file. Once an artifact is published to a repository other maven projects can depend on it.
If you look at the content of your POM file you should see a <dependencies> element containing all dependencies that your project needs. If you want to import classes from a jar in your code you will need to find the maven coordinates of this jar (for example on search.maven.org or mvnrepository.com).
Once you have the coordinates add a corresponding dependency section. It should look like this:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Next time you run mvn package, the jar will be downloaded, used during compilation and packaged with your artifact.
And if you would like to get a good understanding of maven the following free book is excellent: Maven: The Complete Reference

how to get maven to update a specific version dependency

i'm kinda new to maven after coming from a simple yet uncouth ant world.
<dependencies>
<dependency>
<groupId>com.foo.bar.EPT</groupId>
<artifactId>EPTUtils</artifactId>
<version>1.2.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
I'm looking for a maven command to specifically update this version to 1.2.14-SNAPSHOT. I've tried
mvn -DallowSnapshots=true versions:use-latest-snapshots -Dincludes=com.foo.bar.*
but that didn't update what i had in my local repo.
Change
<version>1.2.9-SNAPSHOT</version>
to
<version>1.2.14-SNAPSHOT</version>
in the pom.xml of your Maven project. Then build the project.
mvn clean test package
Maven will download the dependency and store it in your local ~/.m2 repository.
Edit: Also see How do I tell Maven to use the latest version of a dependency? for more information about Maven and latest versions.
Edit 2: You can use the Versions Maven Plugin that as goals that can help you with that.

crystal report jars for maven

I have built a non-maven project to display crystal reports with all necessary jars imported to the lib folder.
But, when I try to find the dependencies to add the same jars into my pom.xml for a maven project, I was not able to look it up online.
How can I find the crystal report dependencies for a maven project ? How to determine groupId and artifact for the crystal jar?
Below is the snapshot of jars I am looking for. Please suggest.
I tried looking into this link in the SCN but couldn't find much details.
You can specify your local jars as maven dependency using "system" scope
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${lib.path}/some_1.0.jar</systemPath>
</dependency>
define 'lib.path' in properties
Below are two solutions : One is pointing to local jars with system scope and the other is deploying the jars into m2. I felt the second solution more reliable.
First solution: I followed the link here ; but couldn't get it entirey working. So changed the scope to system and pointed to the local jars and was able to finally access the classes.
Please see below for the pom.xml
<dependency>
<groupId>com.sap.crystalReports</groupId>
<artifactId>CrystalCommon2</artifactId>
<version>1.0.0-RT</version>
<scope>system</scope>
<systemPath>${lib.path}/CrystalCommon2.jar</systemPath>
</dependency>
.....
Second solution is, from the comment in the question above, I came up with the idea of deploying all the crystal jars, one by one, which I downloaded on my local into my local m2 repository.
mvn deploy:deploy-file -DgroupId=com.crystalruntime.sdk -DartifactId=JDBInterface
-Dversion=1.5 -Dfile= point-to-the-jar-location-on your-local\JDBInterface.jar
-Dpackaging=jar -Durl=file://point-to-local-m2 repository
groupId, artifactId,version- can be modified, but it is good to keep consistency and readability, with the names chosen.
Run this command on any/all the jars that you want to install into m2. I then updated the project and did another clean build and was able to successfully run then application.
Also, I did remove the system scope from the pom.xml
<scope>system</scope>
<systemPath>${lib.path}/JDBInterface.jar</systemPath>
and modified it according to :
<dependency>
<groupId>com.crystalruntime.sdk</groupId>
<artifactId>JDBInterface</artifactId>
<version>1.5</version>
</dependency>
This made more sense to me, to use in the maven project.
This is the link I followed for reference.

Is there a maven repository for flash-selenium.jar?

I recently moved to maven project and since then I found adding dependencies very difficult. Before that I just needed to download the jar and add to library folder .
Now I am searching flash-selenium.jar dependency but I failed to find any. So I added it manually in my C:.m2\repository\org\seleniumhq\selenium\flash-selenium folder but still it is giving error. So how can I use this jar in my maven project?Its a request to people those have 1500 points here , could you please create a label for selenium flash related problems. Thanks
There's no flash-selenium dependency in maven central, but there are other artifacts like:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0rc2</version>
</dependency>
the complete list:
http://search.maven.org/#search|ga|1|selenium
Maybe some of this fits what you need.

Add a dependency in Maven

How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)

Categories