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).
Related
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.
I have a Spring project using Gradle that I want to package and upload to a maven repository to be used as a dependency in other Gradle projects. I tried using the maven-publish plugin to do this but the generated JAR has two issues -
1. it is generating a fat jar.
2. there is no pom.xml or any other file in jar that would tell the consumer project about the project's dependencies.
How can I accomplish the two tasks?
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)
In my maven project, I have this dependency which is my own project that is installed in my local maven (through cmd mvn install):
<dependency>
<groupId>com.myproject</groupId>
<artifactId>api-core</artifactId>
<version>1.0.0</version>
</dependency>
However when I start the tomcat server, I will get ClassDefNotFoundError on the classes within this project.
I tried to add the jar to the deployment assembly through the project's properties, however when I add this jar file, it is taken as a folder and will always be placed into the Deploy path of "WEB-INF/lib/core.api.1.0.0.jar" which is then a folder inside the lib, therefore tomcat isn't able to locate the jar file. I also noticed in the Web Deployment Assembly, the Maven Dependencies are deployed to WEB-INF/lib. Apparently my own jar file is not considered Maven Dependencies when it is being deployed. When I further look into the Maven Dependencies from Eclipse, the jar file is packed inside as "core" folder and it is not treated as a jar file. Therefore on run time, the web app has trouble locating the jar file and is giving me complain.
Further investigation shows that in Eclipse, I have the core project imported, and Eclipse is "smart" to recognize that project is the one generating the dependency, and therefore automatically convert the jar to the folder. If I remove the core project, the maven dependencies will then successfully added as a jar file, and then the deployment to tomcat issue not problem at all!
So, my question is, is it a way to keep the dependency in folder structure, while I can still have to core project imported to my workspace?
Yes, there is one: Show up the contextual menu of the web project, go to the Maven tab and uncheck the Resolve dependencies from workspace projects option: In this way, Eclipse will not interfere in Maven's dependency resolution chain.
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.