Change name of dependency jar before upload on remote repository - deployment

Here, the story of my problem :
I want to upload a jar with a pom.xml with deploy command, but i want the jar uploaded doesn't contains in this name the version number.
For example, the pom.xml for the jogl.all.jar :
<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>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl.all</artifactId>
<version>2.0-b526-20111018</version>
<packaging>jar</packaging>
<name>Jogl</name>
</project>
My deploy cmd :
mvn deploy:deploy-file
-Durl=http://maven.iscpif.fr/thirdparty/
-DrepositoryId=maven.iscpif.fr
-DgroupId=org.jogamp.jogl
-DartifactId=jogl.all
-Dversion=2.0-b526-20111018
-Dfile=./jogl.all.jar
-DpomFile=./pom-jogl-all.xml
-Dpackaging=jar
The deployed jar equal here : jogl.all-2.0-b526-2011108.jar
But, when i call this dependency i want maven try to download a jar with this name : jogl.all.jar
Thanks for your advice :)
SR.

You cannot change the artifact name if you are deploying to a remote repository. This would break the way maven works.
Refer to #Pascal's comment in this related SO discussion as well.
You can change the name of the dependant jars while including them in the distribution using maven assembly plugin by using the property outputFileNameMapping. Something like the following:
<dependencySets>
<dependencySet>
<outputDirectory>/webapps/myapp/WEB-INF/lib</outputDirectory>
<excludes>
<exclude>${project.groupId}:${project.artifactId}</exclude>
</excludes>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
</dependencySets>

Related

How to do a modular project architecture with Maven in Eclipse?

First of all im a little newbie in Maven+Eclipse world, so please excuse me if im not explaining myself good.
Im trying to implement Maven to existing Java old projects, the architecture im trying to achive is something like this (i put an image to explain myself a little better):
The project Utils have the most of the libs, that genericlly will be used for the other projects, and some classes that will be useful for the others (like date comparison method and mathematic method etc...), this project is working well with mvn install, generating the respective .war file.
The questions are:
The N Web Modules projects must have the project Utils as a
depedency and the most of dependencies too. I
don't know how to achive this in the pom.xml of N Web Modules
projects.
I don't know if it is posible in
Eclipse+Maven: Try to do some Parent Web Project that
implements the other projects and in one single mvn install the
parent project build and install the rest of the childs
(including Utils and N Web Modules).
I hope you can orientate and help me with this.
I think you are looking for Multi-Module projects
http://books.sonatype.com/mvnex-book/reference/multimodule.html
You can put various subprojects in one larger project and build them all at once. Furthermore, modules can depend on other modules (as long as this is not circular) and they are build in the correct order.
The project Utils have the most of the libs, that genericlly will be
used for the other projects, and some classes that will be useful for
the others (like date comparison method and mathematic method etc...),
this project is working well with mvn install, generating the
respective .war file.
One advise, you should extract classes used by other projects in a maven project with a JAR packaging and not leave them in a WAR packaging.
In Maven, generally, dependencies are provided as JAR.
It may also be provided as WAR by configuring the maven-war-plugin with some specific properties such as attachClasses but it looks like a trick and it also may create side effects.
Here are some information on how to do it.
But the documentation doesn't advise this way :
If you need to re-use this JAR/WAR in another project, the recommended
approach is to move the classes to a separate module that builds a
JAR, and then declare a dependency on that JAR from your webapp as
well as from any other projects that need it.
About your two questions.
The N Web Modules projects must have the project Utils as a dependency
and the most of dependencies too. I don't know how to achive this in
the pom.xml of N Web Modules projects.
Just include it as a dependency in the dependencies element of the consumer project :
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>mygroup</groupId>
<artifactId>project1-consumer</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
</dependencies>
</project>
I don't know if it is posible in Eclipse+Maven: Try to do some Parent
Web Project that implements the other projects and in one single mvn
install the parent project build and install the rest of the childs
(including Utils and N Web Modules).
What you are looking for is designing a multi-module project.
It relies on a aggregator pom that declares each module.
Note that this module has to be specified with a pom packaging as it doesn't produce a consumable artifact.
You could define something like that :
<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>mygroup</groupId>
<artifactId>myaggregatorpom</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>util</module>
<module>project1-consumer</module>
<module>project2-consumer</module>
</modules>
</project>

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.

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.

m2eclipse and/or wtp not packaging a dependency correctly?

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.