ejb-client Maven dependencies in Eclipse - maven

I use a dependency with ejb-client type in a Maven project:
<dependency>
<groupId>mygroup</groupId>
<artifactId>foo</artifactId>
<type>ejb-client</type>
</dependency>
It works properly when I build the project with Maven: it includes a version of the dependency that has remote EJB interfaces only (no implementations).
However, when I export the project to Eclipse Luna, and deploy it from Eclipse to jBoss/WildFly, Eclipse copies the full version of the dependency as if I used <type>ejb</type>.
Eclipse also gives me a warning:
Dependency to project foo with type ejb-client is not fully
supported. Classpath and/or deployment issues might arise. Try
Maven->Disable Workspace Resolution...
Is there a way to make ejb-client dependencies to work in Eclipse? Or is there any workaround?

In the past I've found that ejb-client jars are not a very good idea. They share the same dependencies as the full ejb-jar and you normally don't want that. You will also find that IDE support for these is a little weak.
You're far better off hand building your remote EJB API as a separate jar artefact and including it where needed.

Related

OSGI Bundle vs jar dependency

I'm trying to understand the difference between the following
<dependency>
<groupId>com.myspace.order</groupId>
<artifactId>dal</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
AND
<dependency>
<groupId>com.myspace.order</groupId>
<artifactId>dal</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>bundle</type>
</dependency>
The dal artifact itself has packaging specified as bundle as:
<packaging>bundle</packaging>
Now when I deploy the dal artifact, I see it published in the repo as a jar (with a manifest within it). In this case, what should my dependency on dal be. Should it be of type bundle or jar? If I am doing OSGI, I assume way would be to have the type specified as bundle. Is this correct? Or, can I just have a jar dependency here?
When you declare a dependency in Maven, you can only depend on a normal Jar, not a bundle, because Maven does not recognize the OSGi environment restrictions.
See this question:
Why can't maven find an osgi bundle dependency?
At the time you compile your project, you don't need to worry (but should!) about the OSGi environment yet... for example, it will not complain if you try to use packages not exported by the bundle you're depending upon....
When you try to deploy your bundle within a OSGi container, if you correctly declared your dependencies on the 'dal' packages you use, including of course the version (which usually you should leave for the maven-bundle-plugin to do for you based on your POM), it will only be resolved if there's a bundle within the container which exports the required packages in the right version (or version range).
Considering that 'dal' seems to be a bundle already, you just have to make sure to deploy the your bundle and 'dal' together and everything will work fine.
However, if you by mistake added a dependency on a private package of 'dal', although Maven will happily compile it for you, when you thrown it in OSGi you will be greeted by a nasty wiring exception :)
Notice that a bundle is just a normal jar which contains OSGi metadata in the manifest (Bundle-SymbolicName, Bundle-Version etc). So if you don't use OSGi, a bundle will work as any other jar.
But anyway, if you want some more info, check this question:
What is the meaning of type "bundle" in a maven dependency?

Where do I get up-to-date versions of org.eclipse.jdt for Maven?

I would like to use the Eclipse AST to generate source code. My project is managed by Maven and I would like to simply add dependencies for the compiler. Unfortunately, the most recent version I found in central is 3.3.0-v_771. The Tycho project offers newer versions. However, I found that the poms do not specify dependencies and I don't want to do that myself. I've spent quite some time googling for other sources but that's the best I could come up with.
Does anyone know of a better, maven-compliant way of getting JDT in Maven?
You can the use Maven-Eclipse-Plugin to deploy your Eclipse bundles to Maven on your own and then use these. An example command would be:
mvn eclipse:to-maven -DdeployTo=internal-nexus::default::http://myNexus/content/repositories/eclipse -DeclipseDir=C:/Eclipse
Alternatively you could purchase a license for Nexus Pro and provide Eclipse p2-Repositories as Maven repositories.
Now there is an other way. Some of the Eclipse Neon.2 jars are published as normal maven artifacts (pom files are user friendly, the standard dependency management of maven will work).
If you want to use jdt-core in your project you just need to add this:
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.12.2</version>
</dependency>
... and you let maven do the rest for your. I have published a simple example how to use the java code formatter from eclipse in a simple java application.

Maven build order

I have a multi-module maven build and I need one particular module (lets call it project-A) to be build at the end. It depends on a module (lets call it project-B) that holds native code that gets compiled to a dll and installed into the maven repository as a zip file using some maven trickery. As it doesn't depends on it directly because the native code is not a java jar, I use Maven Dependency Plugin to unpack the zip file and place the native dll in my build directory. Everything is working fine except for the building order. It builds first project-A in spite of being declared the other way around in the tag in the parent. I would like to tell maven that project-A depends on project-B. I tried to add project-B as a dependency, but as it builds no jar it throws an ERROR, also this seemed hacky to me. Any help would be appreciated.
Just declare dependency in project A to project B and it will work fine. It does not matter if the project B is a native rather than a java project. Just make sure you declare the dependency correctly taking the packaging into account as type.. (which is probably pom so you would have
<dependency>
<groupId>...</groupId>
<artifactId>B</artifactId>
<version>...</version>
<type>pom</type>
</dependency>
in Project A)
The order in which you specify the modules in the parent Pom is also relevant. Maven actually builds in this order unless it has to build a module out of sequence due to direct dependencies.

Netbeans: maven dependencies of type pom

I've spent a lot of time and my head is blowing up already so I'll be very thankful for any help.
I'm migrating Netbeans Platform application from ant to maven, and so I'm changing all the jars in my version control repo to maven dependencies. I've found needed artifact in main maven repo and I've added it as a dependency with a help of Netbeans, but it's of type POM and was placed in Non-classpath Dependencies and I have no idea how to use it as it wasn't added to classpath etc…
Can someone explain what are these POM dependencies and how to use them?
Thank you in advance!!
EDIT
here is dependency definition in pom.xml
<dependency>
<groupId>com.kitfox.svg</groupId>
<artifactId>svg-salamander</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
Adding a pom dependency only pulls down transitive dependencies, that is jar dependencies defined as dependencies in the pom. The pom does not get added on the classpath for obvious reasons, but the transitive dependencies reachable from pom will be added to classpath.
What you ideally need to do is have dependencies of type jar Default dependency type is jar and you can simply define dependencies without any type element in the dependency section.
If you have located the jar files you need in Maven Cental, then you simply need to provide groupId artifactId and version for each one of those in dependencies section.
Personally I cannot think of any case when one would need to add pom type dependency. I usually use pom packaging for parent module in a project (specify common project configuration like plugin versions, common dependencies, like log4j for example, repositories, properties etc.) and for utility package module (the one that assembles the project and does some other necessary things).
Judging from my experience (I did it several times), when migrating project from ant to maven you should take all the jar files that your project used to depend on and convert them into maven dependencies (groupId:artifactId:version). Most probably all of these dependencies will not have any <type> (e.g. be jars).

How to prevent duplicate servlet jar using eclipse+m2eclipse

I'm using Eclipse + Maven + m2eclipse to build and test a web application in Apache Tomcat.
I've configured a Tomcat server inside Eclipse, and configured the deployment assembly for my web app, including "Maven Dependencies" (specialization of Java Build Path Entries).
When I deploy and start the server, Tomcat/Catalina always warns me:
INFO: validateJarFile(/projects/src/main/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
This is because m2eclipse sees servlet-api-2.5 as a dependency of my project, and considers it as part of "Maven Dependencies", and copies it as part of the deployment assembly, but the Tomcat servlet container has its own copy of this and doesn't like seeing 2 copies on the class path.
I've marked the dependency from my project to servlet-api-2.5 in my pom.xml with
<scope>
provided
</scope>
which does prevent standalone Maven from packaging servlet-api-2.5 into my builds, but m2eclipse doesn't see it that way.
(This isn't a huge deal because the warning is harmless, I only see it during testing inside the IDE, and real customers won't see it, but I'd still like to know how to fix it because I like cleanliness and I like knowing how things work.)
Is there a correct way to tell m2eclipse not to deploy this file, or to tell Eclipse not to let m2eclipse have the final say on which dependencies are runtime dependencies?
I did find https://issues.sonatype.org/browse/MNGECLIPSE-1193 which mentions
the "Maven Dependencies" container reflects test compile time scope, so it is supposed to have dependencies with scope "provided"
Install extras for m2eclipse plugin ("Maven Integration for WTP") from update site http://m2eclipse.sonatype.org/sites/m2e-extras. After install, update the project configuration.
Normally there is a dependency in your project that is depending on servlet-apî.jar
The default behaviour of Maven is that i wiill try to import your dependency + the dependencies of the imported dependency.
If you want to exclude a specific "sub-dependency", you can give maven a configuration like this :
<dependency>
<groupId>com.hpsworldwide.mbtrs.switch</groupId>
<artifactId>YOUR_DEPENDENCY</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
then maven will import YOUR_DEPENDENCY + all YOUR_DEPENDENCY dependencies, but will exclude servlet-api from the dependencies of YOUR_DEPENDENCY.
I have just had a similar problem, and believe I have got to the bottom of it.
If you go to your server configuration settings in Eclipse and select "Serve Modules without Publishing" then this should no longer occur.
Maven/M2Eclipse is building the WAR correctly - servlet-api-2.5.jar wont be in your target directories or WAR file.
But the problem is, when you deploy the application via eclipse on to your tomcat, Eclipse does not use your maven built WAR/target directories as default, it just uses the normal Eclipse "export" settings for your project. So it sees in your "Java EE Modules" (or "Deployment Assembly List" if you are using Helios) the list of all the jars in your Maven_Dependencies, but it does not respect the scope, and just deploys all the jars.
If you select serve without publishing option then Eclipst/Tomcat should just run the app straight off your target directory so will respect the maven scopes.
It won't ever affect your live deployments (unless you are deploying via eclipse!) as maven is doing the right thing, but it can sometimes cause problems locally as you can ave conflicting servlet/jsp jars which can cause classcastexceptions and general misery...
If you are using Indigo you can find the WTP plugin by clicking to "Window" -> "Preferences" -> "Maven" -> "Discovery" -> "Open Catalog".
One tip: after install "Maven Integration for WTP" and update the project configuration, check the directory /WEB-INF/lib and delete all JARs inside. Now, clean the Tomcat work dir and run again.

Resources