How to add a Dependency via Maven for an Eclipse Plug-In Project - maven

I'm working on a Xtext/Xtend based plugin for Eclipse. My project structure contains of various Plug-In projects. The project was created as a maven project and converted to an Xtend project. Developing and building works fine but now I'm at a point where I want to add a dependency (org.apache.poi) to one of the plug-in projects.
I added the <dependency> node from maven central to my pom.xml in the parent project and it got downloaded to my local maven repo. So far so good but when I try to import org.apache.poi.xssf.usermodel.XSSFWorkbook in one of the (child) plug-in projects it can't be resolved.
When using maven in a plain Xtend project I have no problems using it. After adding the <dependency> to my pom.xml I'm able to use it afterwards. So I guess the problem lies in the fact, that I'm now dealing with a plug-in project. At the plain Xtend project, for example, I have a "Maven Dependencies" classpath container which I don't have in my plug-in project.
What I've tried so far:
added the <dependency> to the pom.xml in my parent and/or the child plug-in project where I want to use it
added the dependency via Eclipse GUI (opened pom.xml -> Add Dependency)
added the dependency via right MB on plug-in project -> maven -> Add Dependency
Maven Update Project
clean install -U after adding the dependency
clean/build project
In the MANIFEST.MF I can't add the dependency as it is not shown in the list of dependencies to choose.
What's the way of adding maven dependencies to a plug-in project in Eclipse?

Related

IntelliJ IDEA, the Libraries added to the Intellij are not automatically updating pom.xml

In intelliJ IDEA,
I add libraries dependencies in
pom.xml
and "Project Structure -> Project Settings -> libraries -> add ->from maven"
but now, how to write the '2' dependencies to pom.xml automatically?
because there aren't '2' libraries dependency in pom.xml. they aren't synchronization.
I already set Settings > Maven > Importing > Import maven project automatically, Don't work.
note: I want to the Libraries added in the Intellij which can automatically updating pom.xml file.
In settings / Maven, you can switch to "import maven project automatically".
Then, when you modify a pom.xml, it will update your project (ie download new dependencies) automatically
I dont think pom.xml is something which will automatically generate dependencies, If so there wont be any point to maven build type itslef.

gral-examples Maven dependency

I added gral-core Maven dependency to my project as it is explained here
http://trac.erichseifert.de/gral/wiki/Download
Problem is that I also need to add gral-examples.jar in Maven dependencies, but I cannot find the code for it. I need this to work because I share this project with few other people via EGit plugin for Eclipse, so I can't just add this library to build path, I need it to be Maven dependency.

How to force intelliJ to import a maven dependency with classifier as a "Maven Library" instead of "Intellij Module"

In my maven based IntelliJ project I have 2 modules - modules A and B.
The pom.xml of module A creates an uber jar (including dependencies which are not accessible by the project) and attaches it as an artifact with classifier "withdeps"
The pom.xml of module B has a dependency on the classified "withdeps" artifact A
When I import the maven modules IntelliJ adds the module's A source code in the dependencies of module B (ignoring the "withdeps" classifier).
Is it possible to force Intellij to add the module A dependency to B as "maven library" instead of the default "project source code/Intellij module"? If not what can I do to resolve the compilation errors in IntelliJ (Ctrl+F9)
Thanks
Open the pom.xml of module B only when creating the intellij project. Then all dependencies will be as maven dependencies.
The downside is that this way you will have to open module A as separate project in another window, then when you change something you will have to do mvn install and refresh project B.
Much better solution would be to install all depencencies into maven repository, described here in maven docs.

Local Maven Dependency project is referenced as a class folder instead of a jar

I'm using Eclipse Indigo with the m2e Plugin (Version 1.0.1). I have two separate workspace projects: A Maven Project that is basically a Vaadin widget and a second Maven project that is my main project which is referencing that widget with:
<dependency>
<groupId>com.mycompany.widget</groupId>
<artifactId>Calendar</artifactId>
<version>1.2</version>
<type>jar</type>
</dependency>
If I run mvn clean install on the widget project it is packaged properly as a jar and also available in my local Maven repository. I can also use the classes of the widget in my main project. However, in my main project's Maven dependencies, the widget project is shown as a class folder instead of a jar (though all other external widget dependencies are shown as jar files).
This causes some problems when I try to unpack (or even copy) the dependency to my main project with dependency:unpack-dependencies (resp. dependency:copy-dependencies). The maven build fails with:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:unpack-dependencies (default-cli) on project [main project]: Error unpacking file: /.../Calendar/target/classes to: /.../[main-project]/target/classes
[ERROR] org.codehaus.plexus.archiver.ArchiverException: The source must not be a directory.
My question is: How can I reference my widget project as a jar instead of a class folder in my main project?
They are in separate directories, right? Try this:
Right-click your project, select Maven -> Disable Workspace Resolution.
Also check the project properties and make sure that the project isn't referenced in Java Build Path -> Projects.

Maven beginner question, get m2eclipse to download jar and add to build path?

From what I have read, after adding the relevant maven repositories, maven should automatically download the necessary jars to satisfy dependencies in the pom.xml file.
However, no jars ever get downloaded for me after I add dependencies in eclipse. Am I missing some glaringly obvious step?
I'd recommend to start from creating your project with m2eclipse. See more details in this article.
Basically, you need to make sure the following:
your Eclipse project has a valid pom.xml and all dependencies are available (you should see errors on Maven console, in the Problems or Markers view or when opening pom.xml in m2eclipse's POM editor)
Maven support is enabled for this project (you can use Maven / Enable Dependency Management from popup menu on that project)
project configuration is in sync with pom.xml (you can use Maven / Update Project Configuration from the project popup menu)
you can also use Maven / Update Dependencies to refresh your dependencies (e.g. when you got them in your Local Maven repo from the command line)
Dependencies jars aren't in your project but in your local maven repository.
These jars will be automatically used when you compile you project with maven (or m2eclipse).
If you don't have the needed jar yet, maven will download it for you.

Resources