maven-antrun-plugin copy resources works only on validate phase - maven

I am using maven-antrun-plugin version 1.8 to copy some files to the src/main/resources folder so that it gets included in jar in package phase.
If the execution phase of the task defined to copy to resources folder is validate everything works fine but if it is compile/test the files are copied to src/main/resources folder but are not included in jar

It is because Resources folder gets copied to target folder at process-resources phase of Maven. Therefore to get files in the resources folder of jar/war you need to copy files to resources folder before the process-resources phase i.e. you can pick validate, initialize and generate-sources phase of maven for same.

It is important to understand the Maven lifecycle. Bind the Antrun plugin to an early enough phase to achieve what you want.
That said - consider packaging the other resources into a jar and then adding that jar as a dependency instead of adding Antrun plugin invocations. Or, use the Assembly plugin.

Related

Can i make maven-war-plugin to *only* copy the classes.jar but not the .war into local repo?

OK, so i'm using the maven-war-plugin to build my war, which works fine.
I also have it setup to generate a -classes.jar.
When i run the build, both the war and -classes.jar gets copied into my .m2 repo, which takes up a lot of space.
I would like for only the classes-jar to get copied. Howver, setting the maven-install-plugin to "skip" skips both war and the classes-jar.
Is there a way for me to configure the war build so that only the classes jar gets copied into the repo?
Thanks in advance

How do I build an exploded WAR in a multi-module Maven project and also include sibling JAR files in its WEB-INF/lib directory?

I’m using Maven 3.3.3 with the Maven WAR 2.6 plugin. I have a multi module project with both JAR and WAR projects within it. My WAR projects depend on my JAR projects, however, I do not want to package my WAR files, opting instead to keep them in an exploded form. So I tried running this command
/usr/local/apache-maven-3.3.3/bin/mvn -B -f /home/jboss/.jenkins/jobs/subco/workspace/pom.xml -B clean prepare-package war:exploded -DskipTests -T 3
Although this keeps my WAR exploded, the JAR projects do not get included in my web application’s target/myproject/WEB-INF/lib directory. Instead what is included are empty directories where my JAR files would have been, for instance
.jenkins/jobs/subco/workspace/myproject/target/myproject/WEB-INF/lib/child-jar-module-2.0.0-SNAPSHOT.jar/
How can I keep an exploded WAR, include my JAR files, and do it all from the command line (as opposed to creating a custom profile in my parent pom to do it for me)?
Edit: If you think this is a duplicate of another one, notice the part of my question where i point out that empty directories are generated when using the "prepare-package" phase. I don't want that.

Maven - Which build phase?

I have a Jetty embedded project.
I configured the package phase, using maven-shade-plugin, to create a jar file. It creates a jar file on target folder.
I need to copy some a folter, containing some javascript/html. Which phase do i have to use? the same package phase?
thanks
It depends on what you trying to archive - building a jar containing ressources such as javascript and html files Maven will automaticially include those resources if you place them under /src/main/resources unless excluded in the pom.xml in the phase package (the same and only non-plugin available phase package of the default lifecycle of Maven).
If you on the other hand want to build a webapplication you normally specify the packaging to be a war leading to a *.war web archive. In this case you would normaly place script and html files somewhere under src/main/webapp/WEB-INF as described here: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

How to reference packaged resources from the jasmine maven plugin?

I want to use the jasmine-maven-plugin to test my maven my-webapp project. This project depends on another my-lib project that contains some required JavaScript libraries. When the my-webapp project is built, it adds the my-lib JAR to the WEB-INF/lib/ path of the generated WAR. Inside the my-lib JAR, the needed JS resources are in folders META-INF/resources and META-INF/test-resources.
How can I reference these packaged resources from the jasmine-maven-plugin goals jasmine:bdd and jasmine:test?
Note that I've also tried to run the goals in the integration-test phase like explained here, but I still can't reference the needed resources.
UPDATE: Would running jetty:run-war from within the jasmine-maven-plugin help? If so, how can I achieve that?
I think you would need to first use the maven-dependency-plugin to unpack the jar, under a different goal.
Something like this: unpack dependency and repack classes using maven?
Then you can specify the parameters, under the configuration section of the plugin for that goal, from wherever you unpacked the jar.
wherever/you/unpacked/
Run the unpack goal first, then the bdd and test.

How to make Maven deploy src/main/resources?

I have a Maven project. It is successfully deploying the jar file. I also want it to deploy the contents of src/main/resources.
mvn deploy does not deploy the resources.
How can I make it do that?
I read about using the copy file task and other workaround methods, but I want to use Maven's default behavior for deploying, which I thought would include the resources.
The folder src/main/resources contains resources which will be packaged into the jar file which means in other words it is already deployed within the created jar file.

Resources