m2eclipse - after pom and dependencies definition - no libraries on classpath / Maven Dependencies - eclipse

I've been doing just simple archetype projects until now, and always after dependencies definition and saving pom.xml, immediately after that the Maven Dependencies library was full of libraries. But now I declared:
parent(pom packaging, scm, repository management)
parent(pom packaging, shared dependencies)
actual project (jar packaging, few more dependencies)
actual project (jar packaging, few more dependencies)
I created them from the upper one by "Create module" ... Problem is, that I can't make it automatically fill the Maven Dependencies library
In .classpath file there is this line <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> as in other "working" projects, but there is nothing on the classpath. Any suggestions please ?

Can you run mvn dependency:tree on the command line for the child project and confirm that you see the expected dependencies. If you don't, then there is something wrong with your poms (that you will have to post to get more help).

Related

Circular Dependencies in Eclipse Platform

I'm trying to add the Eclipse Platform to my Maven project and stumbled over something very weird.
There is the plug-in org.eclipse.swt, which has a dependency org.eclipse.swt.${osgi.platform}, where ${osgi.platform} can be any of the following:
cocoa.macosc.cocoa
gtk.linux.aarch64
win32.win32.x86_64
However if you check the pom.xml of org.eclipse.swt.win32.win32.x86_64 you learn that this project has a dependency to org.eclipse.swt. Which forms a nice dependency circle, which is not allowed in Maven nor in OSGi.
Consequently I'm getting a StackOverflowError, but only if I try to use the maven-dependency-plugin with -Dosgi.platform=win32.win32.x86_64.
If I don't use that parameter I get the following exception:
No versions available for org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar:[3.105.2,3.105.2]
(Which is probably okay, because I guess that Linux is the default value, but it doesn't apply to me, since I've got a Windows PC.)
I can't exclude the dependency either, e.g. with:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.swt</artifactId>
<exclusions>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.swt.gtk.linux.aarch64</artifactId>
</exclusion>
</exclusions>
</dependency>
I get the same error messages as above with that approach.
I'm wondering how the Eclipse guys even managed to release that mess, but more importantly: How do I build against a Maven project with circular dependencies like this?
You're looking at the wrong place. Eclipse artifacts are published in Eclipse p2 repositories. In addition, some Eclipse artifacts will be published in Maven repositories for use in plain (non-Eclipse based) Java applications which cannot be used to build Eclipse-based applications. Something seems to have gone wrong publishing Eclipse SWT to Maven Central causing the circular dependencies. Please report this to Eclipse.
The Eclipse IDE packages are built with the Maven plug-in Tycho. See for example the pom.xml file for the Eclipse platform or here the parent pom.xml for all IDE packages. Tycho uses one or more Eclipse p2 repositories to resolve dependencies. A Maven repository would not work to resolve Import-Package dependencies or product configurations, for example. In a Maven repository, an artifact has a version, while in a p2 repository also Java packages of the same JAR can have different versions. In a Maven Tycho pom.xml only the p2 repositories have to be specified, the dependencies are already declared in the META-INF/MANIFEST.MF, feature.xml and *.product files.

Maven: how to build jar and include as a dependency

I have a multi module project. I am using eclipse and Maven 3. I wish to first build a jar (a standalone project with its own pom). This is not the problem.
The problem is this jar is included as a dependency of my multi-module EAR project (used by two of the wars). The code of the JAR will often change and will require building before the EAR project is built.
How can I make this jar build prior to the EAR build in one action?
Here's my setup:
parentProject (packaging=pom, dependency[filters down to wars]=jarProject)
earproject (packaging ear, parent=parentProject)
war1Project (packaging war, parent=parentProject)
war2Project (packaging war, parent=parentProject)
jarProject (packaging=jar, no parent)
Add your jar project as topmost <module> in your multi-module EAR project's POM.
See also Maven: The Complete Reference, Multi-module vs. Inheritance.

Can maven treat WEB-INF\lib the way eclipse (and m2e) does?

I have a servlet/jsp web project which runs fine on eclipse and is exported as war fine (once I clean it that is). I mavenized the project deleting all of the dependencies from the WEB-INF\lib folder except a homebrew jar (the output of another project in the workspace). When I run the package maven goal I get messages for missing classes from this jar:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
#..... NOTICE THIS COMES FROM A CUSTOM JAR
[ERROR] /C:/path/DataServlet.java:[3,30] package xxx.java.helpers does not exist
Now this has been asked before and the most rigorous solution appears to be to create a local repo: Can I add jars to maven 2 build classpath without installing them? (NB: I am at maven 3).
I would like to avoid this - so is there any way maven will just stuff this jar to WEB-INF\lib in the war ?
Solutions that use some maven plugin to cp the contents of the WEB-INF\lib in the war are welcome - although I just have this feeling that there should be a solution that takes into account the "special" nature of this folder.
Observations:
Alt+F5 removes this line:
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
which corresponds to the "Web App libraries" in the Java Build Path. So not only maven refuses to take into account the WEB-INF\lib - it also breaks the build path of eclipse completely.
Related:
Maven: How to include jars in Eclipse, which are not available in repository?
Uses the maven eclipse plugin : update my classpath with an Eclipse User Library via the maven eclipse plugin - not compatible with m2e
How does the m2e eclipse plugin interact with eclipse? - apparently m2e checks the pom then calls the eclipse builders (hence the .classpath is read)
Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server
Deploying a Maven project with dependencies to Tomcat or Jboss running within Eclipse
Did you add this jar from WEB-INF\lib as a dependency like this:
<dependency>
<groupId>someGroupId</groupId>
<artifactId>someArtifactId</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/homebrew jar</systemPath>
</dependency>

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.