aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes how do i add a jar file externally as a maven dependency in eclipse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "how do i add a jar file externally as a maven dependency in eclipse?" Watch "how do i add a jar file externally as a maven dependency in eclipse?" New topic
Author

how do i add a jar file externally as a maven dependency in eclipse?

linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
i am not getting selenium-server2.17.0 as a listed item in eclipse when i try to add from Maven --> Add Dependency

so i want to add it externally
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

The selenium-server JARs appear to be in Maven Central at:
http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-server/

Just enter the proper coordinate and it should download.

I have noticed that the search function in Eclipse doesn't always find everything, the indexing capabilities of m2e are not that good. But if you know the coordinates, then you can always enter them manually.



JBoss In Action
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
i have a jar file named selenium-server-2.17.0 . how do i add it manually in the pom.xml file?

i do not know how to name in the groups!!!


<dependency>
<groupId>??</groupId>
<artifactId>??</artifactId>
<version>??</version>
</dependency>
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Linda

You can use the install plugin to manually upload a jar into your local repository.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>


However, if the jar you require is on Maven Central, you should be able to find its coordinates from here: http://search.maven.org/

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Available from Maven Central:



Be aware, there is a newer version available - 2.18.0
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
Thanks for the reply James.

When i add the above jar file by editing the POM.xml file. i get a error in the pom.xml file. i do not understand why??
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.17.0</version>
</dependency>


i added the above jar file for my Webdriver API's i used. But i do not understand why i am getting the error in pom.xml file
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
i got the error as soon as i edited the pom.xml file as above
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Linda

People won't be able to help you unless you give specific error details. What is the error you receive?
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
Its not a specific error. Eclipse shows that pom.xml file has error saying that there is a spelling mistake in few words in the pom.xml even though there is none.

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Linda

What happens when you run a build using Maven?
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86



i am getting a error with the following jar file now.

how can i correct it?

the previous jar file was taken properly.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86



following is the error trace when i do maven install from eclipse. its not able to find that jar!!!
what is the workaround ??
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

Linda

Re-run the install build, thus time with the 'Force Updates' option checked (or -U on the command line if you prefer)
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
where is the Force updates option in eclipse?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Don't run that from Eclipse. Go to the command line and run "mvn -U package" within your project's directory.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
Thanks Peter :-)
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86



whenever i clean and try to rebuild i get the above errors?

can somebody help me why i am getting this errors?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Try opening the JAR file using the jar utility. Here is an example:

jar -tf C:\Users\prasanna\.m2\repository\com\google\guava\guava\10.0.1\guava-10.0.1.jar

If that is not successful, then the JARs are corrupt. Delete the entire directory containing the artifacts. For example, for the guava JAR, delete C:\Users\prasanna\.m2\repository\com\google\guava\.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86



how can i put the dependency for ScreenRecorder.jar in maven?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

I used Jarfinder (http://www.jarfinder.com/index.php/java) to look up that class. Jarfinder knows about almost all open source classes. It could not find this class. Unless the owner of the JAR file that contains this class provides instructions on how to access the JAR via a Maven dependency, you will either have to import the JAR into your local Maven repository or deploy the JAR file to Nexus (or some other remote repository server). In my environment, we always do the latter. Oh, look in the JAR and see if there is a META-INF/maven directory; if there is, and you go to the subdirectories you will see the pom.xml which will give you the details about the artifact.

When we do this, we generally use the common package name for all classes in the JAR as the groupId (in your case, this might be "ch.randelshofer.screenrecorder"), and the JAR file name (minus the extension) as the artifactId. We also look at the META-INF/MANIFEST.MF file to see if it contains any version info. If it doesn't, we use the timestamp on the class files as the artifact's version.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
Thank you so much for this important information.. :-)
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
I added a Settings.xml file and changed the control to local repository after adding the ScreenRecorder.jar . It worked. Thanks a lot for all your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i add a jar file externally as a maven dependency in eclipse?