Mule 4 : Is there a way to refer Maven POM properties from a Mule Flow? - mule4

I want to refer the project name and version in the URL of the API. For example, my app is called sample-mule-project and has a version "v1". So my final URL should be like /sample-mule-project/v1/
Maven pom has these properties called name and version with which we can refer these values inside the pom file. Is there a way how we can refer these values inside the mule flow?
I tried using ${project.name} and ${project.version} but it did not work which I understand is because these are not defined inside properties file. So is there a way to achieve this?

That's because Maven properties do not exists anymore when the application is executed.
You can use some Maven plugins to replace values in a properties files, that can be used inside the application. For example the Maven Resources plugin. Be careful of not override properties inside other files, like the XML Mule configurations of the application.

Related

Spring MVC application.properties not override by profile file application-dev.properties

I was looking at a way to configure different application.properties file depending on a JVM environnement variable.
I found this documentation on Spring references.
In addition to application.properties files, profile-specific properties can also be defined using the naming convention application-{profile}.properties.
Profile specific properties are loaded from the same locations as standard application.properties, with profile-specific files always overriding the default ones irrespective of whether the profile-specific files are inside or outside your packaged jar.
Then I did that :
Configuration structure
And then added a -Dspring.profiles.active=dev to my JVM options.
Profile option for JVM
I tried to see that my params in dev are used but it isn't the case. Te application loads the data from the application.properties file.
Any idea why?
Try to modify the default properties file's name to 'application-default.properties', as it is said in the documentation:
The Environment has a set of default profiles (by default [default]) which are used if no active profiles are set (i.e. if no profiles are explicitly activated then properties from application-default.properties are loaded).
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties

How do I deploy application classes and Spring config files to Tomcat as a single jar?

Currently I create a new war file for each change but the changes are taking place in only a few classes and the Spring applicationContext.xml.
I would like to just update a jar file that contains these classes and not continually re-deploy hundreds of files that have not changed. I can create the jar easily enough but where do I put it and do I have to tell Spring to look in a specific jar for its' config files?
It is quite impossible to hot-redeploy code in Tomcat without using extra tools like JRebel or custom JVM agents.
But it is possible to modularize you application by:
1: Putting JARs to $TOMCAT_HOME/lib. Never do this, this solution is good only for simple cases.
2: Tune context.xml, putting Loader in it, like below:
<Context antiJARLocking="true" path="/">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="${catalina.base}/my-app-plugins/*.jar"/>
</Context>
This will enable you putting JAR file in $TOMCAT_HOME/my-app-plugins and thet will be added to the classpath of you app. You should put context.xml to the src/main/webapp/META-INF folder (Maven layout). However, restart is still needed.
3: Use OSGi. May be an overkill.

How to set order of jars in WebLogic?

In my application I am using Joda-Time 2.0 but in my WebLogic path there is library Joda-Time 1.2.
How can I change the order and tell WebLogic to use my library? Now it is using its own library, not mine. I just added a Maven project dependency to Joda-Time 2.0.
There are several ways of doing this.
Change your startWeblogic.cmd(sh) in the bin folder for your domain, look for the classpath setting and add the new joda before any other WebLogic jars
as was said above, you can change your weblogic.xml if the application is a web application and chose to prefer any lib that comes inside the war.
If you are using an Enterprise application, you can set the following options in your weblogic-application.xml:
<prefer-application-packages>
<package-name>org.apache.*</package-name>
<package-name>antlr.*</package-name>
</prefer-application-packages>
And set your package name for joda in there.
Please note that the first option might result in strange behavior from WebLogic.
Note for some reason I can't get the code to work with the XML.
As your class is present in your war, WEB-INF/lib,
can you try using the weblogic.xml setting to force the WEB-INF/lib class to get loaded in preference to that in server/lib with
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

External classes/jar in OSGi

My application supports running on many dbms and it requires user to configure dbms connection setting and also provide the jdbc jar file.
Now the application is to be packaged as OSGi bundle. There will be another main jar which lanches OSGi server and starts the application as bundle.
Can you please suggest how can I package the application as bundle and let user provide the jdbc jar file.
Will it require something like the main launcher jar specifying JDBC driver classes as FRAMEWORK_SYSTEMPACKAGES property?
Thanks in advance,
Aman
There are two ways of doing this:
1) Adding the driver.jar to the classpath of the main launcher and, like you say, expose its packages via the framework by specifying that property (or actually you can use the FRAMEWORK_SYSTEMPACKAGES_EXTRA property to just specify additional packages, instead of specifying all of them).
2) Manually wrapping the driver.jar as a bundle, or doing it dynamically at runtime. For example, you could try to wrap bundles that are copied to a certain folder (similar to what Apache Felix File Install does) by using Pax URL or some other tool that can create a bundle out of an ordinary jar file for you (see http://team.ops4j.org/wiki/display/paxurl/Pax+URL).

Unity 2.0 XML configuration possible?

Is it possible to use custom XML to store unity container configuration in my IoC class library project?
I dont want to store the IoC config at the startup project (WPF project).
Regards
Bryan
You can use ConfigurationManager.OpenMappedExeConfiguration to load an arbitrary file, but you'll need to do that yourself - the simpler overloads will go to the appdomain's config file by default.
If you have the Unity source code, you can look in the Unity\Tests\TestSupport.Unity\Configuration\ConfigFileLoader.cs file for an (perhap overly complex) example. There we pull a config file out of a resource, dump it to disk, and then load it via ConfigurationManager.

Resources