Maven WebApp tomcat7 system properties - java

We are using a maven dependency to add embedded tomcat on our webapplication. It works fine, but I need to add systemProperties to embedded tomcat, so that our webapp can use this systemProperties.
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<path>/html5</path>
<enableNaming>true</enableNaming>
<finalName>html5.jar</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I tried to add system properties like this, but it didn't work. I added it
<build>
<plugins>
<plugin>
<configuration>
<systemProperties>
<dashboard.oracle.host>1.1.1.1</dashboard.oracle.host>
<dashboard.oracle.port>1521</dashboard.oracle.port>
<dashboard.oracle.sid>orcl</dashboard.oracle.sid>
<dashboard.oracle.url>
jdbc:oracle:thin:#${dashboard.oracle.host}:${dashboard.oracle.port}:${dashboard.oracle.sid}
</dashboard.oracle.url>
<dashboard.oracle.username>username</dashboard.oracle.username>
<dashboard.oracle.password>password</dashboard.oracle.password>
</systemProperties>
</configuration>
...
</plugin>
</plugins>
</build>

In general the way you have added the system properties to the tomcat plugin is correct:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<example.value.1>alpha</example.value.1>
<example.value.2>beta</example.value.2>
</systemProperties>
</configuration>
</plugin>
Taken from the Apache Docu.

the system properties in the Maven Plugin are only for when running the tomcat7:run mojo ... in order to pass in the system properties to the executable war (jar), you must do it on the command line:
java -DsysProp1=value -DsysProp2=value -jar exec-war.jar

Related

Jar is not creating for spring boot

I am adding pluginManagement to avoid
Failed to execute goal org.apache.openjpa:openjpa-maven-plugin:3.0.0:enhance (enhancer) on project Execution enhancer of goal org.apache.openjpa:openjpa-maven-plugin:3.0.0:enhance failed:
Error. but when I add pluginManagement it stops creating jar for my project.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.test.testApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<includes>**/tablemodels/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
<persistenceXmlFile>src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
If I remove pluginManagement from pom then Jar is getting created.
My guess is that you just wrapped your <plugins> tag in a <pluginManagement> tag, which does not do what you want. I suggest you read the documentation to understand the relationship between plugin and pluginManagement. See also another post on StackOverflow.
As to your underlying problem: I guess the error you mention is an Eclipse error. It is emitted by the m2e plugin which requires a connector for each maven plugin in your pom.
You can usually come up with a connector (if it is not found on the Eclipse Marketplace) by typing " m2e connector" into your favorite search engine.
In this case you might want to install this: https://github.com/beskow/openjpa-maven-connector

Exclude webapp folder from Maven Build

I was trying to achieve a custom directory structure for my war with maven build.
Below is my build command used in pom.xml.
<build>
<finalName>abc</finalName>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<configuration>
<tasks>
<mkdir dir="bin" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>bin</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>bin</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
Please find below the current directory structure of war file after unzip the war. Maven is including complete webapp directory under WEB-INF/Classes , But i want only java class files(ndaws directory). I have tried a lot of excluding techniques, But nothing works.
Got the solution, My changes in pom is not reflecting, war is being created from build folder under target.
Thanks
remove resource directory from maven-resources-plugin
and add warSourceDirectory to maven-war-plugin
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
or if using intelij and webapp folder marked 'resoures', select the folder.
open context menu.
Mark Directory as > Unmark as Resources Root
I tryed alot of solutions. In the end I found one that solve my problem... It's a similiar case, but I need to exclude a folder inside the webapp.
I opened my war file using 7zip... The folder that I want to exclude were in the main page.
I used this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<packagingExcludes>myfolder/**</packagingExcludes>
</configuration>
</plugin>
Just change "myfolder" with the folder that you want to exclude.
If that is more than one folder, multiply this line.

How to deploy war to Tomcat from child pom using maven tomcat plugin?

I have a maven project with the following plugin in the pom
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/casemanager</path>
<update>true</update>
</configuration>
</plugin>
When I do a mvn tomcat7:run, my war is deployed just fine. But I have the following configuration in one of the modules of my maven project
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>
true
</fork>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
I want tomcat to run in the pre-integration-test phase. Now when I do a mvn verify, it starts the server but does not deploy my war. I have even tried providing the warSourceDirectory. Am I missing something here?
I figured it out. Seems like when I execute a goal in a child pom, tomcat does not search for wars in other modules on the same level. I had to use webapp
<webapps>
<webapp>
<groupId>com.fico.fos.casemanager</groupId>
<artifactId>casemanager.ui</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
</webapps>
I had to use this within the configuration tags

Deploy Java app to Heroku using Git

My project written using the Spark framework has this build config.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.7</compilerVersion>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.avaje</groupId>
<artifactId>ebean-maven-enhancement-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>main</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<configuration>
<classSource>target/classes</classSource>
<packages>somepath.domain.**</packages>
<transformArgs>debug=1</transformArgs>
</configuration>
</plugin>
</plugins>
</build>
Its main class resides in somepath.Bootstrap.
The Procfile sits next to the pom.
What should the contents of the Procfile be?
(I am deploying via git.)
Procfile contains command, that will be executed after deploying your appliaction (git push heroku master for you example i guess).
I do not very familiar with spark, but i guess it can be something like this:
web: mvn exec:java -Dexec.mainClass="somepath.Bootstrap"
A Procfile is a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform.
Here is an example for a Java app:
web: java -cp target/classes:target/dependency/* Main
This is taken from a Heroku Java sample app that uses Spark.
Be aware that build tools, such as Maven, will not be available at runtime.

Android project build with native libraries inside using maven

I have an Android project with Maven that uses internal libraries. When I run a maven install the so library is not inside the jar file generated and in consequence is not inside the apk generated. I'm using Eclipse with maven and android maven plugin v.3.7.0.
My pom.xml is:
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>../bin/${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
<sdk>
<path>${env.ANDROID_HOME}</path>
<platform>15</platform>
</sdk>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
It seems that nativeLibrariesDirectory tag doesn't works for me.
Any idea to fix this problem?
Thanks
Here is how to include native libraries in your apk:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<manifest>
<debuggable>true</debuggable>
</manifest>
<!-- Where the native files are located; in the future we should use src/main/libs -->
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
</configuration>
<executions>
<execution>
<id>manifestUpdate</id>
<phase>process-resources</phase>
<goals>
<goal>manifest-update</goal>
</goals>
</execution>
<execution>
<id>alignApk</id>
<phase>package</phase>
<goals>
<goal>zipalign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The Android for Maven Eclipse project doesn't yet support native libraries. If you'd like to see this supported please send a pull request.

Categories