I know this has been asked a few times in the past, but I'm unable to find a solution (except for the "add the .jar to your project manually in Eclipse"..)
What I have:
A Maven project
A .jar web-service we've created (let's call it kc.ourwebservice)
After a clean install (in Eclipse or via the command line) and Full Publish in Eclipse (and yes, I have done an Update Maven Project - Force Update of Snapshots/Releases before that), this .jar can be found in:
This kc.ourwebservice.jar is present in our Nexus Repository Manager OSS
This kc.ourwebservice.jar is present in our Eclipse project at the Maven dependencies
This kc.ourwebservice.jar is present when I run mvn dependency:tree -Dverbose
This kc.ourwebservice.jar is present in my .m2 folder
However, it's missing from the deployed JBoss .war's lib folder, which is what my question is about.
I know I could manually add the .jar in Eclipse' Deployment Assembly (or org.eclipse.wst.common.component file), but every time I switch git branches or do an "Update Maven Project", it's gone again. And I also don't want to manually add this .jar when the project is put on a server.
I need a permanent solution so the .jar is correctly added to the deployed JBoss .war, using the Maven plugins that were designed for it.
One thing to add. This webservice has both an .aar and .jar. Both of them are necessary. The .jar when we're starting the application, so I gave it a <scope>compile</scope>, and all the .aar we use are only needed at runtime, so I gave it that scope (<scope>runtime</scope>).
Here is the relevant pom.xml code (lots of more dependencies, plugins and code at the ...'s, but those are irrelevant for this problem):
<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>
<parent>
...
</parent>
<artifactId>...</artifactId>
<packaging>war</packaging>
...
<properties>
...
<ourwebservice.version>1.0.0</ourwebservice.version>
...
</properties>
...
<plugins>
...
<!-- Takes care of copying the aar services to the WEB-INF/services -->
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-repo-maven-plugin</artifactId>
<version>1.7.3</version>
<configuration>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<stripServiceVersion>false</stripServiceVersion>
<services>...,ourwebservice</services>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<id>deploy webservices</id>
<goals>
<goal>create-repository</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<outputDirectory>${warOutputDir}</outputDirectory>
<webappDirectory>${webappDirectory}</webappDirectory>
<warName>${project.artifactId}</warName>
<!-- Tell the maven war plugin to use the merged web.xml -->
<webXml>${warOutputDir}/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
<webResources>
<resource>
<directory>${basedir}/src</directory>
<targetPath>WEB-INF/classes</targetPath>
<excludes>
<exclude>**/*.java</exclude>
<exclude>sample-properties.properties</exclude>
<exclude>sample-log4j.properties</exclude>
</excludes>
</resource>
<!-- Copy the generated services that were extracted from the dependencies to the WEB-INF/services folder of the war archive. -->
<resource>
<directory>${project.build.directory}/generated-resources/services</directory>
<targetPath>/WEB-INF/services</targetPath>
<includes>
<include>**/*.aar</include>
</includes>
</resource>
...
</webResources>
<!-- The axis2 services should not be stored in the WEB-INF/lib -->
<packagingExcludes>WEB-INF/lib/*.aar</packagingExcludes>
</configuration>
</plugin>
<!-- JBoss plugin used to deploy war file - http://mojo.codehaus.org/jboss-maven-plugin/ -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<hostName>${deploymentHostName}</hostName>
<port>${deploymentPort}</port>
<fileName>${deploymentFileName}</fileName>
<serverName>default</serverName>
<jbossHome>
//${deploymentHostName}/${jbossHome}
</jbossHome>
</configuration>
</plugin>
</plugins>
...
<dependencies>
...
<dependency>
<groupId>kc</groupId>
<artifactId>ourwebservice</artifactId>
<version>${ourwebservice.version}</version>
<type>aar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>kc</groupId>
<artifactId>ourwebservice</artifactId>
<version>${ourwebservice.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
...
</dependencies>
...
</project>
Does anyone has any idea why the .jar isn't deployed to the .war? Or better yet, does anyone know a solution so the .jar is always deployed to this .war when doing a clean install and publish?
All other .jar files are present in the .war, this webservice is the only one missing.
Related
We are using a third party library that doesn't exist in Maven Central Repository and we wan't to deploy this archive as an artifact to Artifactory. We are trying to do that via Artifactory UI and we successfully deployed both archive.jar and archive-sources.jar. The problem occurs when we add this dependency through Gradle to our build.gradle script. Archive.jar is fetched from our repository but archive-sources.jar is not fetched. We are developing with Eclipse and you can see the problem through screenshot.
We tried several things including defining classifier in Artifactory UI, editing pom with Artifactory POM Editor, publishing pom file manually and nothing worked. Whatever we do we couldn't get the source of this archive. Any kind of help would save a lot of time and effort. Thanks!
Screenshot of Artifactory UI:
We have solved the issue but it was a little bit complicated. There are many steps to apply the solution:
In the case of jain-sdp archive, here are the steps:
1- Deploy jain-sdp sources artifact with classifier "sources" as it is shown in the screenshot.
2- Manually upload jain-sdp.pom file with including the "sourceDirectory" tag:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>javax.sip</groupId>
<version>1.2</version>
<artifactId>jain-sip</artifactId>
</parent>
<groupId>javax.sdp</groupId>
<artifactId>jain-sdp</artifactId>
<version>1.0.1111</version>
<packaging>jar</packaging>
<name>jain-sdp</name>
<url>http://jain-sip.dev.java.net</url>
<build>
<sourceDirectory>../../src/javax/</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes>
<include>**/sdp/**</include>
</includes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/javax/</directory>
<includes>
<include>sdp/**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
</project>
3- Manually create the below files.
pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>javax.sip</groupId>
<version>1.2</version>
<artifactId>jain-sip</artifactId>
</parent>
<groupId>javax.sdp</groupId>
<artifactId>jain-sdp</artifactId>
<version>1.0.1111</version>
<packaging>jar</packaging>
<name>jain-sdp</name>
<url>http://jain-sip.dev.java.net</url>
<build>
<sourceDirectory>../../src/javax/</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes>
<include>**/sdp/**</include>
</includes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/javax/</directory>
<includes>
<include>sdp/**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
</project>
pom.properties:
#Generated by Maven
#Tue Feb 05 21:33:14 CET 2008
version=1.2
groupId=javax.sdp
artifactId=jain-sdp
4- Include the files that have been created in Step 3 to the below path in the archive:
META-INF/maven/javax.sdp/jain-sdp/pom.properties
META-INF/maven/javax.sdp/jain-sdp/pom.xml
Note that these files should be added to jain-sdp.jar, not jain-sdp-sources.jar
5- Upload jain-sdp.jar to the Artifactory through UI
I think that these steps should be done manually. There is no other way to solve this problem that I can think of. sourceDirectories should be included manually to pom files and archives manually.
Add your Source files into your jar, observing the same directory structure as for the class file contents.
This means you don't need to manage another artifact and don't need to update your pom.xml
Simplest steps to perform this addition is on the CLI: change into your source directory and "update" the jar. Doing it with this specific current working directory which will preserve the correct relative filenames.
For example, I have directory structure:
~/project/src/com/mycompany
~/project/target
and have built a jar into ~/project/target named existing.jar
$ cd ~/project/src; jar uvf ../target/existing.jar com
$ jar tvf ~/project/target/existing.jar
should show class files and source files in the same tree.
...
6923 Sun Sep 18 23:19:36 PDT 2016 org/spacehq/reddit/util/http/ResponseType.class
4676 Sun Sep 18 22:30:38 PDT 2016 org/spacehq/reddit/util/http/ResponseType.groovy
...
IntelliJ IDEA detects these source files in the jar and presents them when opening the related class file. I'd assume other full featured IDEs would also.
You should of course be able to automate this somehow with Maven, to take out the human step, but this is good for a one-off.
I created a dynamic web application in eclipse Version: Kepler Service Release 1 using menu.
After that I converted it into a maven project using
configure -> convert to maven project. Then I did
maven->Add dependency and then searched for log4j.
After adding that on hovering over the tag
for log4j it displays Missing artifact log4j:log4j:bundle:1.2.17.
I can't update dependencies using maven. How to fix it?
Please also explain the reason for the error.
Here is the generated xml after adding log4j.
<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>Healthcare</groupId>
<artifactId>Healthcare</artifactId>
<version>0.0.1-HEALTHCARE</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>bundle</type>
</dependency>
</dependencies>
</project>
First why did you changed the default source folder location? The default is src/main/java and for webapp src/main/webapp. Apart from that a bundle for log4j does not exist on Maven Central just remove the <type>bundle</type> from your dependency, cause in Maven Central only a jar is available.
I always do the following trick:
In the dependencies management i edit the dependencies properties (select the dependencies with problem and click on properties button) changing the type from bundled to jar and that fixs the problem.
Well i hope that this solution work for you :) regards,
I too played with all the options provided above but it did not helped. By updating Maven dependencies forcefully my issue got resolved.
Go to project >> Maven >> Update Project
select the project and click OK.
Project will automatically try to download required jar but if still you are getting same error then do below step.
Go to project >> Maven >> Update Project >> check in the checkbox 'Force Update of Snapshots/Releases'
select the project and click OK.
Please check if the dependencies are correct or if it is missing.
<properties>
<springframework.version>4.2.1.RELEASE</springframework.version>
<jackson.version>2.5.3</jackson.version>
<log4j.version>1.2.17</log4j.version>
</properties>
By default (and the common usage), Maven would consume jars as a dependency. Just change the bundle to jar in your pom.xml file in the given dependency which is giving you an error.
My RCP was created on a 3.x Eclipse and is now on 4.x using the compatibility layer.
This is the setup that I have: I have two plugins: xyz-plugin and xyz-rcp-plugin. My RCP application is composed of these two plugins. I have a Test fragment (xyz-test) whose host plugin is xyz-plugin and contains SWTBot tests. My product configuration points to the application defined in the plugin.xml of xyz-rcp-plugin.
When I run the SWTBot Test via Eclipse, it all works ok. I point it to the correct application on the Main tab and it launches the correct one.
When I try to run it via Maven (using mvn integration-test), after the command to launch the UI for testing, no UI opens and it just reports saying there are test failures but it never actually even reaches the stage for testing my cases.
I feel this is happening because my test fragment only has xyz-plugin as its host and so knows its dependency but the application is actually contained in xyz-rcp-plugin so I am guessing it doesn't bring that plugin into the testing workspace. In fact, the test runs when I omit the <application> configuration in my pom file; it simple launches the default which is the Eclipse SDK.
So but how can I make the SWTBot test run my application, if the plugin with the application is not a dependency of the test plugin?
Below is my pom file for the test fragment,
<?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>
<parent>
<groupId>com.xyz</groupId>
<artifactId>all</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>com.xyz.test</artifactId>
<packaging>eclipse-test-plugin</packaging>
<properties>
<ui.test.vmargs></ui.test.vmargs>
</properties>
<profiles>
<profile>
<id>macosx</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<ui.test.vmargs>-XstartOnFirstThread</ui.test.vmargs>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<product>com.xyz.rcp.product</product>
<application>com.xyz.rcp.Application</application>
<argLine>${ui.test.vmargs}</argLine>
<dependencies>
<dependency>
<!-- explicit dependency is only needed because SWTbot brings its
own hamcrest bundle which conflicts with the one from junit in the eclipse
platform -->
<type>p2-installable-unit</type>
<artifactId>org.hamcrest</artifactId>
<version>0.0.0</version>
</dependency>
</dependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-xyz</id>
<phase>compile</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
<includeTypes>tar.gz</includeTypes>
<outputDirectory>${project.build.directory}/work</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Tycho does not automatically add the bundle defining the configured <application> to the test runtime - you need to manually ensure that this bundle is included.
One way to do this is to specify extra dependencies in the pom.xml of the test project. In this way, you can add bundles or even entire features (as always, including transitive dependencies) to the test runtime.
Example pom.xml snippet:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>xyz-rcp-plugin</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
I installed m2eclipse plugin in my eclipse.I have a java project in eclipse. Then I add a pom.xml into the root folder of my project. Convert my project into maven project. Now the problem comes: I can download jar contained in pom.xml, but can't import it into my java file.
Always got java compile error in my project. In package explorer view,I can see maven dependencies.
I have tried this:maven clean, restart eclipse, project clean.
Here is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TomLabs</groupId>
<artifactId>TomLabs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Tom source code</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>
</project>
One possibility could be the package/class what you are trying to import is not available in the version of the jar file you have mentioned in the pom.xml.
Assuming the following pom.xml maven would build a client.war file which when deployed to Tomcat will have the URL www.server.com:8080/client/
What would one have to change so the application can be reached at the server root www.server.com:8080/?
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>client</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>...</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>target/generated-resources</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
...
</plugins>
<finalName>client</finalName>
</build>
...
</project>
I believe you can leave the war named client.war if you'd like. Then configure the tomcat6 plugin, setting the path like this:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<!-- put the configuration in an execution if you want to... -->
<configuration>
<path>/</path>
<warFile>${project.build.directory}/client.war</warFile>
<!-- other config options here -->
</configuration>
</plugin>
I haven't used tomcat7 version of the plugin, but I'm guessing it's similar.
Since you're using the combination of eclipse, tomcat, and maven, I'm going to make the guess that the m2e-wtp plugin is in use here. There's a FAQ that addresses this. This also shows though how to change your context root in a maven specific way (using the war plugin for specifying a finalName for the war) which results in a correctly named war file (such as ROOT.war as mentioned in other answers.
Maven war plugin (which is defined on super-pom by default) will only generate a war file. It's up to you to set up your app on Tomcat. If you want to add the "deploy to a container" to your maven build, go with Tomcat Maven Plugin or Cargo Maven Plugin.
What you want has nothing to do with Maven, actually. Setting your war name to ROOT.war should do it (<finalName>ROOT</finalName> on your build section), but if you want to add your context.xml to the war file, you could do something like (assuming src/main/webapp is your webapp folder defined by maven):
`<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<webResource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<includes>
<include>context.xml</include>
</includes>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
</configuration>
</plugin>
`