Building SOA composite application using maven - maven

Using SOA suite 11, trying building source code (composite.xml with configuration file) in SOA composite application into a jar file using maven.
Can anyone help to guide me making POM.xml for the same. i am using "Apache-ANT-Plugin" in my pom file.

http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
This POM relates to this SOA Composite, i.e. the one in this same directory.
There is another POM in the SOA Application directory which handles
the whole SOA Application, which may contain additional projects.
-->
4.0.0
test1
HelloWrold
1.0-SNAPSHOT
sar
<!--
The parent points to the common SOA parent POM. That is a special POM that is
shipped by Oracle as a point of customization (only). You can add default values
for properties like serverUrl, etc. to the SOA common parent POM, so that you
do not have to specify them over and over in every project POM.
-->
<parent>
<groupId>com.oracle.soa</groupId>
<artifactId>sar-common</artifactId>
<version>12.1.3-0-0</version>
</parent>
<properties>
<!-- These parameters are used by the compile goal -->
<scac.input.dir>${project.basedir}\SOA/</scac.input.dir>
<scac.output.dir>${project.basedir}/target</scac.output.dir>
<scac.input>${scac.input.dir}/composite.xml</scac.input>
<scac.output>${scac.output.dir}/out.xml</scac.output>
<scac.error>${scac.output.dir}/error.txt</scac.error>
<scac.displayLevel>1</scac.displayLevel>
<!-- if you are using a config plan, uncomment the following line and update to point
to your config plan -->
<!--<configplan>${scac.input.dir}/configplan.xml</configplan>-->
<!-- These parameters are used by the deploy and undeploy goals -->
<composite.name>${project.artifactId}</composite.name>
<composite.revision>1.0</composite.revision>
<composite.partition>default</composite.partition>
<serverUrl>${oracleServerUrl}</serverUrl>
<user>${oracleUsername}</user>
<password>${oraclePassword}</password>
<overwrite>true</overwrite>
<forceDefault>true</forceDefault>
<regenerateRulebase>false</regenerateRulebase>
<keepInstancesOnRedeploy>false</keepInstancesOnRedeploy>
<!-- These parameters are used by the test goal
if you are using the sca-test (test) goal, you need to uncomment the following
line and point it to your jndi.properties file. -->
<!--<jndi.properties.input>UNDEFINED</jndi.properties.input>-->
<scatest.result>${scac.output.dir}/testResult</scatest.result>
<!-- input is the name of the composite to run test suties against -->
<input>${project.artifactId}</input>
<!--<scac.ant.buildfile>${env.MW_HOME}/soa/bin/ant-sca-compile.xml</scac.ant.buildfile>
<sca.ant.testfile>${env.MW_HOME}/soa/bin/ant-sca-test.xml</sca.ant.testfile>
-->
</properties>
<build>
<plugins>
<plugin>
<groupId>com.oracle.soa.plugin</groupId>
<artifactId>oracle-soa-plugin</artifactId>
<version>12.1.3-0-0</version>
<configuration>
<compositeName>${project.artifactId}</compositeName>
<composite>${scac.input}</composite>
<sarLocation>${scac.output.dir}/sca_${project.artifactId}_rev${composite.revision}.jar</sarLocation>
<serverUrl>${serverUrl}</serverUrl>
<user>${user}</user>
<password>${password}</password>
<!-- Note: compositeRevision is needed to package, revision is needed to undeploy -->
<compositeRevision>${composite.revision}</compositeRevision>
<revision>${composite.revision}</revision>
<scacInputDir>${scac.input.dir}</scacInputDir>
<input>${input}</input>
</configuration>
<!-- extensions=true is needed to use the custom sar packaging type -->
<extensions>true</extensions>
</plugin>
</plugins>
</build>

Related

Fabric8 Docker Maven Plugin: docker:tag fails with Cannot invoke "BuildImageConfiguration.cleanupMode()" because "buildConfig" is null

I use FabricIO's Docker Maven Plugin.
I'm trying to create a docker tagged image with Docker Maven Pugin.
The build goal works, but when trying to tag the image, DMP fails:
Execution start of goal io.fabric8:docker-maven-plugin:0.40.2:tag failed: Cannot invoke "io.fabric8.maven.docker.config.BuildImageConfiguration.cleanupMode()" because "buildConfig" is null
docker-maven-plugin version : 0.40.2 (latest 2022-09)
Maven version (mvn -v) :
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Java version: 18.0.2-ea, vendor: Private Build, runtime: /usr/lib/jvm/java-18-openjdk-amd64
Ubuntu 22.04
I've also opened a bug here since it does not behave according to the documentation:e
https://github.com/fabric8io/docker-maven-plugin/issues/1610
But maybe - Is there something could be doing wrong?
Here is the plugin part of my pom.xml.
Note that I put the docker:tag goal in place of docker:start so that it runs after docker:build if that being missing was the cause.
<plugin>
<!-- The Docker Maven plugin is used to create docker image with the fat jar -->
<groupId>io.fabric8</groupId><artifactId>docker-maven-plugin</artifactId><version>${version.docker-maven-plugin}</version>
<configuration>
<images>
<image>
<alias>mongo</alias>
<name>mongo:5</name>
<run>
<wait><time>6000</time><log>Waiting for connections</log></wait>
<log><prefix>MO</prefix><color>yellow</color></log>
<!-- Assign dynamically mapped ports to maven variable (which can be reused in integration tests) -->
<ports><port>mongo.port:27017</port></ports>
<env>
<MONGO_INITDB_ROOT_USERNAME>root</MONGO_INITDB_ROOT_USERNAME>
<MONGO_INITDB_ROOT_PASSWORD>kotlin4ever</MONGO_INITDB_ROOT_PASSWORD>
</env>
</run>
</image>
<!-- Image holding the artifact of this build -->
<image>
<alias>service</alias><!-- Alias name which can used for linking containers during runtime -->
<name>dacadoo/${project.artifactId}:${project.version}</name>
<build>
<from>openjdk:20</from>
<assembly>
<descriptor>${basedir}/src/main/docker/docker-assembly.xml</descriptor>
<!--
<descriptorRef>artifact-with-dependencies</descriptorRef>
-->
</assembly>
<ports><port>8080</port></ports>
<!--
<cmd>java -jar /maven/tracker-service.jar</cmd>
-->
<entryPoint><exec><arg>java</arg><arg>-jar</arg><arg>/tracker-service.jar</arg></exec></entryPoint>
</build>
<!-- Runtime configuration for starting/stopping/linking containers -->
<run>
<!-- Assign dynamically mapped ports to maven variables (which can be reused in integration tests) -->
<ports><port>service.port:8080</port></ports>
<wait>
<time>10000</time><url>http://${docker.host.address}:${service.port}/health</url>
</wait>
<links><link>mongo:mongo</link></links>
<log><prefix>TS</prefix><color>cyan</color></log>
</run>
</image>
</images>
</configuration>
<!-- Hooking into the lifecycle -->
<executions>
<execution><id>start</id><goals><goal>build</goal><goal>tag</goal></goals><phase>pre-integration-test</phase></execution>
<!--
<execution><id>stop</id><goals><goal>stop</goal></goals><phase>post-integration-test</phase></execution>
-->
</executions>
</plugin>

display application version in title using thymeleaf and springboot

I want to display in my htm page the version of my webapp, using something like this (thymeleaf inside) :
<h4 th:text="${version}">Version</h4>
The data is well set in the pom.xml :
<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>fr.test.navig</groupId>
<artifactId>navigo</artifactId>
<version>2.0.3-SNAPSHOT</version>
...
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Application</mainClass>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
and I can see it in the MANIFEST.MF (which is in the generated jar under META-INF) :
Implementation-Version: 2.0.3-SNAPSHOT
I've tried to get the appplication version in the controller and set it in a ModuleAttribute :
#ModelAttribute("version")
public String getVersion() {
logger.info("ModelAttribute to get application version");
return getClass().getPackage().getImplementationVersion();
}
But getClass().getPackage().getImplementationVersion() value is null. Indeed the package implementationVersion is not the implementation Version of the application by default.
I know I'm late but Patrick's answer and Spring docs greatly helps in this matter.
1. If your pom.xml use spring-boot-starter-parent as parent, you can use #project.version# to get version (and any other Maven properties) in your application.properties file. According to Spring docs:
You can automatically expand properties from the Maven project using
resource filtering. If you use the spring-boot-starter-parent you
can
then refer to your Maven ‘project properties’ via #..# placeholders
Maven pom.xml:
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Foo</name>
<description>Bar</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
Spring application.properties:
foo.app.version=#project.version#
2. Then a class annotated with #ControllerAdvice can be used to inject version as model attribute.
#ControllerAdvice
public class ControllerAdvice {
#Value("${foo.app.version}")
private String applicationVersion;
#ModelAttribute("applicationVersion")
public String getApplicationVersion() {
return applicationVersion;
}
}
3. Finally this model attribute can be accessed by Thymeleaf as any other.
<th:block th:text="${applicationVersion}"></th:block>
Hope this helps!
Here is the simplest way I've found :
In my controller :
#ModelAttribute("version")
public String getVersion() throws IOException {
logger.info("ModelAttribute to get application version");
Manifest manif = new Manifest(
Application.class.getResourceAsStream("/META-INF/MANIFEST.MF"));
String version = (String) manif.getMainAttributes().get(
Attributes.Name.IMPLEMENTATION_VERSION);
return version;
}
In my htm page :
<h4 th:text="${version}">Version</h4>
You need to configure resource plugin to activate filtering on the file that need to be enriched with properties coming from your POM file.
In the generated war, the version (in fact ${project.version}) will be hardcoded to your POM version.

Maven: include resource file based on profile

I'm converting an Ant webapp project over to Maven. I have most of it working, but I'm stuck trying to figure out how to copy some resource files from different sources based on the profile.
I have src/main/resources/persistence-{dev, prod}.xml. One of these needs to be included in the war file as WEB-INF/classes/META-INF/persistence.xml.
I would like the dev version to be copied when the dev profile is active, and the prod version when prod is active.
Just use the maven resources plugin like so http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html and have a property for the file name or extension set in a profile.
If you are not wedded to the paradigm of having 3 separate persistence.xml files and copying one or the other selectively, you can use maven profiles with filtering like this (just implemented this the other day and today came across your post):
In persistence.xml:
<property name="hibernate.show_sql" value="${hibernate.debug}" />
<property name="hibernate.format_sql" value="${hibernate.debug}" />
In pom.xml create a profile and define the variable:
<profiles>
<profile>
<id>hib-debug</id>
<properties>
<hibernate.debug>true</hibernate.debug>
</properties>
</profile>
</profiles>
define a default for when you build without specifying a profile:
<properties>
<hibernate.debug>false</hibernate.debug>
</properties>
and.... make sure you turn on resource filtering:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Then you build with mvn -Phib-debug and voila! Substitution is done.

Jetty Maven Plugin is ignoring custom webdefault.xml

I'm trying to get around the common issue of Jetty locking static files on Windows with the technique of setting useFileMappedBuffer to false in webdefault.xml. Unfortunately, every time Jetty is not picking up my customized webdefault.xml.
I'm using Apache Maven 3.0.2. I've tried using the maven-jetty-plugin (v6.1.26) and jetty-maven-plugin (v8.0.0.M2) but with no difference. I've tried running clean and rebuilding as well before running Jetty.
I've verified each time that my webdefault.xml was taken from the same version as the plugin and has the correct settings, namely, only changing this setting from true to false:
...
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
...
And here's what my pom.xml Jetty plugin section looks like:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/</contextPath>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
</configuration>
</plugin>
I've also tried altering the path to my file:
<webDefaultXml>${basedir}/src/main/resources/webdefault.xml</webDefaultXml>
Everywhere I've seen this exact solution and it sounds like it is working for others (although I found one instance where someone had my issue). The startup for jetty has this in the output:
> mvn jetty:run
...
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
...
This further makes me think it isn't being applied. All the other paths are correct in the output.
My most direct issue that I'm seeing while Jetty is running is that whenever I edit a static file (JavaScript, CSS, etc.) with IntelliJ IDEA 10, I get this error message:
Cannot save file:
D:\...\... (The requested operation cannot be performed on a file with a user-mapped section open)
After I stop Jetty then it saves just fine. This happens every time.
Any ideas what I could be doing wrong? Thanks in advance.
I found an entirely different doc for the newer Jetty plugin jetty-maven-plugin (v8.0.0.M2) and it looks like the configuration name has changed:
http://wiki.eclipse.org/Jetty/Reference/webdefault.xml#Using_the_Jetty_Maven_Plugin
<project>
...
<plugins>
<plugin>
...
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<webAppConfig>
...
<defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
</webAppConfig>
</configuration>
</plugin>
...
</plugins>
...
</project>
This now seems to work for the newer plugin. I'm still unsure why the v6 plugin does not pick up the customized config.
The only solution I found that worked with maven-jetty-plugin 6.1.24 was this:
http://false.ekta.is/2010/12/jettyrun-maven-plugin-file-locking-on-windows-a-better-way/
The Jetty documentation outlines three ways to do it (as of Jetty 9):
https://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html
I successfully used the init-param method in Maven:
<!-- Running an embedded server for testing/development -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.9.v20180320</version>
<configuration>
<webApp>
<_initParams>
<org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
</_initParams>
</webApp>
</configuration>
</plugin>

How to access the internal sun.security class from an OSGI bundle?

What options do I need to add to the maven build or the java runtime to access the internal sun.security classes? There is Java code from Akamai in an OSGI bundle needs access to internal sun.security classes. The Apache Felix console gives errors for the OSGI bundle:
sun.awt.image.codec -- Cannot be resolved
sun.io -- Cannot be resolved
sun.misc -- Cannot be resolved
sun.rmi.rmic -- Cannot be resolved
sun.security.action -- Cannot be resolved
sun.security.ec -- Cannot be resolved
sun.security.internal.interfaces -- Cannot be resolved
...
I looked at this article about using internal sun classes but it only refers to javac. My maven build starts like:
<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>
<artifactId>cdncache</artifactId>
<packaging>bundle</packaging>
<name>NCDN Cache</name>
<description>Classes and interfaces to expire resource from the Akamai CDN cache [build:${build.number}]\
</description>
<version>1.0-${build.number}</version>
<properties>
<!-- Skip tests, so maven execution is faster. -->
<maven.test.skip>true</maven.test.skip>
<file.encoding>utf-8</file.encoding>
</properties>
<build>
<plugins>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
com.nymag.akamai,
com.akamai.*,
...
</Export-Package>
<Private-Package>
org.apache.axis.*,
...
sun.security,
sun.security.ec,
</Private-Package>
<Bundle-Version>1.0</Bundle-Version>
<Bundle-Activator>com.nymag.akamai.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
...
I agree with stjohnroe that using VM-specific classes is usually bad, but sometimes you have to (for instance, as you are currently in a transition phase). If you want to do so, you can add
org.osgi.framework.system.packages.extra=sun.your.package.of.choice
to the framework properties. If you use the standard Felix launcher, you can edit conf/config.properties for that.
All of these are non public API classes and cannot be relied upon to be present in all jre distributions. I believe that they are all present sun distributions, but not in IBM distributions etc. Try running against a Sun distribution, but this looks like a case of building against undocumented features, a big no no.

Resources