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.
Related
How to build the environment specific war file for a spring boot application using maven.I have created 3 profile configuration files placed in src/main/resource/ folder.
application.prod.properties
application.dev.properties
application.test.properties
I am able to run application by specifying required profile type in the VM argument tab with the value "-Dspring.profiles.active=dev" while executing the project as spring boot application.
Here while running as spring boot application i am able to the specify the required profile. In the same way when I need to use for MAVEN install with different profile. Is it there any way to specify profile as part of VM argument list in Run Configuration for Maven Install goal.
I have limitation as not to touch the existing java code.
I am using STS IDE, Spring boot 1.5.2.RELEASE version, Java 1.8 and oracle db.
In the same way also help me in how to configure profiles in Jenkins.
My profile configuration has two requirements.
Run the application in STS IDE as spring boot app with the VM args.
Used the below VM ARGS
-Dspring.profiles.active=dev
Blockquote
(Here I am getting below exception while starting SpringBootApp locally in Dev Environment).
APPLICATION FAILED TO START
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
Blockquote
How to do the same thing using maven install by specifying profiles dynamically to generate war file.I am unable to find the solution.
In your main application.properties file, set spring.profiles.active to #myActiveProfile# (or any name you wish)
spring.profiles.active=#myActiveProfile#
Add your application.properties file as a filtered resource so that the placeholder myActiveProfile is replaced during build phase.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
…
</build>
Add a profiles section to your pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<myActiveProfile>dev</myActiveProfile>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<myActiveProfile>prod</myActiveProfile>
</properties>
</profile>
</profiles>
Basically, you are able to specify maven profiles when executing a particular goal. E.g mvn install -P profileName. Within a profile, you can create a property which can be passed from the command line when running a goal like mvn install -DmyActiveProfile=foo
Hope this helps.
Helpful Links
How to set spring active profiles with maven profiles
https://maven.apache.org/guides/introduction/introduction-to-profiles.html
Here, first of all I would suggest to rename your properties files to application-prod.properties, application-dev.properties and application-test.properties.
Second, maven install goal is to compile and build your project.
If you also want to run your application, when you do install I suggest to use spring-boot-maven-plugin.
And you can use a maven command something like below
mvn clean install spring-boot:run
Some links below for you information
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html
I'm not well experienced in java.
I build a UI using JSP for my servlets to get input data from users. Everytime I want to see the UI and how the Servlets are performing I have to do all thses steps over and over again,
create the war file by mvn clean install
Copy war file to Webapps folder
restart apache tomcat
View the result using the url
I want to know if there is a command that i can use to rerun apache tomcat with the war file im building at once, So that i only have to refresh the webpage to see the result. Or any method that is easier than above.
I use Intellij Idea.
Thanks in advance.
IntelliJ IDEA Community Edition does not support J2EE, but you can also achieve this in the following two ways. For full support of tomcat, you can buy IntelliJ IDEA Enterpries Edition.
Use maven-compiler-plugin
1) Add this plugin to your pom.xml:
<build>
<finalName>mvn-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
</plugins>
</build>
2) Then run this command:
mvn tomcat:run
Or Install Tomcat Runner Plugin
Refer to this link for usage of this plugin.
May be this will help you to deploy the war file on server
Heroku supports deployment of Java apps based on Maven
They also give advice for app deployment if a lib is needed that is not available in a public maven repository
But:
I have two Maven projects, where one depends on the other one. When I locally mvn install the dependent artifact I can mvn package the other one and everything works fine. However, I cannot push it to heroku, because heroku can't access my local mvn repo.
What can I do? Will it be necessary to setup a private maven repo accessible to heroku on the web (e.g. artifactory) or are there any other ways to deploy such an app with a custom dependency on heroku?
Thanks.
There is an alternate deployment path for Heroku called Anvil that might help here. With this path, you would build everything locally with any private libs you need and copy all dependencies into your target directory, and then use Anvil to build and release the whole thing to your Heroku app. By default, Anvil will detect your app as Java and try to build it again, but you can override this by specifiying the null buildpack, which tells it to take your files as is because you already did the build locally. This is probably better shown with an example:
Install Anvil:
heroku plugins:install https://github.com/ddollar/heroku-anvil
Clone this example app that already has copy-dependencies configured in its pom.xml. You would need to configure this in your own app:
git clone git://github.com/heroku/template-java-jaxrs.git
Go into the dir and build the app, which will run copy-dependencies. This is critical because you need all your dependencies in your app's target dir, not in ~/.m2/repository so Heroku will be able to find them:
mvn package
Create the Heroku app:
heroku create
Use Anvil to build with the null buildpack and release to the app:
heroku build -b https://github.com/ryandotsmith/null-buildpack.git -r
Take a look how we do it with a live open source web app: pom.xml. The app is deployed to Heroku using Maven and Ant. We automatically do git clone, then copy new files into the folder, and then do git commit && git push. What's important is that we use maven-invoker-plugin in order to download artifacts inside the Heroku slug.
You need a Maven repository. If your projects are on GitHub then you can use JitPack for this. It will build your code and publish a jar.
There are instructions and docs on the website. Basically add JitPack as a repository and then add your project as a dependency.
As of August 2018 I would recommend using Heroku Maven Plugin
It allows to build application locally and then push artefact to Heroku.
It solved my issues with local maven dependencies.
Sample configuration for Spring Boot app:
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.5</version>
<configuration>
<appName>${heroku.appName}</appName>
<processTypes>
<web>java -Dserver.port=$PORT $JAVA_OPTS -jar target/${project.build.finalName}.jar</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
If you are using Heroku CLI then ${heroku.appName} will be automatically resolved.
I don't get it. I've set up my pom.xml to use the Maven exec plugin so I can execute some of the classes in my project with the correct classpath, -D defines and -javaagent. So from a shell with the classes built in ./target/classes etc.. I can run the main() methods using
mvn exec:java -Dexec:mainClass=classWithAMainMethod
All good so far.
Now I want to ship my project(a jar artifact) and I still want to be able to use the configuration I've put in the pom.xml for running the classes with the correct arguments etc.. How do I do it? Is there some way of staying
mvn -artifactJar=MyArtifact.jar exec:java -Dexec:mainClass=classWithAMainMethod
when all I have is MyArtifact.jar(Or a maven repository with MyArtifact.jar in it)??
I've tried the following:
Get the jar with the dependency:get goal and unzip it. I can't do anything with it
as the pom.xml seems to end up in META-INF/maven in the artifact jar. Is there any way of using it?
Creating a dummy pom where I want to run my project with a single dependency on my projects artifact. I can then use exec:java to run the main classes but it's dosen't uses the configuration from my projects pom.
Thanks.
The AppAssembler plugin worked out quite well for me. I replaced the exec plugin config in my project's pom with something like this in the build section:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
<extraJvmArguments>
-Djava.rmi.server.hostname=localhost
-javaagent:${spring.javaagent.jar}
</extraJvmArguments>
<programs>
<program>
<name>foo1</name>
<mainClass>net.foor.FooMain</mainClass>
</program>
...
</configuration>
</plugin>
In Eclipse I created an external tools launcher to run the resulting scripts from target/appassembler/bin
On the machine I wanted to deploy to(Assuming access to the internal Maven repository where my artifact+dependencies have been installed/deployed):
First use wget or mvn dependency:get to get a copy of my artifact jar.
Extract the pom. unzip -j artifact.jar */pom.xml*
Run mvn appassembler:assemble -DassembleDirectory=.
Move the artifact.jar into the ./lib directory
Set execute permissions on generated shell scripts in ./bin
Have you tried using something like onejar?
That sounds like what you're looking for.
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