I can make the Azure ops pipeline but my question is I have checkedin my code into repository where we should not checkin the application property file.
That means on the deployment time i should have to download the application property file from some secure place and build my spring boot app before i deploy into app engine right.
So, what i did so far is, I downloaded my application property file into azure agent at run time. I passed the property file into maven build command but it did not work out. [Note: I already searched a lot read a lot of answers and applied as well but nothing worked]
Command line I used:
mvn -f myapp-springboot-api/pom.xml
-Dspring-boot.run.jvmArguments="-Dspring.config.location=file:/home/username/application.properties"
clean package appengine:deploy
I also tried with
mvn -f myapp-springboot-api/pom.xml
--spring.config.location=file:/home/username/application.properties
clean package appengine:deploy
This also did not workout.
Also, I tried passing the whole property file location via pom.xml
pom.xml changes:
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>1.1.1.RELEASE</spring-cloud.version>
<property.file.location>${property.file.location}</property.file.location>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<files>
<file>${property.file.location}</file>
</files>
</configuration>
</plugins>
</build>
Than I tried to build with:
mvn -f myapp-springboot-api/pom.xml
-Dproperty.file.location="/home/username/application.properties" clean package appengine:deploy
Than also I was not able to load the define external property file.
Thanks in advance, please help your help is highly appreciated.
The commands you are using won't actually pass the external properties files to the application engine (As it exists on a different server) and would only be scoped to the running maven process that is packaging + deploying.
So if you have copied your property file onto the external agent before building I would just replace the default one you have checked into source control.
So your build steps would be for example:
Download property file
Overlay:
mv /home/username/application.properties myapp-springboot-api/src/main/resources/application.properties
Build + Deploy
mvn -f myapp-springboot-api/pom.xml clean package appengine:deploy
So now your compiled and deployed jar file would include your new properties file, an alternative that recently came out would be to use something like Azure App Configuration.
If you want to not have to do another command you could also use the Maven Resources Plugin to perform the copy for you.
Is it possible to run a web application using Tomcat Server in Intellij Idea Community Edition?
I tried to find some information about it but haven't achived any success.
Intellij Community does not offer Java application server integration. Your alternatives are
buying Intellij licence,
switching to Eclipse ;)
installing Smart Tomcat plugin https://plugins.jetbrains.com/plugin/9492, make following settings (image)
installing IDEA Jetty Runner plugin https://plugins.jetbrains.com/plugin/7505
running the application server from Maven, Gradle, whatever, as outlined in the other answers.
I personally installed the Jetty Runner plugin (Jetty is fine for me, I do not need Tomcat) and I am satisfied with this solution. I had to deal with IntelliJ idea - Jetty, report an exception, though.
If you are using maven, you can use this command mvn tomcat:run, but first you add in your pom.xml this structure into build tag, just like this:
<build>
<finalName>mvn-webapp-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Using Maven, try tomcat7-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextFile>src/main/webapp/WEB-INF/config/app-config.xml</contextFile>
<mode>context</mode>
<charset>UTF-8</charset>
<warDirectory>target/${project.artifactId}-${project.version}</warDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run it using tomcat7:run-war
More goals here
Tomcat (Headless) can be integrated with IntelliJ Idea - Community edition.
Step-by-step instructions are as below:
Add tomcatX-maven-plugin to pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>SampleProject</path>
</configuration>
</plugin>
</plugins>
</build>
Add new run configuration as below:
Run >> Edit Configurations >> + >> Maven
Parameters tab ...
Name :: Tomcat
Working Directory :: Project Root Directory
Command Line :: tomcat7:run
Runner tab ...
VM Options :: <user needed options>
JRE :: <project needed>
Invoke Tomcat in Run/Debug mode directly from IntelliJ Run >> Run/Debug menu
NOTE: Though this is considered a hacking of using using Tomcat integration features of IntelliJ - Enterprise version features, but I would consider this a programmatic way integrating tomcat to the IntelliJ Idea - community edition.
Yes, you can use maven plugin, or simple java program. No need for IDE plugin.
See for example Main class from https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat
Tomcat can also be integrated with IntelliJ Idea - Community Edition with Tomcat Runner Plugin.
Details below:
https://plugins.jetbrains.com/plugin/8266-tomcat-runner-plugin-for-intellij
The maven plugin and embedded Tomcat are usable work-arounds (I like second better because you can debug) but actual web server integration is a feature only available in intelij paid editions.
Yes, its possible and its fairly easy.
Near the run button, from the dropdown, choose "edit configurations..."
On the left, click the plus, then maven and rename it "Tomcat" on the right side.
for command line, enter "spring-boot:run"
Under the runner tab, for 'VM Options', enter "-XX:MaxPermSize=256m -Xms128m -Xmx512m
-Djava.awt.headless=true" NOTE: 'use project settings' should be unticked.
For environment variables enter "env=dev"
Finally, click Ok.
When you're ready to press run, if you go to "localhost:8080/< page_name > " you'll see your page.
My pom.xml file is the same as the Official spring tutorial
Serving Web Content with Spring MVC
<?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>org.springframework</groupId>
<artifactId>gs-serving-web-content</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Well the question is already answered, however what I am writing here is just my observation so other fellows in the community can save some of their time.
I tried running a spring-mvc project using the embedded tom-cat in Intellij communit edition.
First try I did was using the Gradle tom-cat plugin, however the problem that I faced there is the tomcat server just starts once, after that from the second start the build complains saying that a container is already running.
There are so many open thread on the web about this, for some it works and for most of the people (almost 90% of the web threads that I broke my head with, faced the same problem of container not getting started the second time. The resolution is not there.
After wasting a lot lot of my time, I finally decided to switch to maven tom-cat plugin and do the same spring-mvc setup with maven that I did with gradle and VOILA! it worked in the first short.
So long story short, if you are setting up spring-mvc project in intellij community edition, please consider maven tomcat plugin.
Hope this helps somebody's hours of exploration across various web forums.
Using Tomcat 9 in IntelliJ IDEA Community Edition without installing any plugin
Note: Make sure environment variables JAVA_HOME and CATALINA_HOME is set. And in case value for JAVA_HOME or CATALINA_HOME is reset recently then restart IntelliJ IDEA before proceeding further.
First open the project in IntelliJ IDEA and then click on File > Settings... > Tools > External Tools, then click on the + button.
Then we have to specify the Name for the Tomcat, then in the Program we
have to specify the path for the catalina.bat file in the bin folder in
the folder where Tomcat is installed, then in Arguments we have to write jpda run and then click on Ok and then on Apply.
After that we can we run the Tomcat by clicking on Tools > External Tools > name_you_provided_for_tomcat.
Then we have to put the necessary files of the application we want to host on the Tomcat in the webapps folder in the folder where Tomcat is installed.
You can use tomcat plugin with gradle. For more information, you here.
apply plugin: 'tomcat'
dependencies {
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.4'
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
[tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8090
[tomcatRun, tomcatRunWar, tomcatStop]*.stopKey = 'stfu'
tomcatRunWar.contextPath = "/$rootProject.name"
tomcatRunWar.ajpPort = 8000
if (checkBeforeRun.toBoolean()) {
tomcatRunWar { dependsOn += ['check'] }
}
I used Jay Lin's answer. Highly recommend it.
If you never used Maven before and don't want to go deep into it: follow Jay Lin's answer, but also do this:
right click on your project name -> Add Framework support -> Maven.
Then install maven from here http://maven.apache.org/install.html. Do what it says, run the commands.
Then install spring-boot from here https://mvnrepository.com.
Then follow the error messages if there are any - maybe you would need to install some other stuff (just google it and that mvnrepository.com would come up). To install use this command:
mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path
replace path with where you downloaded the jar file, replace version, group and artifact id with info from mvnrepository.com.
Further errors I encountered:
I had to create a class in src/main/java (with simple System.out.println command in main) and add <start-class>main.java.Hello</start-class> in <properties> tag in pom.xml. Btw, the pom.xml should appear itself when you do the first action from my answer - copy paste Jay Lin's code there.
Another error I got was connected to JAVA_HOME variable and the verion stuff. Somewhy it thought jdk is 7th version and I was telling it was 8th. So I changed the java version tag in <properties> to this <java.version>1.7</java.version>.
Now it works fine! Good luck everyone.
If you use Gradle, you can try my script: https://github.com/Adrninistrator/IDEA-IC-Tomcat .This script will build files for web application, create a Tomcat instance, start Tomcat and load the web application.
I think maven is not installed properly. check with mvn --v
or
Please check maven home path in env variables
or you have created this project before the installation of maven
I am using intellij CE to create the WAR, and deploying the war externally using tomcat deployment manager. This works for testing the application however I still couldnt find the way to debug it.
open cmd and current dir to tomcat/bin.
you can start and stop the server using the batch files start.bat and shutdown.bat.
Now build your app using mvn goal in intellij.
Open localhost:8080/ **Your port number may differ.
Use this tomcat application to deploy the application, If you get the authentication error, you would need to set the credentials under conf/tomcat-users.xml.
For Intellij 14.0.0 the Application server option is available under
View > Tools window > Application Server (But if it is enable, i mean if you have any plugin installed)
VM :-Djava.endorsed.dirs="C:/Program Files/Apache Software Foundation/Tomcat 8.0/common/endorsed"
-Dcatalina.base="C:/Program Files/Apache Software Foundation/Tomcat 8.0"
-Dcatalina.home="C:/Program Files/Apache Software Foundation/Tomcat 8.0"
-Djava.io.tmpdir="C:/Program Files/Apache Software Foundation/Tomcat 8.0/temp"
-Xmx1024M
This is my first time using maven on a project. Basically, I am working in the src on a webapp and when I am ready to push a change to the target i do a mvn clean install (this was what I was told to do).
The issue is that if I am just making a minor html tweak in a jsp and want to see the results I have to wait for tests, compile copy the war over deploy, server restart and then I have to log in again.
There's got to be a better way to do this. It's making my development speed slow to a crawl.
You can use maven tomcat plugin to run an in-memory tomcat over your maven project. Any jsp or static resource changes will apply immediately. Java code changes still require you to manually stop and start the server.
To do so use following maven goal
mvn clean tomcat:run
One other choice is jetty plugin. add jetty plugin to pom.xml,and run,that's ok.
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.11.v20130520</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<contextPath>/</contextPath>
</configuration>
</plugin>
</plugins>
</build>
run your application:
mvn jetty:run
I have a couple of questions.
I'm trying to learn how to make web apps with Java (I'm coming from C#). The project which I'm going to work on is using Spring MVC.
Now all the tutorials of Spring MVC / Java want me to use Maven. I'm also using Eclipse.
My problem is that every time I try to run a project downloaded from some tutorial like these:
http://tech-read.com/2011/10/31/spring-3-mvc-annotations/
http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/
I can't run the project. it tells me that the project has no main and then tries to find a class, nothing very clear...
I've also watched youtube videos about it, and some guy was using Jetty to launch the website. (video link : http://www.youtube.com/watch?v=uv9tXFrTLtI)
So my question is:
If I have Eclipse, Oracle JDK 1.7, Spring Tool Suite 3, Maven + m2e - Maven Integration for Eclipse, Spring IDE blah blah plugin, should I be able to run a website from a simple Hello World project? If so, Is there something specific I have to tell Maven / Eclipse to launch my things?
You need to run it in a server context.
To do this you need to install a java web server, like svz said. Tomcat is the one I use.
Spring Source Toolkit (STS) comes with this set up out of the box.
Spring is confusing enough to learn, I would suggest using this IDE until you get the hang of it, then you can experiment with better (different?) web servers.
Try right clicking on your project and running it on a server.
It should be set up to do it for you out of the box.
You can also install it as a plugin to eclipse, or install tomcat manually and drop your war files into the app directory.
You could use jetty. Add the jetty plugin in your pom like this :
<build>
<finalName>spring-mvc-webapp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.0.1</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
Execute mvn jetty:run
Connect to URL : http://localhost:8080/spring-mvc-webapp/
I'm looking for help coming up with the steps required to get a basic "hello world" web app up and running on a Mac using IntelliJ and GlassFish. So far I've found this guide, which is helpful but outdated (some dialogs/steps have changed since it was written).
Can anyone well-versed in these tools help me sort out the steps required to get a basic web app deployed to GlassFish 3.0.1 using IntelliJ 9.0.4?
First, get Glassfish running on its own. This experience will serve you well, since the process is pretty much the same on all Unix systems. If you only learn to interact with Glassfish through your IDE, then you'll be totally lost without the IDE.
There are two ways to deploy an app: through the admin web interface (user-friendly, but painfully slow), or through the command line. Here's how you do the latter: first, make sure that the asadmin utility that came with Glassfish is on your path, then do something like this:
asadmin --user admin deploy --name hello ~/projects/hello/build/hello.ear
By default, the admin user has an empty password; if it doesn't, you'll be prompted for it.
I don't know about Glassfish, but I can tell you how to do it with Tomcat. The only difference should be the app server that you start inside IntelliJ:
Under project settings, create a web module - that'll give you your /WEB-INF and web.xml
Under project settings, create an artifact that maps to your exploded WAR file. Make sure that the JARs you need are added to the WEB-INF/lib; your .class files are copied to WEB-INF/classes; all necessary resources are put where you want them.
Set up Glassfish and tell it to deploy your exploded WAR artifact. Give it the name of your web app as context root (e.g., "/foo").
Run the web app. IntelliJ will compile your code, create the exploded WAR artifact in the /out directory, and deploy to your app server.
You should see the app start under the URL http://localhost:4848/foo/index.html, assuming you have an index.html welcome file in your web.xml
JNDI set up is another matter.
IMO the best way to have an EAR/WAR deployed on any application server is to use Maven to build an EAR and Cargo Maven plugin for redeploying. The reason why I would use it is that it's totally IDE-independent and can use it both in development and my continuous integration server.
pom.xml fragment of EAR/WAR module for Glassfish:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<container>
<containerId>glassfish2x</containerId> <!-- or glassfish3x -->
<type>installed</type>
<home>${glassfish.home}</home>
</container>
<configuration>
<properties>
<cargo.remote.password>${glassfish.password}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>installed</type>
<deployables>
<deployable>
<location>${project.build.directory}/${project.build.finalName}.${project.packaging}</location>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
Redeploy command:
mvn cargo:redeploy -Dglassfish.home=/path/to/glassfish/-Dglassfish.password=adminadmin -DskipTests=true -o
You should learn about Maven 2 if you don't know what it is.
I had success with this tutorial: Developing applications for GlassFish Server in IntelliJ IDEA 10. I'm using IDEA 11 and GlassFish 3.1.2