Multi Module Maven2 Project with WTP - java

I'm having a hard time to make my Maven2 multi module project, with a deep project structure, appear as a single ear (with its dependencies - which includes 1 war, 2 ejbs and 1 jar) to be deployed in my JBOSS 5 server inside my Eclipse Ganymede (tab Servers).
I've been trying to use Maven Eclipse Plugin to turn my projects into a WTP project without success. Therefore they appear to be deployed in the server they appear as separated projets.
My project has 1 war, 2 ejbs and 1 jar that must be packaged inside an ear, each of the "subprojects" is a separate module.
Project's pom.xml (type pom):
...
<modules>
<module>ejb1</module>
<module>ejb2</module>
<module>war</module>
<module>jar</module>
<module>ear</module>
</modules>
...
The ear module is only responsable to pack the other modules together.
Is there a way to tell eclipse (ganymede) that all those projects (ejbs, war and jar) are inside the ear module so I can deploy the ear in the server?

What you want to do is have maven create the eclipse projects via mvn eclipse:eclipse This might be helpful.

try m2eclipse (google it) and install the WTP integration tool, create a project using the maven wizard, change the type to pom in the pom xml editor, create a sub modules from the pom and that adds it as child, if its a web project it get the WTP behavior i.e it can be deployed to a j2ee container ( jboss / tomcat ), add a dep to the web module for ejb module in the web pom etc, deploy the web app to the container

Installing the m2eclipse with the optional WTP configuration worked for me. I also added the following to my parent pom to ensure the right natures and builders in the eclipse files
This yields eclipse .project files that are ready for m2eclipse. then I can Update the project files using m2eclipse allowing hot deploy the webapp and its dependencies
<build>
...
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5.1</version>
<!--
Eclipse project natures: http: //vikashazrati.wordpress.com/2007/12/22/adding-project-nature-to-your-maven-pomxml/
Maven-eclipse-plugin: http: //maven.apache.org/plugins/maven-eclipse-plugin/
-->
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>org.eclipse.jem.workbench.JavaEMFNature</projectnature>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
<projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>org.eclipse.wst.jsdt.core.jsNature</projectnature>
<projectnature>org.maven.ide.eclipse.maven2Nature</projectnature>
</additionalProjectnatures>
<buildcommands>
<buildcommand>org.eclipse.wst.jsdt.core.javascriptValidator</buildcommand>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
<buildcommand>org.eclipse.wst.common.project.facet.core.builder</buildcommand>
<buildcommand>org.eclipse.wst.validation.validationbuilder</buildcommand>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
<buildcommand>org.maven.ide.eclipse.maven2Builder</buildcommand>
</buildcommands>
</configuration>
</plugin>

use -Dwtpversion=2.0 parameter of maven or on command line mvn -Dwtpversion=2.0 in super pom project. i use m2eclipse plugin but has got some issues for multi module project. I use m2eclipse plugin for dependency management. If i want to clean, install etc. all project with super pom, i do it on command line. Also project properties must check in eclipse. Project Facets, Java EE Module dependencies must check. You can also export to ear project, but be carefull to check maven modules is compiled after changing.

Related

Maven Eclipse plugin, WAR overlays, and dependencies on project vs. Maven repo

I have a Maven web project that depends on other projects that build WAR targets, and then uses the other web projects as overlays. All of these projects are part of a single parent project, imported into Eclipse as a Maven project.
The main web project's POM has dependencies and overlays with maven-war-plugin defined for the other modules.
My problem
in Eclipse, for some reason, when I update the Eclipse project from the Maven project, some of the modules are recognized as coming from other Eclipse projects, and others are expected to come from my Maven repository.
On closer inspection org.eclipse.wst.common.component shows a difference in the dependent-module for some modules.
<dependent-module ... handle="module:/overlay/prj/module1" />
vs.
<dependent-module ... handle="module:/overlay/var/M2_REPO/group/id/module2" />
Why would some modules be recognized differently than others?
Both are equally included as dependencies and overlays in the POM.
My workaround has been to edit this file by hand to get Eclipse to recognize that it should use the other Eclipse project directly (module:/overlay/prj) rather than look to the Maven repo.

Does maven need internet connection after Multi module project is deployed on server

I am having a large non maven project in company and having multiple projects as module which are added as deployment assembly in parent project.
Company is planning to integrate maven which can be achieved by creating Multi Module maven project but maven requires internet connection. There is no problem while developing but after deployment internet connection is blocked on server system. I have two questions:
1) Does maven requires internet connection after it is built and deployed on server?
2) Packaging is restricted to pom for aggregator project. How can it be deployed on server since there is no war for aggregator project?
Maven can manage a project's build, reporting and documentation from a central piece of information.
Maven is used when building packages, installing dependencies, deploying packages, it can also run unit tests during building. After packaging, the package has nothing to do with maven. Just forget about maven after building. So there's no need network connecting when running your project.
For multiple modules, you can integrate all the modules as single maven project. They can be installed in local maven repository. The installed modules, usually as jar file just the same as other open source jars.
You can run mvn clean install to install your module in repository.
Eg, com/yourcompany/module1.jar.
In your main project, you can add dependencies in pom.xml like
<dependency>
<groupId>com.yourcompany</groupId>
<artifactId>module1</artifactId>
<version>1.0.0</version>
</dependency>
which means your main project depends on module1.

maven dependency - 3 projects and 1 framework project dependency not be including

Eclipse - Neon
Maven
Java
archetype - 4 projects
Hi, I generated an maven archetype with 4 projects ?
============================================================
- framework (packaging ejb)
- bulk (kind of packaging : pom) it has 3 modules.
- bulk_ear
- bulk_ejb
- bulk_web
- bulke_ear (packaging ear)
- bulk_ejb (packaging ejb) - jpa...
- bulk_web (packaging war)
===========================================================
I would like to add the framework.jar as dependency to be used on the bulk_web and bulk_ejb projects
Would you please help me to do that. because I tried but with no success
My tries :
I added the framework dependency on bulk
I added the framework dependency on bulk_ear
But when I Maven install, the framework.jar does not packaged to ear.
<dependency>
<groupId>br.com.xxx</groupId>
<artifactId>framework</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Your goal "provided" means that the jar is provided by you manually or by the including framwork. Also if you want to package your artifacts with other libs you should have a look at the maven assembly plugin.
How to include package.jar with maven-assembly-plugin
Try to change maven scope to compile:
Compile means that you need the JAR for compiling and running the app. For a web application, as an example, the JAR will be placed in the WEB-INF/lib directory.
Provided means that you need the JAR for compiling, but at run time there is already a JAR provided by the environment so you don't need it packaged with your app. For a web app, this means that the JAR file will not be placed into the WEB-INF/lib directory.

Using third-party libraries in Eclipse RCP Tycho app

I've created a boiler-plate project following vogella's extensive Tycho tutorial.
Facts:
There's no feature, and there's no plugin. The only plugin is the RCP app, which is also the entry-point.
Problem:
I have no idea in which pom.xml do I include the 3rd party dependencies.
I cannot include them in the RCP project, because the packaging of that pom is eclipse-plugin, and not jar. From what I've noticed, if I change the packaging to jar, then the "Maven Dependencies" library is added automatically. If I change back to eclipse-plugin, they get removed.
Questions:
Where do I add the dependencies? There's no pom with jar packaging in my project.
Should I create a separate project with the necessary JARs? How do I include that dependency to my entire project?
Is it really that much of a good practice to create a separate plugin and a feature for this RCP app?
Related solutions:
"Update projects" doesn't work, and neither do the n other solutions in the other SO questions.
There's also this question and that question, but I don't fully get the answers
I think that you have a fundamental misunderstanding.
Maven: Maven determines all of the project dependencies via the pom.xml and resolves transitive dependencies automatically (assuming that all of the pom files and artifacts exist in repositories that you've configured and correctly declare their dependencies).
Tycho: The problem is that Eclipse already has its own project model based on product files, feature.xml files, and plug-in MANIFEST.MF files. Tycho leverages the Maven machinery for Eclipse, but the idea is that the pom.xml files just configure the Maven plug-ins and declare the packaging type. That provides an entry point for Maven, but then Tycho takes over. While Maven would normally build the dependency chain from information in the pom.xml files, Tycho is building the dependency change from information in the product, feature, and MANIFEST.MF files. You don't put any dependencies in the pom.xml files. Tycho also uses Eclipse p2 repositories (instead of normal Maven repositories) for finding dependent plug-ins that are not found in the local modules or target platform.
That's actually a benefit for many Eclipse developers since they've already set up everything properly in their Eclipse plug-ins, features, and products. They do not want to have to repeat all of the dependencies in the pom.xml.
Using Libraries in Eclipse plug-ins: In Eclipse, if you want to use a library that is not already packaged as an Eclipse plug-in, you have a few options. Your plug-in can include a set of JARs in a libs folder and then include that libs folder in the plug-in and runtime classpath (see the build.properties file). Another option is to create your own "library plug-in" that repackages a JAR library as an Eclipse plug-in. See also https://wiki.eclipse.org/FAQ_What_is_the_classpath_of_a_plug-in%3F. That's the answer that you're getting above.
The problem is that if you're trying to include a complex library with multiple JARs that is normally distributed and included in a standard Java project via Maven. We hit this problem with the Jersey JAX-RS implementation in my project. There's no p2 repository that includes all of the pieces of the libraries as plug-ins with correct dependency information.
Easy Solution: If you need a common library, check the Orbit project first to see whether the libraries have already been packaged as Eclipse plug-ins, http://www.eclipse.org/orbit/. In that case, you can download them and include them in your target platform, or you can pull them in dynamically at (Tycho) build time from their p2 repository. Your plug-ins would just include those plug-ins as dependencies (in the their MANIFEST.MF files).
Workaround / Solution: In our case, Jersey JAX-RS was not available as an Eclipse plug-in, and it had a bunch of transitive dependencies. The workaround was to create an Eclipse "library plug-in" like I mentioned above with two pom files. We initially created a skeleton plug-in with an empty libs folder. One pom file is just a standard Maven pom file with <packaging>jar</packaging> that declares the top-level dependencies required to pull in the Jersey JAX-RS implementation and all of its dependencies. The dependencies are declared with <scope>compile</scope>. We use the maven-dependency-plugin to copy all of those dependencies into the project's libs folder.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
We actually ended up running Maven with that pom by hand from time to time to update the libs, and then we just checked the plug-in with all of its dependent JARs into source control. Checking the build later, I see that we actually populate the libs folder on-the-fly with Maven with a separate build task just before we start the Maven/Tycho part of the build. Of course, plug-in's MANIFEST-MF file's Bundle-ClassPath and Export-Package entries are coming straight from source control. We have to check those from time to time to ensure that they match the libraries and packages that we're getting from Maven. (That doesn't tend to change much unless we bump major library versions or add a new dependency at the Maven level.) The plug-in's build.properties has the libs/ folder as part of bin.includes.
In the development environment, after we first check out the code, we just run mvn (with an External Tools launch config that's also checked in with the project) on the project's "copy dependencies" pom file. That populates the libs folder with all of the JAX-RS libraries and dependencies. We only have to run it again when we update something about the dependencies or when we're jumping between branches that have different versions of the JAX-RS dependencies. We set .gitignore to ensure that we don't commit the libs to Git.
The other pom for this project is set up like a normal Tycho pom file with <packaging>eclipse-plugin</packaging>. During our automated build, we run one step early in the build process (just after check out) that calls mvn with the jar pom to populate the libs. Then we proceed with the main Maven/Tycho build using the eclipse-plugin pom. The eclipse-plugin pom has no dependency information (as I said above). It's just providing Tycho a way to recognize the Eclipse plug-in and build it based on its MANIFEST.MF and build.properties files. But the built plug-in includes and exposes all of those libs that were populated by the mvn call to the jar pom step.
So, it's a bit of a mess, but that's the best solution we found a couple of years ago when we hit this problem. I'm not sure whether Tycho is doing any work to permit some sort of hybrid Maven/Tycho build that could do this automatically as part of the build. I guess I should ask the developers. :)
Your questions:
Where do I add the dependencies? There's no pom with jar packaging in my project. Answer: The workaround above lets you do it with one project. You just have two pom files, like pom_deps.xml and pom.xml. You just have to invoke the pom_deps.xml separately to populate the libs folder (in the dev environment and with your automated builds).
Should I create a separate project with the necessary JARs? How do I include that dependency to my entire project? Answer: the workaround that I described above lets you do it with a single project. Another way to do it is to create a separate JAR project, but I don't think that your Eclipse RCP app can really include a <packaging>jar</packaging> module in a useful way. The only way I've found to do it is to use a similar workaround. You build the JAR module first, install it into the maven repository, and then have one of your plug-in projects bundle the JAR in its libs folder. (If you really want to do it that way, ask. We have a case where we have to do that, too, and I can provide the steps we do in development and the build to make it work. I think the single project workaround that I provided above makes more sense for your case.)
Is it really that much of a good practice to create a separate plugin and a feature for this RCP app? Answer: that's really a separate question. If you have a feature with multiple plug-ins, you have the same problem. Tycho can handle the product/feature/plug-ins, but it cannot jump across into Maven-based dependency resolution. You'll end up having to use the same workarounds
Summary: The fundamental issue is that Eclipse plug-ins can't "see" a bare JAR library. The plug-in needs to have the library included in its local libs folder (with a matching Bundle-ClassPath entry in MANIFEST.MF), or it needs to depend on some other plug-in that exports the appropriate packages. Tycho just resolves dependencies via Eclipse plug-ins, and it cannot leverage normal Maven dependency resolution directly to pull in a bunch of JARs. If all of your dependencies are already plug-ins, you're fine. If not, you may have to use the workaround above to package a set of libraries for your plug-ins to use.
Just adding the plugin to pom dependencies and including the entry <pomDependencies>consider</pomDependencies> in the configuration of target-platform-configuration makes it work.
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- The configuration to make tycho consider the maven dependencies -->
<pomDependencies>consider</pomDependencies>
<!-- other configurations -->
</configuartion>
</plugin>
<!-- other plugins-->
</plugins>
<dependencies>
<!-- An example third-party bundle (plugin) present in maven repository-->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Reference link here.

Maven Multimodule project issue?

Hi I have multimodule maven project something like this..
parent
Core
Web
and my Web project depend on Core project classes so i added Core project as a dependency in Web project pom.xml file.
But from inside eclipse when i am running Web project the lib directory does not contain Core-project.jar file in class-path so project not running. How can resolve this issue?..Plugin I used in my Web Projec *Pom.xml* file..
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
And i am using Tomcat6 Server.
this Dependency tag in my Web Project pom.xml File...
<dependency>
<groupId>org.csdc</groupId>
<artifactId>core-java</artifactId>
<version>5.0.0</version>
</dependency>
And When i run web project from inside Eclipse i am not getting core.jar in this path....
workspace_maven.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\web\WEB-INF\lib
Anyone got any such issue .If yes please let me know how can i resolve this issue?
Under Eclipse : you do not need to have your core.jar in your classpath. Check your librairies (web->properties->java build path->librairies), you should see your core folder and not your core.jar.
Make sure that "resolve workspace dependencies" is checked in your maven build target.
Install the m2e and m2e-wtp plugins for eclipse. m2e-wtp handles web projects and tomcat. You don't need the plugins sections of your pom that you've documented in the question.
For maven to work with projects in eclipse you need to ensure that the parent project is at the same level as the child projects and the pom of the parent project is like below
<modules>
<module>../project1</module>
<module>../project2</module>
</modules>
Unfortunately this is the only way to get maven to work correctly in eclipse and jenkins for multi-module builds.
Not exactly clear that this is what you are looking for, but the jars won't appear under your lib directory in eclipse because they are in your repository.
My version of eclipse has a 'maven' menu when I right click on the project. If yours does too then make sure that you have 'Enable Maven Nature' selected. This will make a small M appear next to the project name and a new folder in the project, which contains all of the dependencies listed in your pom.
1.Go to web project build path -> Libraries - Add variable -> Configure Variables -> New -> Enter Name as M2_REPO and Path as C:\Users\usernmee.m2\repository and click Ok.
All the dependencies will configured in the project build path. So no compilation error in web projecct.
2.Maven project need to take war and deploy it in any web container(tomcat,etc).
Check the war in your target directory after running mvn clean package. If it is missing there, check the scope of your dependency for "Core" in your pom.xml for "Web", make sure that it is not provided or test.
It sounds like from your pom fragment that you are using mvn eclipse:eclipse (which you shouldn't be anymore), instead use the m2eclipse plugin: http://www.sonatype.org/m2eclipse.
Install the correct set of plugins and configure them correctly.
If you need a more detailed answer, you should give us more information what you tried to achieve, which plugins you use, what kind of web server, how you deploy, whether you use Maben to deploy or the Eclipse WTP, etc.
[EDIT] You won't see anything in project/WEB-INF/lib when you start the project in Eclipse - there is no point putting anything in there because this folder isn't used.
Instead, you probably deploy the project to a web server. There are plugins for Eclipse which can do that (i.e. start a web server, deploy your project into it) but since you don't mention how exactly you "start" the project inside of Eclipse, which version of Eclipse you're using and which buttons you click, how you configured Eclipse, etc. it's really hard to help you.

Categories

Resources