maven adds version number to war - won't deploy - java

I'm using maven to build a war file for JBOSS AS 7. After a maven deploy, there is 'test.war' in the local repository, and a 'test-2.war' in the remote repository. This is all as expected (2 is the version in the POM).
If I manually deploy the 'test.war', everything works fine. If I deploy 'test-2.war' the deployment fails. If I rename 'test-2.war' to be 'test.war', the deployment works but trying to access it in a browser fails with error:
type Status report
message /test/Test
description The requested resource (/test/Test) is not available.
Since both war files are the result of the same maven build and deploy, why doesn't renaming the -2 version work the same as the first?
Is there a way I can deploy the -2 version without renaming, or what can I do to force the build so that I can rename the -2 version and have it deploy?
I know I can use maven's jboss deploy, but that's not an option in my case. I need the war file from the remote repository for manual deployments.
EDIT: The basic question here is why can't I rename the file {artifactId}-{version}.war to just {artifactId}.war and have it deploy in JBoss AS 7 properly?

You can rename the war like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>bird.war</warName>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
OR
<build>
<finalName>bird.war</finalName>
. . .
</build>
Take a look here

Related

NoModuleFileException: File does not exist for module having uri

I am deploying a J2ee project on websphere and I have set up artifacts,ear etc. with intelliJ.
It is a multi module maven project and was working fine till I have accidentally modified some set up in intelliJ.
What can be the reason? What intelliJ setting can influence this?I have tried to investigate pom but they looks fine and I haven not modified them before the issue.
The error is:
A file does not exist for module element having uri: namefile.war
If your war has snapshot change your ear plugin to skip versioning in the file name like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>6</version>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>

How to change JAR build path in Jenkins?

I am building a Java project via Jenkins. The JAR is being created (after I execute maven clean install in Jenkins) in C:\Windows\System32\config\systemprofile.m2\repository\com\other folders.
Is there any way to change this path? I want to sent the JAR to a VM via SSH. However, I am not able to access this folder since this is system directory.
Thank you.
For some reason, your Jenkins uses this directory as local Maven repository. I would define a different local repository in Jenkins or in the settings.xml. It is also important that you make sure that no two running builds use the same local repository at the same time because local repositories cannot be used concurrently.
If you are using maven to build, add the below to your pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>your custom location</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
By default, maven should create your build artifacts (including the JAR file) in target directory next to your pom.xml.
You can change this behavior in pom.xml by specifying the build directory:
<build>
<directory>/some/other/dir</directory>
</build>
The directory you are referring to is your local maven repository, which contains all JAR files maven is working with. You can read more about local maven repository here.

Adding Tomcat server remotely to Eclipse IDE

Normally in Eclipse we run, Tomcat v7.0 Server at localhost
Can we add a tomcat which is located remotely on another IP address?
Currently, I'm running programs in Windows. I need it to be run with tomcat server which is located on another IP address on Linux.
Convert your web project to Maven Project and copy and paste the below code to your pom file.
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://yourhost:8080/manager/text</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
Convert your web project to Maven Project and copy and paste the below code to your pom file.
org.apache.tomcat.maventomcat7-maven-plugin2.1http://yourhost:8080/manager/text
Yes the above code is working you need to configure remote ip to url section.

Fail to deploy WAR in Jenkins

I'm using Jenkins for the first time and I wanna try it in local before deploy in my company.
So I have a app.war generated from eclipse : it's a maven project.
I wanna to build it in Jenkins and then deploy it in Tomcat 6.
So I set the "right" configuration I think in Jenkins, but when I have launch the build, I got a successful build in my project but it's not deploying in tomcat .
I'll put my console Output of Jenkins and the configuration
Console Output Jenkins :
Configuration Jenkins
So what's wrong with that ? Thnx
Solution to your question -Edited
You have to select the appropriate container to deploy, from your question it is clear that you should choose Tomcat 7.X as a container.
Please use Jenkins Deploy Plugin which is configured with the following options as seen in the below link. Also this link will be your solution.
Also you can embed the Tomcat Maven Plugin in your pom.xml like below
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/YourPath</path>
</configuration>
</plugin>
Give the goals as clean install tomcat7:deploy -e

how to run a web service maven project on jetty 8 from eclipse?

I have a REST web service which I created previously and deployed in Tomcat7. I wanted to deploy it on Jetty, as advised in a previous question, I made a Maven project and copied my files there and configured the dependencies and I can run Maven install from eclipse successfully.
This is my build part in POM.xml:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<dependentWarExcludes></dependentWarExcludes>
<webappDirectory>
WebContent
</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
I followed instructions here to use maven jetty plug-in (I am not sure if this is required). The question here is how can I deploy my maven project in jetty from eclipse so that i can go to http:localhost:8080/myproject for example and see my project working?
EDIT:
The way I used to run the service on Tomcat was by right click on the project and click on Run As -> Run on server (which is configured in eclipse servers)
I am using eclipse Indigo, Maven 3 and jetty 8. Also I used jersey for the web service.
Here, you are mixing two different things:
Run your Web application using a Eclipse server plugin as Tomcat plugin for Eclipse.
Run your Web application using a Maven plugin as Jetty Maven plugin. There are also Maven plugins for Tomcat.
Having said that, take a look to this answer where it is described how to configure Eclipse to run Maven plugins (it could change depending on Eclipse version but idea would be similar)
Edited:
If you just want to run jetty from Maven, just use the following command line:
mvn jetty:run
But, in any case, I recommend that you indicate the Maven jetty plugin version in the pom file (Maven will warn you if you don't).
Edited 2
First, update your jetty maven plugin version:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
</plugin>
Second. You are working with two plugins, one for building the war file (maven-war-plugin) and another one for running your application on jetty (jetty-maven-plugin). Take in mind that jetty thinks your project has a standard maven project structure, it means, it will look for your web app content in /src/main/webapp but it looks like is not here. In your war plugin configuration, you specify that your web content is in WebContent, so tell jetty plugin that directory is there, as well as you are telling it to war plugin:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
<configuration>
<webAppSourceDirectory>/WebContent</webAppSourceDirectory>
<webXml>/over/here/web.xml</webXml>
<jettyEnvXml>/src/over/here/jetty-env.xml</jettyEnvXml>
<classesDirectory>/somewhere/else</classesDirectory>
<configuration>
</plugin>
See documentation. Of course, it is better to work with a standard maven project structure so you do not need to tell jetty where things are.

Categories