I wanted to Deploy a simple Spring MVC APP to open shift I googled for this and found spring-mvc-3-on-jboss but there project structure is different I have basic Spring MVC project structure is
that is at this repo, at openshift.com I created Application and configured as :
But I can not see my home.jsp file as welcome file when I goto my app-url I see only the default/traditional welcome page. Any suggestion how to configure project to work correctly?
There is one major problem with your pom.xml, I think that makes your app not working on the openshift.com. You should add the following lines to your pom.xml
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'webapps'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<finalName>yourAppName</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I haven't tested this code with JBoss Application Server, so change your server to Apache Tomcat 7. that worked for me correctly.
first you have clone your git repository then automatically created folder in document folder.
then your war file extract and past your clone directory into webapps folder
and create test folder paste your code in folder and also root war file.
then your ulr in your folder name write and enter.
for example
like this.
git clone ssh://5565c850e0b8cd07580001ba#yourdomain.rhcloud.com
paste your extract war file into your clone directory.
then fire git commmand
$ git add .
$ git commit -m "A checkin to my application"
$ git push
Related
I need to create WAR file based on specific environment properties file.
So I have created 2 properties files,
application.DEV.properties
application.PROD.properties
Now when I run the project using eclipse embedded tomcat, I pass on the -Dspring.profiles.active=DEV as VM argument. Then when I hit my endpoint, I can see the DEV related messages returned. Same is the case when I pass PROD as parameter.
Now, what I want to do is I want to create a WAR file with maven command and pass the parameter in such a way that my specific properties file gets loaded. So I have referred google as well as stackoverflow and found various options like below,
mvn clean install -Drun.profiles=DEV
mvn clean install -Drun.jvmArguments="-Dspring.profiles.active=DEV"
mvn clean install -Dspring.profiles.active="DEV"
mvn clean install -Dspring.profiles.active=DEV
I tried all above. When I hit the command, the WAR gets generated. but it doesn't get deployed on tomcat, because it cant read the properties file and gives error. It seems like the profile specific properties file does not get loaded in the WAR.
I want to know what is the alternative to -Dspring.profiles.active=DEV when I want to generate a WAR file using maven?
How to generate WAR to correctly include proper profile specific properties file?
I am using spring boot 1.5.14.RELEASE.
As commented on this answer by Mickael, you can get help from the maven documentation on how to use profiles : https://maven.apache.org/guides/introduction/introduction-to-profiles.html
The usual way to choose a profile with maven is
mvn -Pprod package
Where prod is the name of your profile. If you want to build with the dev profile, it would be
mvn -Pdev package
Such profiles are defined in your file pom.xml under project>profiles>profile. And at that place, you can specify packaging options.
Here is such a profile:
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- log configuration -->
<logback.loglevel>DEBUG</logback.loglevel>
<!-- default Spring profiles -->
<spring.profiles.active>dev${profile.no-liquibase}</spring.profiles.active>
</properties>
</profile>
You have to pass spring.profiles.active to the runtime, not to the "build runtime". The only spring profiles, which are desirable at build time, would be for testing purposes.
In case of "war on Tomcat", you can set spring.profiles.active:
(Globally) Create a file in <tomcat_home>/bin/ named setnev.sh (respectively .bat, when you are on a Windows machine) with:
export JAVA_OPTS="-Dspring.profiles.active=PROFILE_OF_THIS_TOMCAT"
respectively:
set JAVA_OPTS="-Dspring.profiles.active=PROFILE_OF_THIS_TOMCAT"
(Globally) Add a line to <tomcat_home>/conf/catalina.properties:
spring.profiles.active=PROFILE_OF_THIS_TOMCAT
(At Container level) Add a file named context.xml at $CATALINA_BASE/conf/[enginename]/[hostname]/ (, you could also put it into /<webapp_root>/META-INF/, but then you'd have to distinguish at build time) with the following content:
<Context>
<Environment name="spring.profiles.active" value="PROFILE_OF_THIS_TOMCAT" />
</Context>
I am wondering if there is a way to dynamically deploy a maven project on eclipse and have the same result as if it was packaged in a WAR.
I noticed that when I right-click the project and choose "run as" and then choose tomcat the project deployed does not work properly but when I generate the war and place it manually it works fine.
That means everytime I change something in the code I have to generate a war and deploy it manually on the server.
Is there a tomcat config that I can use to have an output when I run from eclipse similar to when i generate a war?
I'm using tomcat 6.0.26 and eclipse Neon 3.
Thanks.
Yes, you can ...
In general the steps are:
1) Turn your existing project into a maven project by adding a pom.xml like this into the project root folder:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>yourApp</artifactId>
<packaging>war</packaging>
<version>2.3</version>
<name>Your Web Application</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Add your dependencies as needed. -->
</dependencies>
</project>
2) Rightclick the project and Configure -> Convert to Maven Project
3) In Eclipse Servers view add an Apache Tomcat.
4) Rightclick the Tomcat server and Add and Remove ... -> Add your project.
5) Launch the Tomcat in debug mode.
Now eclipse will deploy the project in exploded .WAR format, replacing and therefore hot deploying resources on every change and compiling Java classes on change.
If you do not alter Java method or class signature, changes in Java source code and resources take effect instantly without the requirement to restart Tomcat or the web application.
The problem was that I didn't configure the maven profiles when I ran the project from eclipse which explains why I had different outputs when deploying the project from a war and directly from eclipse. The answer here Maven Profiles and Tomcat in Eclipse explains how to configure maven profiles when you run on server from eclipse.
I have a question regarding maven and its tomcat7 plugin :)
I have the following maven projects:
plugin1: plain java project packaged as jar
plugin2: plain java project packaged as jar
webapp: standalone webapp project packaged as jar
those three project are properly build in maven and the outcome works fine:
I can use the jars from plugin1/plugin2
I can deploy the webapp war file to a web container
I can run tomcat7:run to start the webapp
Now, I need to provide different packaging of the webapp containing specific plugin setup.
i.e. I want to generate a war file with webapp + plugin1 and another one with webapp + pugin2
To achieve this, I have created 2 additionnal maven projects that declare dependancies on the webapp project + the appropriate plugin projects and are packaged as wars.
The generated war files have the expected content, and can be deployed to a tomcat, but when I try to use the maven tomcat plugin (tomcat7:run again), it simply doesnt start anything.
Though this is not blocking for me (my main point was to generate the war files), I have the feeling that I missed something.
the pom.xml for those aggregate projects looks like this (note that there is absolutly no code in those projects, these were just created for packaging with specific dependancies convenience).
<groupId>my.project</groupId>
<artifactId>live1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>MyWebapp</name>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>my.project</groupId>
<artifactId>plugin1</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>MyWebapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>localhost</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
Thanks !
note: long time lurker, first time asker here, if some information is missing tell me :)
Depending on the structure of your project it may not be suficient to just add a dependency of type war. You may need also to configure <overlays> as described here maven-war-plugin.
It looks like your final war does not provide the full web configuration that you expect. With overlays you can configure how the resources from the dependency will be packed into your final web app.
There must be some difference in the way that your external tomcat starts the app compared to the tomcat7 plugin. May be you can try -X option :
mvn -X tomcat7:run
This should log out some details, of what the embedded tomcat is configuring..
I am new to maven. So I have a project with pom.xml file. So I ran that with maven and the build was successful. I have glassfish. Glassfish is already running separately. So now what is the next step to run the project with Glassfish? My IDE is eclipse.
You have to first tell Maven to build the WAR, check out this plugin for that: http://maven.apache.org/plugins/maven-war-plugin/.
Then you need to tell maven how to deploy to glassfish, you can either configure a Maven execution plugin to do this (see here: https://www.mojohaus.org/exec-maven-plugin/). Or you can look around for a custom plugin devoted to integrating maven with glassfish. This one looks promising, but I have not used it: http://maven-glassfish-plugin.java.net/.
Maven provides a lot of basic functionality out of the box, but most of the cooler stuff with build automation is done through plugins.
Update
Just updating to add a very simple Pom that will do a auto-deployment. Note: if you just run a "mvn clean install", with the packaging set to 'war', maven will build the .war file for you and place it in the target/ folder. You can take this and deploy it to glassfish manually if you just want to get started.
Below is part of a very simple pom that uses the Maven execution plugin to auto-deploy to glassfish as a function of the build:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<executable>${path-to-asadmin-util}</executable>
<arguments>
<argument>deploy</argument>
<argument>--user=${username}]</argument>
<argument>--passwordfile=${password-file}</argument>
<argument>--host=localhost</argument>
<argument>--port=4848</argument>
<argument>target/${project.name}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
This basically just calls the deploy command on the glassfish asadmin utility[1]. You need to fill in the following variables:
${path-to-asadmin-util} --> this is the path to your asadmin utility
(normally in the glassfish_home/bin)
${username} --> glassfish admin username
${password-file} --> password file for logging into glassfish
admin[2]
${project.name} --> name of your war
If you want to get more complicated I suggest taking a look at this thread: GlassFish v3 and glassfish-maven-plugin (Mac).
[1] - http://docs.oracle.com/cd/E18930_01/html/821-2433/deploy-1.html#SJSASEEREFMANdeploy-1
[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn
Additonnaly, you should have a glance at this StackOverflow thread, dealing with maven deployement in glassifsh : https://stackoverflow.com/a/1836691/1047365.
For further understanding of Maven, you should REALLY read this (free) book : http://www.sonatype.com/books/mvnref-book/reference/. This is THE reference for Maven.
We can explain you what Maven is doing, producing, etc ... but Sonatype made a great work and you'll probably learn more reading it than we could ever do !
Regards.
I found this tutorial useful: http://tshikatshikaaa.blogspot.com/2012/05/introduction-to-maven-concepts-crash.html
I have a multi module web app building with maven. We build the war as per normal and deploy and run on developer machines and local test servers using tomcat.
Then we want to deploy the application to the cloud. To do this we create a special version of tomcat which has all the libraries preloaded and a special version of the war which only has our code. Point here is tomcat is preloaded on the cloud server, the war is uploaded each time it is changed. Currently we are having to manually remove the dependencies from the built war.
What is the best way for maven to do this? Should I build a custom packaging type or maybe run some post build plugin to remove these wars? Or something else? I think the best way to activate this custom build is via a profile. I did try and remove these dependencies by setting them to scope = provided in the new profile but the transitive dependencies still made it into the war.
If you want to exclude all dependencies, you can use the war plugin's packagingExcludes to do so:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
...
</configuration>
</plugin>
Specify this plugin inside a profile to only perform it for production.
You can achieve using profile in maven. As you said it is not working, I can think of you configure something wrong. Try something like:
<profiles>
<profile>
<id>dev</id>
<activation>
<!-- active by default, turn off when on prod -->
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<!-- include this in dev, not in prod -->
<dependency>
<groupId>com.company</groupId>
<artifactId>xyz</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
Then in command line, mvn package -P !dev to deactivate dev profile so that not include the jars.
Make sure com.company:xzy is not included in <project><dependencies></dependencies></project>.