Include jar files from maven repository to eclipse project? - eclipse

How can I include jars from local maven repository into eclipse project? Actually, I need to include them into WebContent/WEB-INF/lib directory in eclipse web service project, if it makes any differencies.

Open your pom file and add a dependency like this.. suppose the jar you want to add from local repository is myfaces-10.jar
and if it is in the path .m2\repository\org\apache\myfaces\myfaces\10\myfaces-10.jar .. then add a dependency in your pom.xml like this..
<dependencies>
.
.
<dependency>
<groupId>org.apache.myfaces</groupId>
<artifactId>myfaces</artifactId>
<version>10</version>
</dependency>
.
.
now the jar will be available in the classpath and you can use it in your project..
make sure your groupId matches the path like in my example...
hope it helps..

Related

How can I import external *.jar in spring mvc project using maven?

I followed this correct answer in how to add local jar using maven, But I get 404 not found.
POM.Xml
<dependency>
<groupId>tn.mass</groupId>
<artifactId>massTer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
eclipse console error
Check in your .m2 folder if massTer.jar is present with correct group id and version. Ideally if you are owning the source project massTer then I would suggest you to user maven-install-plugin to get it installed within your .m2 folder when you run mvn clean install over that project. Instead of building the jar and later adding it as mvn install:install

Why does addition of MigLayout still give an error inspite of adding the MigLayout jar file in the libraries in netbeans 8.0?

Though I have configured the classpath and added the jar file in the library of the project , it still gives me an error as "package net.miginfocom.swing. does not exist".
What can I do to avoid this error?
You can use maven to automatically download MigLayout. Just click new project, select and maven from categories, then Java Application. Once created go into the "pom.xml" (within Project Files) and paste this under the properties section:
<dependencies>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
</dependencies>
Then just build the project and maven will download and install MigLayout. Hope this helps.

How to move jar file in Maven Library

I am using Eclipse Indigo with Maven. i have created Maven Project and selected ArtifactId as webapp-archetype 1.5.1 as shown in the screen shot below.
When i am done completing the project, list of libraries appears under Maven Library. Now, i want to add few external Jars to Maven Library by going into its build-Path and add external jar, it adds the jar file but NOT under Maven Library. I can't manually move it under Maven Library, neither can i paste it.
P.S , i want to remove few jar files from the Maven Library as well.
You need to add dependencies in your pom.xml not by adding external jars manually to your build path.
So remove the extra jar you added by hand end add:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
Edit
If you have m2eclipse plugin installed on your eclipse, right click on your project, and under Maven menu do a "Update project configuration".
Your new jar should be displayed under Maven dependencies
or if not, run a mvn eclipse:clean eclipse:eclipse to regenerate the .project and .classpath of your project

Eclipse Maven Dependency

I have just added dependencies to an eclipse project so that my jar can see other jars. How can I be sure that the dependencies work, and that what I've done is correct? I view a pom.xml file that has been created so what are the target folder and classes,test-classes subfolders used for? Thanks
If you have the m2eclipse plugin installed you can open your pom in Eclipse and click on the Dependency Hierarchy tab to view your resolved dependencies. You should manage all dependencies through Maven with the setup you are describing.
If you want to check command line you may want to look at using Effective Pom.
If you use m2e, it adds Maven Dependencies pseudo library to your project.
You may expand it and see if the dependent jar file is in there.
If it is, Eclipse ( or more precisely m2e ) has resolved the dependency correctly and it's available for you project build.
If you added your dependencies correctly your application should build and execute correctly, or am I missing something? Dependencies should be added to a POM section that looks like this example:
<dependencies>
<dependency>
<groupId>annogen</groupId>
<artifactId>annogen</artifactId>
<version>0.1.0</version>
</dependency>
<!-- other dependencies here -->
</dependencies>
Maven and the m2e/m2eclipse plugin rely on source files to be conventionally placed in src/main/java for application code and src/test/java for test code. Application code is compiled to target/classes and test code is compiled to target/test-classes. If you plan to use Maven and/or m2e/m2eclipse, do read about it. Maven: The Complete Reference is a good starting point.

Adding dependencies in Maven Netbeans

I've created a Maven project and added the dependencies (jar files) that I need; however, netbeans says that it still cannot find it.
Specifically in my case, I added the jmf-2.1.1e.jar file into my dependencies folder. When I go back to my program it still gives me the compile error that it cannot find the javax.media package.
Did you let Netbeans manage the dependency?
In your "Projects" listing, find and context+click on the "Dependencies" folder in the list. From the context menu, choose "Add Dependency".
This approach works at least in NetBeans 7.4 and 8.0 beta.
Make sure that your pom.xml has the following snippet that defines the dependency
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>
The dependency is available in Maven Central. Add the pom snippet manually to the pom.xml and run Maven in the shell and let it download the dependency. This should resolve your issue.
Maven automatically downloads the dependency once specified in the pom.xml. For this you would have to build your project with the dependency as specified by Tim Sparg.