Deploy war file to jetty using jenkins - java

I deployed the war file to tomcat using jenkins as a post-build action
WAR/EAR files=**/demo.war
Context path=application
Container=tomcat 7
Manager user name=admin
Manager password=admin
Tomcat URL=https://localhost:8080/
How to deploy a war file to jetty instead of tomcat using jenkins. The project is a maven project which does not have any plugin for jetty.

I think the simplest way to do this is the following:
1. Add to pluguns of pom.xml next lines
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.1.v20140108</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>stopKey</stopKey>
<stopWait>20</stopWait>
</configuration>
</plugin>
2. Change goals to
mvn jetty:stop jetty:run-forked
If you cannot change pom.xml then you can create separate pom.xml (on other folder). And run the same tasks with this pom.xml. Post Steps > Invoke top-level maven target > advavanced

Related

How to deploy a module in an Alfresco deployed in Tomcat

I have successfully deployed alfresco community 4.2.f in a Tomcat 7.0.59 with a database MySQL5.6 and jdk1.8.0_141
No problems thus far, now, I got a module developed by our company which I need to be deployed in alfresco. This module invokes a WS which will send a PDF to some place.
I got this module in a jar compiled with jdk1.8.0_141
I tried to put it inside the alfresco.war before deployment in Tomcat in WEB-INF/lib but when I do that and deploy with startup.bat from Tomcat it pops in the console
instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/xfire/XFireRuntimeException
I understand this exception is caused by putting the jar inside the war.
I was told that the jar was compiled also in jdk8.
Also, tell you that if instead of this jar I put inside the alfresco.war in WEB-INF/classes a properties file to get our database in deployment it works fine.
The problem is when I try to deploy the module.
I saw there are quite tutorials pointing to do something like:
java -jar bin/alfresco-mmt.jar
I can't do that because this is done installing alfresco with its wizard I assume. I did it deploying alfresco in a fresh tomcat installation.
Does anyone know how to deploy our module with the way we deployed alfresco? Thank you.
You have two ways to install your amp :
The first traditional one :
This is the one installed with the apply amp procédure (alfresco-mmt).
To me, this is not true that it is not compatible with your installation. You can easily find the bin folder (containing the alfresco-mmt.jar file) here in the alfresco packaging : https://download.alfresco.com/release/community/4.2.f-build-00012/alfresco-community-4.2.f.zip
When you have it, you can follow the documentation : http://docs.alfresco.com/4.2/tasks/amp-install.html
And apply your amp for example following this way :
java -jar alfresco-mmt.jar install <AMPFileLocation> <WARFileLocation>
The second one :
You can recreate the war with the alfresco sdk and include in the build the module you created.
If you follow this documentation : http://docs.alfresco.com/4.2/tasks/dev-extensions-maven-sdk-tutorials-all-in-one-archetype.html
the war produced in the target folder of the repo part will contain your module, since the pom of this module will contains a dependency to the amp module :
...
<dependencies>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
</dependency>
<!-- Demonstrating the dependency on the repo AMP developed in the 'amp'
module -->
<dependency>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<version>${my-amp.version}</version>
<type>amp</type>
</dependency>
</dependencies>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- Here is can control the order of overlay of your (WAR, AMP, etc.)
dependencies | NOTE: At least one WAR dependency must be uncompressed first
| NOTE: In order to have a dependency effectively added to the WAR you need
to | explicitly mention it in the overlay section. | NOTE: First-win resource
strategy is used by the WAR plugin -->
<overlays>
<!-- Current project customizations -->
<overlay />
<!-- The Alfresco WAR -->
<overlay>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
<!-- To allow inclusion of META-INF -->
<excludes />
</overlay>
<!-- Add / order your AMPs here -
<overlay>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<type>amp</type>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>

Disable distributionManagement in Maven POM

I am trying to run a mvn deploy goal with maven on my Liferay portlet but am getting the following error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.
2:deploy (default-deploy) on project MyPortlet: Deployment failed: repository eleme
nt was not specified in the POM inside distributionManagement element or in -Dal
tDeploymentRepository=id::layout::url parameter -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on pro
ject RiskID: Deployment failed: repository element was not specified in the POM
inside distributionManagement element or in -DaltDeploymentRepository=id::layout
I understand this error will return if you don't include the <distributionManagement /> tag in the pom.xml, however I don't wish to package this to a remote location and would like to instead deploy to my local tomcat instance; can this be configured?
The error is not about dependencyManagement but rather distributionManagement
Deployment failed: repository eleme
nt was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
The alternative (if you don't want to place it in your pom.xml file) is also provided by using the altDeploymentRepository option:
Specifies an alternative repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ).
Format: id::layout::url
The first element, the id, must have a matching with a server defined in your settings.xml file (where you specify the credentials to use for the specific server).
The layour and the url are then specific to the target repository.
You can then invoke the command as:
mvn deploy -DaltDeploymentRepository=test:Maven2:http://somewhere:someport
Where test is the id of a server element in your Maven settings
<servers>
<server>
<id>test</id>
<username>my_login</username>
<password>my_password</password>
</server>
</servers>
Update
Based on latest clarifications (via comments and edits), here some important points:
The Maven deploy phase is meant for
done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
Hence, in your case you don't need to use the deploy phase nor the maven-deploy-plugin.
Since Tomcat is the target server, you then need to use the tomcat7-maven-plugin
Here are few instructions:
Configure your pom.xml
Add to your pom.xml the following:
<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>tomcat8</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
Configure your settings.xml
Add to your Maven settings.xml the following in the servers section:
<server>
<username>maven</username>
<password>maven</password>
<id>tomcat8</id>
</server>
Note the matching tomcat8 id between the settings and the plugin configuration above, server element.
Configure Tomcat for deploy
In the tomcat conf folder, configure the tomcat-users.xml file:
<role rolename="manager-script"/>
<user username="maven" password="maven" roles="manager-gui,manager-script"/>
note the credentials matching with what we actually specified in the Maven settings.
Try it
Then from the command line you can finally invoke:
mvn tomcat7:deploy
If you don't want to configure settings.xml nor pom.xml, you then need to pass several parameters via command line as following:
mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy \
-Durl=http://localhost:8080/manager/text \
-Dusername=maven -Dpassword=maven
Note: \ and newlines added for readibility
Check full list of options on the official documentation of its deploy goal.
#A_Di-Matteo's answer is correct for deploying to tomcat. But if you came here looking for how to deploy to a Maven repo without putting repo URLs in pom.xml then here's your answer:
mvn deploy -DskipTests -DaltDeploymentRepository=myrepoid::default::https://maven.example.org/repository/maven-releases
Instead of altDeploymentRepository, you could also use altReleaseDeploymentRepository or altSnapshotDeploymentRepository
More details in docs: https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

Reloading JSPs edited in Eclipse, run with tomcat7-maven-plugin

How can I get a Tomcat instance started with tomcat7-maven-plugin on the command line to reload JSPs when I edit and save them in Eclipse? It's of note that I don't want to start Tomcat via Eclipse, as I depend on some Maven plugin executions that m2e doesn't know how to map.
I start Tomcat thusly, on the command line:
mvn clean package -U tomcat7:run-war-only
Here is the configuration of the Tomcat plugin:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<systemProperties>
<spring.profiles.active>local</spring.profiles.active>
</systemProperties>
<path>/</path>
<port>8080</port>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
When I change and save a JSP in the source of the project, it'd be lovely if Tomcat could reload that without having to go through a full clean/compile/test/package/start cycle.
This can be done by adding a tomcat server plugin to your eclipse and then deploying your war in tomcat through eclipse and not from command line.
If you do that, when you make any changes in JSP or Java, eclipse auto refreshes your war with out you manually triggering it.
Try
mvn clean package -U tomcat7:run
As run-war-only run a packaged war so won't see your code changes.
if you want debug in your ide use
mvnDebug clean package -U tomcat7:run
Then attach a debugger to port 8000
HTH

War context root change is not reflected in WebSphere made through Maven and deployed using MyEclipse

I am using WebSphere 7 and trying to deploy war from MyEclipse (Server > WebSphere 7 > right click > Add Deployment).
I am using below maven war plug-in:
<groupId>com.xxx.my.app</groupId>
<artifactId>my-app</artifactId>
<packaging>war</packaging>
<name>my-app</name>
<build>
<finalName>my-app-context-root</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
To change context root of my war I tried below options:
First option:
<properties>
<m2eclipse.wtp.contextRoot>my-app-context-root</m2eclipse.wtp.contextRoot>
</properties>
Second Option:
<finalName>my-app-context-root</finalName>
But no Luck so for with these options. Whenever I deploy my application/war from MyEclipse and check context root in WebSphere server, WebSphere still shows the context root as 'my-app' (which is mentioned in name tag) not 'my-app-context-root'.
One approach could be changing the war file [ my-app tag] to context root name. This way it will deploy the application with desired context root name.
deploy your war file or application in myeclipse tomcat server and right click on the project folder, select properties and go to web option from the MyEclipse menu. there you can change the context-root of an application. The below link may helpful to you.
Change application context-root in myeclipse
For the direct deployment by MyEclipse, MyEclipse generates some special configuration files like the ibm-web-bnd.xml. These files contain the root path. If you want to specify the context root you have to either get those to work WAS specific files to work or pack your war file into a ear file and deploy the ear.

What defines the "war-ness" of my project?

I'm running the goal: tomcat:deploy. There are no errors, but it's not deploying my project into tomcat. I noticed this message:
[INFO] Skipping non-war project
What defines the "war-ness" of my project? How do I make my Eclipse project a war project?
Here's my plugin setting:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
I have my structure like this:
src > main > java
src > main > webapp > WEB-INF > web.xml
This one works with the maven:war plugin. I'm able to build a war with this structure.
My end objective is to do away with the war building part and be able to deploy my project to tomcat with one maven command.
Maybe you are missing the 'packaging' element in your pom.xml:
<packaging>war</packaging>
If you don't include one, the default packaging is 'jar'.

Categories

Resources