I'd like to use values from a properties file (or some other filesystem resource) in my weblogic.xml. For example, I have this section:
<session-descriptor>
<cookie-name>JSESSIONID</cookie-name>
<cookie-domain>${my.domain}</cookie-domain>
</session-descriptor>
I then have a properties file specifying the value:
my.domain=qa.mydomain.com
on the file system specifying the domain.
Is this possible? Many other configuration mechanisms allow for this. The motivation is that the same code could be deployed in multiple environments with multiple domains and weblogic could simply take the appropriate domain from the file without any operator intervention.
Running weblogic 12c here.
Thanks!
This can be simply achieved using maven's resource plugin, assuming you already on mvn build.
You just need to add below configuration under <build> section
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
You can add below property in your main pom in respective profiles:
<my.domain>desiredValue</my.domain>
In my opinion what you need is to use Weblogic's Deployment Plan feature.
I'm not so familar with it (never used it in productive environments) but with a deployment plan you should be able to change values in web.xml/weblogic.xml during deployment time.
Docs/Example:
Oracle Help Center - Creating and Using a Deployment Plan
Oracle Docs - Save Deployment Plan
Example from middlewaremagic.com
Related
I have the following properties in the pom file
<name>DemoApplication</name>
<description>Demo spring project</description>
<version>1.0.0-SNAPSHOT</version>
And I have a class that reads the properties from application.yml
But instead of using the application.yml under src/main/resources I am specifying the properties through an external file as follows
java -jar DemoApplication-1.0.0-SNAPSHOT.jar --spring.config.location=application.yml
In this external application properties, I have the following attributes
swagger:
apiTitle: '#project.name#'
apiDescription: '#project.description#'
apiVersion: '#project.version#'
The issue is that the #project.name# and other properties are not being replaced as expected, but are read as-is.
How should the problem be approached?
According that section of the official documentation of Spring Boot v2, you can configure it with :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
With useDefaultDelimiters set to false or to true depending on your configuration.
The others sections of that official documentation will be helpful for your use case, especially these one : "77.5 Use YAML for External Properties".
If nothing is working, why don't you are loading a custom Properties file ? It could be loaded as you need without any problem. Just reference it with the correct path when you are starting your program, and inside your program, test if your file config.properties is available and contains what you need to work with.
Of course, the Maven way of loading resources files is the best easy way to go, and it should be a simple Properties file too. I have done exactly that way inside the software I am released to manage my configuration :
Writing a app.properties
Loading that file with Maven at runtime with resource configuration
Expanding properties with classical syntax ${my.prop}
Run the program with a Maven task.
Of course, when you distribute your app as a jar, it is a bit different.
Maybe you can try to write your properties files within a Maven goal.
I have profiles: dev, prod.
And my homepage located at /src/main/resources/static/index.html
How to make different homepage with different profile?
For example, /src/main/resources/static-dev/index.html and /src/main/resources/static-prod/index.html.
Any advice?
Finally I got a simple solution.
Use different config file application.properties and application-prod.properties.
Each of them I config a different resource location. For example spring.resources.static-locations=classpath:/static-dev/.
If your project supports the Maven dependency manager, Maven's build profiles may be able to help you:
<profile>
<id>live</id>
<properties>
<environment>live</environment>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources/${environment}</directory>
</resource>
</resources>
</build>
</profile>
The code above should be in your pom.xml. In your Spring properties you can specify the active profile in one line:
spring.profiles.active=live
This should be enough to conditionally load any resources.
Both resources should be put under /src/main/resources/static (since this is the default static resource folder IIRC) and then categorized into /prod and /dev. Then in your #GetMapping controller, choose to return /prod/index or /dev/index based on your condition
You can create a Filter that changes the request URL from /index.html to /dev/index.html or /prod/index.html as needed.
The filter can also do the /dev or /prod prefixing for .css and .js files.
Unless all your files are split between dev and prod, you'd probably need an explicit list of which requests should be prefixed.
I have 2 projects, one is a webapp, one a jar. Both are projects in maven and the webapp uses the jar as a dependency. I recently implemented the buildnumber-maven-plugin in both so now each have a ${buildNumber} property to reference the scm revision.
I have a UI that I show the versions of both and would like to show the revision number's as well as the version numbers. How can I get the ${buildNumber} property from the pom of the dependency from the main application?
i would use maven to write in a properties file, and this file will be read by a servlet or something like that.
I've not tested it, but that's hint.
First, a properties file, in my war.
This file contains :
version = ${project.version} //the value comes from maven
Secondely,
a servlet or whatever server side (REST resource for example), that can read that property and communicate with the front
Thirdly,
modifying the pom of the war like that :
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<build>
Hope this help
As stated here
The revision number is available using ${buildNumber} in your pom.
<finalName>$\{project.artifactId}-r$\{buildNumber}</finalName>
To propagate it to the resources available to you app you can use instructions from vincent's answer.
Let's assume I have a Java project called com.example:awesome-project, which has a dependency called com.external:awesome-library.
If this awesome-library has resources like configuration.xml, how do I filter this resource so that Maven property placeholders are replaced properly before I use it in the project's code?
Things like <tag name="${groupId}:${artifact}"> need to be changed to <tag name="com.example:awesome-project">, for instance.
Assumptions:
The awesome-library is external to this project, and is not built by
me.
I have no knowledge about the variable placeholders used in the
.xml files. All I know is that they are defined somehow by Maven.
Let's take project meta-data, for example ${artifact}, as an example.
Use dependency:unpack, which will extract resources, by default to ${project.build.directory}/dependency (which you can change if you want).
Then, either use either:
resources:copy-resource and define your filtering in that plugin's execution and also configure its resources configuration to point to ${project.build.directory}/dependency
it might be simpler to just put a resources element in your POM's build section and point it to ${project.build.directory}/dependency with appropriate filtering. Though if you want the standard src/main/resources as well you will need to put it there also.
You can use this solution:
Create parent (builder) project, and place in it constant which will be replaced in resource file:
<properties>
<some.constant>123</some.constant>
</properties>
Define both projects as modules in parent project:
<modules>
<module>../awesome-project</module>
<module>../awesome-library</module>
</modules>
In my-configuration.xml place constant reference as
${some.constant}
In awesome-library.pom config filter processor (for example, suppose that my-configuration.xml is placed in src/main/resources/META-INF:
<build>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>**/my-configuration.xml</include>
</includes>
</resource>
Run maven clean install in parent project.
Good morning # Everybody,
i would like to know if it is possible to externalize Spring libraries. We have a lot of Applications / Webservices which all use the same Spring - libs and now we are forced to deploy our applications on a Websphere (8.5.0.1) server. Since Websphere and Classloading is a bit different than everything else i knew before ...
Well ...
The Idea is the following:
Create a mavenproject containing all Springlibraries and add this jar-file to the server. We would like to keep developing on a tomcat server and just deploy on a websphere without having to much trouble...
But if i move all my springlibs to an external file, it seems that the application cannot be loaded properly (Classloader issue?).
So if anybody of you could give me a hint or a good suggestion, i would really appreciate that.
And of course, if i miss a fact, why it is not possible?
Edit:
This is how my pom.xml actually looks like (a part of course) and i really, really do not like it ...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/hibernate*.jar,
WEB-INF/lib/*spring*.jar,
WEB-INF/lib/xml-apis*.jar,
WEB-INF/lib/xpp3_min*.jar,
WEB-INF/lib/xstream*.jar,
WEB-INF/lib/antlr*.jar,
WEB-INF/lib/webservices-api*.jar,
WEB-INF/lib/commons-collections*.jar,
WEB-INF/lib/dom4j*.jar,
WEB-INF/lib/javassist*.jar,
WEB-INF/lib/jboss-logging*.jar,
WEB-INF/lib/jboss-transaction-api*.jar,
WEB-INF/lib/primefaces*.jar,
WEB-INF/lib/redmond*.jar,
WEB-INF/lib/sunny*.jar,
WEB-INF/lib/akka*.jar,
WEB-INF/lib/scala*.jar,
WEB-INF/lib/scala*.jar,
WEB-INF/lib/jsf-impl*.jar,
WEB-INF/lib/jsf-api*.jar,
WEB-INF/lib/config-0.3.1.jar,
WEB-INF/lib/commons-collections*.jar,
WEB-INF/lib/commons-lang*.jar,
WEB-INF/lib/cglib-nodep*.jar,
WEB-INF/lib/slf4j-api*.jar,
WEB-INF/lib/quartz*.jar,
WEB-INF/lib/c3p0*.jar,
WEB-INF/lib/ojdbc6*.jar,
WEB-INF/lib/mysql-connector-java*.jar,
WEB-INF/lib/aopalliance-1.0.jar,
WEB-INF/lib/aspectjrt-1.6.8.jar,
WEB-INF/lib/cdi-api-1.0.jar,
WEB-INF/lib/commons-cli-1.2.jar,
WEB-INF/lib/commons-io-2.3.jar,
WEB-INF/lib/commons-logging-1.1.1.jar,
WEB-INF/lib/freemarker-2.3.9.jar,
WEB-INF/lib/javax.inject-1.jar,
WEB-INF/lib/jboss-interceptor-api-1.1.jar,
WEB-INF/lib/jcl-over-slf4j-1.6.1.jar,
WEB-INF/lib/jettison-1.0.jar,
WEB-INF/lib/jsr250-api-1.0.jar,
WEB-INF/lib/validation-api-1.0.0.GA.jar
</packagingExcludes>
</configuration>
</plugin>
but if i do it like that, add this libraries as external, my application works (but JUST on a Websphere, which is absolutely not my intention)
try keeping the spring libraries inside the WEB-INF/lib folder as suggested by #Dhanush Gopinath and than change the classloader to parent last.
To change the classloader go in the Domain Manager console to.
Servers > WebSphere Application Servers > $Server Name > Servers Specific Application Settings
Change the ClassLoader policy to "Single" and class loading mode to "parent last". Check if this helps.