Setting up EJB build classpath in Eclipse - java

I have installed Eclipse, WildFly and Jboss Tools. I created an EAR/Maven project and an EJB/Maven project.
I added all the dependencies to the EAR pom.xml. Jboss Tools deploys the WildFly EAR lib with no issues and the application runs fine.
The problem is the build classpath in the EJB project in Eclipse. As all the dependencies are configured in the EAR pom.xml and not in the EJB pom.xml, I cannot figure out how to tell the EJB project in Eclipse to take from the EAR project the jars that were defined as dependencies.
How to set this up?

Add the dependencies in EJB pom.xml and not in EAR pom.xml.

You want to "take from the EAR project the jars that were defined as dependencies", but this is not how Maven works.
Jars are drawn from a Maven repository (like MavenCentral or your local repository), according to the dependencies that are defined in the pom. As #N.Shrivastava already said, you define the dependencies in the pom of the project that actually uses the dependencies. So when you have an ear that includes an ejb jar that has some dependencies, put the dependencies into the pom of the ejb jar and delete them from the pom of the ear. They will be transitively drawn into the ear as well.
If you need the same set of dependencies in different ejb jars, this can be realised by creating a separate project of packaging pom. Then the different ejb jars can depend on that pom project, and draw transitively all the dependencies from the pom project.

Related

Eclipse - Maven : Project dependency gets removed from deployment assembly after Maven--> Update

I am using Maven and Eclipse to create a archetype webapp project.
my project is dependent on another project in the workspace (say, projectA), and everything works well at compile time. Now i have to add the entry for projectA in my deployment assembly, so that it is included in the created WAR, otherwise i get a class not found error when the webapp runs, for the classes i have used from projectA.
Now, everytime I right click --> Maven --> Update , the projectA entry from deployment assembly is automatically removed, and i have to manually add it again before creating the war.
P.S: I have seen similar questions about Maven Dependencies getting removed from deployment assembly, but that does not seem to be the case here, only the projectA entry is removed. I have <packaging> war </packaging> in my pom.xml as well.
Using Eclipse Luna.
as pointed out by #Tunaki in comments:
In a maven project, the dependencies have to be specified in pom.xml.
In my case, i was using Eclipse and specified a dependency using Eclipse, so Maven did not recognize it, and i could not use any Maven specific build tools on the project, without the external dependency being removed.
(Although, it was possible to use Eclipse tools for creating WARs which take care of both maven dependencies and others)

how to configure pom.xml to working with ear project as dependency

I`m new here and i trying to configure maven to working with ear project as dependency of other war project: To imaginate my idea i include the following image
I wonder how to configure poms.xml of this two war projects
(doggle and expert) to get possiblity calling enterprise beans of core.ear project. Simply adding dependency to pom.xml not working correctly. I think I need use some maven plugin or do something addtiotional.
Could somebody help me or give some instructions what I should do to include in pom.xml of each war project ear project and than call EJB bean? I Will grateful for your help.
That's not possible. Convert your war project into jar projects and create two new war projects that depend on the jar project. Now your ear project can depend on the two jar projects.

eclipse plugin classpath issue

Created multimodule maven project where folder structure is as below,
|-ProjectA
|-projectB
|-projectC
|-projectD
Created jar of ProjectA using maven shade and AppendingTransformer to include spring handlers,Schema.(Project B uses spring 3.0.7.RELEASE)
Then added this ProjectA jar in eclipse plugin project and build path.
One of the eclipse project calls ProjectB.method(); which loads configuration file as,
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:META-INF/myfolder/plugin.xml");
This plugin.xml has
<context:component-scan base-package="mysamplefolderpath" />
Problem occurs when it's starts scanning base package in all the jars which are in classpath of eclipse plugin project (eclipse plugin project uses spring 3.0.5.RELEASE).
How can I restrict that base package scan in classpath of ProjectA only?
I got solution. Created shaded jar so plugin refers the required jars in that class path only. Resolved conflict between other jars(having different versions).

Maven dependencies not included in project deployed on Websphere Liberty

I am using Eclipse Luna, Maven 3 and Websphere Liberty 8.5.5. I have added websphere liberty server in eclipse. The EAR/WAR project deployed in liberty does not include maven dependencies in WEB-INF/lib of WAR. If I export EAR or WAR the exported file has all the dependencies included. What could be going wrong?
While working with Maven projects in Eclipse, make sure your Maven dependencies are correctly configured in Project properties > Deployment Assembly to be deployed to WEB-INF/lib folder.
Gas has the right answer. Just here a screenshot:
If the Maven dependencies are missingf click then "Java Build Path Entiries" and the select "Maven Dependencies"
In my workspace this setting will be lost when I do Maven/Update Project.

difference between MutliModule and EAR

What is the difference between maven multimodule project(pom packaging) and ear packaging.
As i know Ear is used to package a group of related Module (EJB, JPA, JSF).
After reading maven documentation i found that multimodule project is used for the same thing.
Are they the same? Can i use multimodule project instead of EAR? can mutlimodule project be deployed to application servers?
A multi-module project (packaging of pom) is a way of defining a parent pom that has child modules. This is convenient for many reasons. For one, you can just build the parent pom with mvn compile and it will build all of its modules, too. Without the parent pom, you'd have to go into each pom and manually type mvn compile otherwise.
Not only that, but using modules gives you other really important features. See the answer to this question. To summarize, imagine you have a continuous integration server that just installed in the middle of you building locally. By using module, you ensure that you compile against your local code instead of the continuous integration server's code. This will prevent a lot of heisenbugs(sp?).
Now the packaging of ear is not directly related to this first multi-module concept. That packaging just determines the binary output. It will output an ear file. In the maven-ear-plugin plugin, you can include other modules like wars/jars/ejbs, but it won't do any of the things I've described in the first paragraph. For example, typing mvn compile in the directory of the ear's pom.xml file will not compile the war file it depends on.
Also, you don't have to include other maven modules in your ear. Another completely unrelated project may install an ejb and you can use that ejb in your ear just as a dependency.
multi module is just a way of organising your project into modules/components.the packaging need not be ear always.it can be for instance a war project that has all its server side content as a jar file in one of its module.
in short,multi module organisation can be opted for a ear project but the converse that mutli module is always a ear project is not true.
The two are not the same. A multi-module project just builds all sub modules, it does not produce an artifact.

Categories