m2eclipse and/or wtp not packaging a dependency correctly? - eclipse

Eclipse Indigo SR 1, wtp 3.3.0, m2eclipse 1.0.100.
When publishing a project to WTP, I'm getting strange behavior with one of the dependencies; instead of putting the jar in the WEB-INF/lib folder, it's creating a folder named for the expected jar, and then putting the source tree (apparently) from that project under that folder. I can't see anything in the dependency's pom.xml or this project's pom.xml that could be causing this.
Other dependencies are being brought over just fine, as jars.
My test project's pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>dwhwtptest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>dwhwtptest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-nyc-transit-data</artifactId>
<version>2.0.3-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>dwhwtptest</finalName>
</build>
</project>
Here's what ends up being published at workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps:
$ find dwhwtptest/
dwhwtptest/
dwhwtptest//index.jsp
dwhwtptest//META-INF
dwhwtptest//META-INF/MANIFEST.MF
dwhwtptest//META-INF/maven
dwhwtptest//META-INF/maven/test
dwhwtptest//META-INF/maven/test/dwhwtptest
dwhwtptest//META-INF/maven/test/dwhwtptest/pom.properties
dwhwtptest//META-INF/maven/test/dwhwtptest/pom.xml
dwhwtptest//WEB-INF
dwhwtptest//WEB-INF/lib
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/META-INF
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/META-INF/MANIFEST.MF
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/model
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/model/NycQueuedInferredLocationBean.java
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/model/NycVehicleManagementStatusBean.java
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/services
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/services/ConfigurationService.java
dwhwtptest//WEB-INF/lib/onebusaway-nyc-transit-data-2.0.3-SNAPSHOT.jar/org/onebusaway/nyc/transit_data/services/VehicleTrackingManagementService.java
dwhwtptest//WEB-INF/web.xml
And here's the pom.xml for the dependency, the onebusaway-nyc-transit-data module:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>onebusaway-nyc</artifactId>
<groupId>org.onebusaway</groupId>
<version>2.0.3-SNAPSHOT</version>
</parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-nyc-transit-data</artifactId>
<packaging>jar</packaging>
<name>onebusaway-nyc-transit-data</name>
<description>Common interfaces and classes for exchanging transit data between UI front-end and transit back-end data sources.</description>
<build>
<finalName>onebusaway-nyc-transit-data</finalName>
</build>
</project>
Suggestions? Anything else I can investigate to try to figure out what's going on here?

A colleague of mine provided me an approach that fixed the issue, but it requires few manual steps.
remove the project from your eclipse
go to your maven root folder with a terminal and kill all the eclipse stuff using this command (you will have to do this twice):
$> find . -iname ".settings" -exec rm -rf '{}' \; ; find . -iname ".project" -exec rm -rf '{}' \; ; find . -iname ".classpath" -exec rm -rf '{}'
on your maven root, execute this command:
$> mvn -Dwtpversion=2.0 eclipse:eclipse
import your project back in eclipse: everything will now work and eclipse will be publishing jars containing code :)
HTH, Bruno (credits to Theodore!)

I suggest trying out the m2e-wtp plugin in addition to your currently installed m2e plugin (which doesn't contain support for WTP based projects) This plugin is available in the Eclipse Marketplace via the embedded Marketplace client or on the web (http://marketplace.eclipse.org/content/maven-integration-eclipse-wtp). It provides a tighter Maven integration with WTP and should improve the overall Maven with WTP experience.

If things still don't work go delete the publish folder. It will look something like:
<Path To Your IDE>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
First make sure you REMOVE the project under Tomcat or whatever other server you are using from withing the IDE. Then close the ID or you cannot delete the folder.
Once you do this, you can run your maven clean/build/install command and deploy your project.
If this does not work, this problem isn't related to the IDE or the Application Server.

Related

Get eclipse plugin for JAR distribution

I want to use io.reactivex rxjava in Eclipse RCP application.
What is the best way to get it as eclipse plugin, including a source plugin?
Is there a project doing those convertions?
It is not included into the eclipse/orbit.
Or do i need to do it on my own?
Frank
If the original provider is not making an OSGI ready bundle for you (i.e. adding in the few extra bits to the MANIFEST.MF), you can make your own bundle with the Eclipse Bundle Recipes (EBR).
As of writing this (Oct 2015) Eclipse Orbit is currently moving to EBR for new bundles as they are packaged up. But you can do your own. Hopefully by time time some future person reads this, the EBR website will be a bit more complete https://www.eclipse.org/ebr/, but for now these slides and blog posts should get you started:
https://www.eclipsecon.org/na2015/sites/default/files/slides/Tasty%20Recipes%20for%20OSGi%20Bundles.pdf
http://wagenknecht.org/blog/archives/2014/02/eclipse-bundle-recipes.html
The basic idea is you need to connect it up to Maven with a pom.xml that looks a little like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>apache-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.apache.commons.codec</artifactId>
<version>1.9.0-SNAPSHOT</version>
<packaging>eclipse-bundle-recipe</packaging>
<name>Apache Commons Codec</name>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</project>
This works along with the bnd file that looks a little like this:
package-version=${version;===;${Bundle-Version}}
Export-Package: \
*.internal*;x-internal:=true;version="${package-version}", \
*.impl*;x-internal:=true;version="${package-version}", \
*;version="${package-version}"
Import-Package: \
*
And there you go, with the above and a simple maven invocation, you have an OSGI bundle to use with your Eclipse RCP application.
Note that you will probably come across the question of what to name the bundle you are creating, Eclipse has some guidelines that may help: https://wiki.eclipse.org/Bundle_Naming

How to create a maven project in eclipse which give a war which in turn contains sub modules as jar?

I am having client requirement that maven project which generate a war which in turn contains submodules as the jar?
let me clarify the question
This is my master pom.xml inside that i am having two modules named child1 and child2.
I need a MasterWebApp.war inside which the child1.jar and child2.jar presents.
If i changing the packaging as war to packaging - pom then error disappeared but i cant get the required war while maven clean install
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc</groupId>
<artifactId>MasterWebApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Master Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework.version>4.1.7.RELEASE</org.springframework.version>
</properties>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
.......
you can execute two ways.
1) in eclipse.
Right click on project , click on run as --> maven build , give goals as "clean install" will generate war in target folder of your project
2) using command prompt, navigate to directory where pom.xml present and execute below commands
mvn clean install package
it will generate war in target folder
Thanks Raghav, i searched for any alternative way to achieve this, but no more available, so i used the way which u gave the link.
Thanks for the help.

Missing Maven dependencies in Eclipse multi-module project

I’m using STS 2.9.1 (build on Eclipse 3.7.2) with m2e plugin bundled with STS (v1.0.200.20111228-1245).
I have a problem regarding missing dependencies in Eclipse project that contains several modules, or maybe I don’t fully understand how it should work.
It’s a maven project.
In my Project > Properties > Java Build Path > Libraries I have “Maven Dependencies” library, but it's empty (and that’s the problem).
The main POM doesn’t have any dependencies, but it has several modules declared in it.
Adding a dependency to module’s POM doesn’t add it to the “Maven Dependencies” library (what was my expectation) and leads to Eclipse showing errors in source files.
Adding a dependency to the main POM adds it to the “MD” lib, but of course I don’t want to add all of my modules’ dependencies to the main POM just to have it in “MD” lib and adding every single dependency to the Build Path doesn’t seem right nor practical.
I’ve tried:
Project > Clean,
Maven > Update dependencies,
Maven > Update project configuration,
Unchecking the checkbox: Project > Properties > Maven > Resolve dependencies from Workspace projects.
None of the above seems to do the trick.
Example:
Simplified project structure:
simple.project
...
sample-module
...
pom.xml
pom.xml
simple.project/pom.xml:
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>simple.project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sample-module</module>
</modules>
<dependencies>
<dependency><!-- This dependency is present in "MD" lib. -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
simple.project/sample-module/pom.xml:
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>simple.project</artifactId>
<groupId>test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>test</groupId>
<artifactId>sample-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency><!-- I've expected this dependency also to appear in "MD" lib. -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
It is not supposed to work. A project only imports a dependency from another one if it depends on that project (using dependency) or if it inherits from it (using parent). The module element only represents an aggregation.
The question is from time ago, but I solved this creating a Maven Project and adding Maven Modules: right click on project and "New > Project... > Maven > Maven Module".
After that, no more errors were shown in code.
First thing that I see is that you're defining dependencies in a pom parent. There I would expect to see a <dependencyManagement> (see here the doc) structure. In this way the submodules will inherit properly those common dependencies.
Aside from that lets start for the most simple test. Try to compile your project from the maven utility in the command line. If it works then you have a problem in your Eclipse configuration, otherwise the problem is in the way you have defined your project.
If your project compiles properly from the command line, lets see what else can be happening.
The fact that the Maven Dependencies Library is empty means that the Eclipse Maven plugin is not resolving properly your poms. I had quite bad experiences with the embedded STS maven plugin. Try to downgrade it to the m2e 0.10 version. You only need to open the STS DashBoard / Find Updates / Install m2e 0.10
I hope some of these tips can help you.

Plugin JARs are missing in an application built with Tycho

I am building an Eclipse application with Maven Tycho. I managed to create the pom files for building the plugins and features. I ran install on them and got Build successful. I have also cretaed the pom for the application (product) and set the Packaging to "eclipse-application". The application is feature-based. I ran install and got the Build successful. I got the generated folder for the application, containing the folders "plugins" and "features".
The problem is that not all the jar files, for all the plugins, can be found in the plugins folder. I can find the jar files for the plugins that are listed in the features. But the jar files for the plugins listed in the Dependencies tab of other plugins are not generated. In other words, only the plugins referenced in the features are generated as jar files, while the jar files for the ones referenced in the plugins are not generated.
Obviously, I cannot run the application without them. What am I doing wrong? How can I get all the required jar files generated?
Thank you!
Firstly, don't use eclipse-application. It has been deprecated, and, being someone that has tried to make it work with his own projects, I can tell you that it's a bad idea as it has a lot of problems. Instead, use eclipse-repository.
Secondly, the only .jar files that will show up in your products plugins directory will be ones that have compiled successfully, and are also in the dependencies section of your .product file, and not your manifest.mf.
I suspect that your problem is related to the second point, but I've seen eclipse-application do so many odd things that it alone might resolve your issue.
The first answer is on the right track... Use eclipse-repository.
To have Tycho generate a repository, you are probably using the tycho-p2-repository-plugin ... And if you're using that plugin, then you may want to add this little element to the configuration section.
<includeAllDependencies>true</includeAllDependencies>
Here's a larger sample of my pom.xml that's in my p2repository plugin.
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.domain.product</groupId>
<artifactId>parent</artifactId>
<version>1.1.8-SNAPSHOT</version>
<relativePath>../my.domain.product.parent</relativePath>
</parent>
<artifactId>my.domain.product.p2repository</artifactId>
<packaging>eclipse-repository</packaging>
<name>My Product - P2 Repository</name>
<build>
<plugins>
<plugin>
<groupId>${tycho-groupid}</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
<createArtifactRepository>true</createArtifactRepository>
<compress>true</compress>
</configuration>
</plugin>
</plugins>
Hope this helps.

Maven and Eclipse code organization

I'm new to Maven, and after having read the docs on the maven site and Sonatype's online Maven book, I'm still not clear on how to best organize things.
I have two apps, A and B which share code from mylib. Different developers work on apps A and app B, they are released independently. Before we started with maven, in Eclipse, I'd have a workspace with apps A and B and mylib. The classpath for app A contained mylib. If I made a change in mylib, pressing run within Eclipse, contained my latest changes.
In Maven, I can create a parent pom.xml, which references app A and mylib. But this makes mylib a subdirectory of app A. How can I keep one instance of mylib and not link the building of apps A and B?
We use SVN for our SCM
Thanks
You have multiple options, however, potentially the simplest approach would be to separate out mylib into its own Maven project with its own life-cycle. The benefit of this approach is that you can support having multiple versions of mylib and your apps A and B can reference different versions of mylib as needed. If mylib and appA are open in Eclipse (and mylib references the version of mylib you have open), you can build the application in the same manner as you did prior to using Maven.
This approach does not mandate any dependencies between the directory structures of the applications, so you could go with something similar to the following:
/myapps/mylib
/myapps/appA
/myapps/appB
The downside to this approach is that maven will not automatically build both appA and mylib (or appB and mylib) as they are treated as separate applications. However, this may not be much of an issue if your applications are using pre-defined and built versions of mylib (that have been uploaded to your local maven repository using "mvn install").
Here is an example of the POMs for these projects:
mylib:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>myLib</artifactId>
<versioning>0.0.1</versioning>
<packaging>jar</packaging>
<name>mylib</name>
...
</project>
appA:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>appA</artifactId>
<packaging>jar</packaging>
<name>appA</name>
...
<dependencies>
<groupId>com.text</groupId>
<artifactId>mylib</artifactId</artifactId>
<version>0.0.1</version>
</dependencies>
...
</project>
appB:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>appB</artifactId>
<packaging>jar</packaging>
<name>appB</name>
...
<dependencies>
<groupId>com.text</groupId>
<artifactId>mylib</artifactId</artifactId>
<version>0.0.1</version>
</dependencies>
...
</project>
If you still want the convenience of a parent POM (one mvn package comment), then you could create a master pom in the /myapps folder similar to the following:
<project>
<groupId>com.test</groupId>
<version>0.0.1</version>
<artifactId>myapps</artifactId>
<packaging>pom</packaging>
<name>myapps</name>
<modules>
<module>shared</modules>
<module>appA</modules>
<module>appB</modules>
</modules>
</project>
This POM will automatically build myapp, appA and appB. If desired you could also create an appA and appB specific POM (pom-appA.xml). This is not the cleanest approach from a Maven perspective, but it will function. The only issue you would run into is if the version of mylib is not the version on which appA or appB is dependent. In that case your appA or appB code would be compiling against the version in your maven repository (if that version exists).
There are many other options you can use as well and I have seen plenty of discussions on Blogs and Wikis as to which is the best for various scenarios. However, it usually comes down to what works best for you and your organization. As long as it works and you are not going off building a custom, non-portable maven solution, then you are probably doing ok.
Hopefully this gives you some thoughts that you can use.