Load a properties inside a jar - maven

Can I load a properties file inside a jar in a maven plugin execution?
I have a jar with a system-properties (among other things). I can download and expand it, but I wonder if I there is a way to configure a maven plugin (maven jetty plugin) to load these properties. I was thinking in the:
<configuration>
<systemPropertiesFile></systemPropertiesFile>
</configuration>

You'll probably have to use dependency:unpack first to write the properties to a temporary file, and then the properties-maven-plugin to read the properties from that file.

Related

Jmeter + Maven: how to add a jar file to JMeter /lib/ext folder

I have a Jmeter-Maven project and I'd like to put a modified jar file in "/lib/ext" folder.
I've added it to “/src/test/jmeter/lib/ext”, but seems it doesn't work.
Do I need to add dependencies to my POM file or so?
Any suggestions?
Thanks in advance for answers!
You can add libraries to "lib/ext" folder as follows:
<configuration>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-casutg:2.4</artifact>
</jmeterExtensions>
</configuration>
Replace kg.apc:jmeter-plugins-casutg:2.4 with your own artifact in form of:
groupId:artifactId:version
References:
Guide to naming conventions on groupId, artifactId and version
Adding jar's to the /lib/ext directory
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Execute Maven plugin with custom classpath entry

I would like to call a maven plugin with a custom entry on its classpath. This is usually possible by adding <dependencies> inside the <plugin> tag. The problem is, what I would like to add to the classpath is not a maven artifact, but some random folder in my project (the reasons for this are quite obscure, I need a resource file to be present of the classpath, but I must not copy it to the /target/classes due to IDE shenanigans).
Is there any way to specify truly arbitrary classpath entries for a maven plugin?

Add test jars in maven-jetty-plugin or create test-war with maven-war-plugin

I'm using maven to build a multi-module webapp. I would like to run my integration tests in their own module and use the jetty plugin. In order to get everything to work I will need to add a couple of jars to the classpath for the war but I see no option for such a thing in the documentation http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#deploy-war-running-pre-assembled-war
I am able to deploy the war but it fails because it's missing the two jars I need to add.
Is there a way for me to add a couple extra jars to the plugin configuration?
If not, is there a way for me to package a "test-war" like you can do with test-jar in maven?
There are multiple ways to extend the web application classpath with the jetty-maven-plugin. The most appropriated for you would be to set the extraClasspath field in the webAppConfig block of your plugin configuration:
<configuration>
...
<webAppConfig>
...
<extraClasspath>path/to/your/custom-dependency.jar</extraClasspath>
</webAppConfig>
</configuration>
The documentation is not very consistent about that. But the javadoc is quite clear.
You can find relevant configuration examples on my jetty plugin wiki page.
Add the dependencies directly to the plugin's <dependencies/>. No need for scopes or anything -- they'll not enter your final artifact, but rather -- only be used by the Jetty plugin during execution.

read Maven variable from properties file using profile

I want to read a maven variable for configure a build plugin from a properties file. It's not needed in and further project files e.g. context files.
1) made a profile (it works, can use mvn ... -P private)
<profile>
<id>private</id>
<properties>
<env>private</env>
</properties>
</profile>
2) created the filter file with this content (it works)
foo.path=/home/foo/path
3) try to configure the plugin (does not work)
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>foo-plugin</artifactId>
<version>${foo-plugin.version}</version>
<configuration>
<!--<fooPath>home/foo/path></fooPath> that works -->
<fooPath>${foo.path}</fooPath> <!--works not -->
</configuration>
...
</build>
Thx a lot
The name of your property is 'env' but you don't use env anywhere in your configuration.
When Maven docs mention "filter files" they usually mean a file used when processing resources (i.e. copying resources from /src/main/resources to target/classes). As far as I know the properties in those files aren't used for plugin configuration out-of-the-box. I have used the Codehaus properties-maven-plugin:read-project-properties goal do do what you are attempting. Make sure you bind the goal to the lifecycle before any plugins that need the properties for config.
Also, see this answer; you may load properties used to configure other plugins, but not to configure core Maven project elements.

how to let maven war plugin to create multiple war file

i used selenium-mave-plugin for integration test, which require the war file named: project.artifactId-version(say: myproj-0.1-SNAPSHOT.war) while the default war created by maven-war-plugin is project.artifactId.war(say myproj-SNAPSHOT.war).
in order to let selenium plugin, i override the maven-war-plugin in that selenium profile as:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<warName>${project.artifactId}-${project.version}</warName>
</configuration>
</plugin>
now when i build the project, it failed at rpm:rpm, complaining:
source location ..../myProj.war does not exist
my question is if it's possible to create 2 war files: myProj.war and myProj-0.1-SNAPSHOT.war so both rpm and selenium plugins are happy? Thanks
For rpm plugin, please make sure you use the location directive. If you need further help, please post your full pom.xml.
As for selenium, it doesn't really need to know where your .war file resides. Only the web application server needs to know. Sadly, you didn't provide information in which phase of maven the "does not exist" error occured. So I can only guess it's while starting jetty, tomcat or another web application server.
You should run your full build (including tests) with: mvn clean verify integration-test rpm:prm.

Resources