Maven: how to deploy updated resources? - maven

I am having trouble getting a good work flow using Maven for a webapp.
My context.xml fragment points to the target/MY_WEB_APP folder and so I would like a quick way to get modified resource files into that folder.
My resource files are in src/main/resources and they get copied to target/classes when I run Maven resources:resources. However unless I run a full build I don't get those files in the target/MY_WEB_APP folder. The full build takes a couple of minutes and I only want to copy the modified resource files.
All of the resources are classpath resources and are hot swappable as the frameworks can be set to auto-reload. An example is the Struts config files that are auto-reloaded on each request as I have set struts.devMode=true. Hence if I can get it into the correct location then I don't need to do a full build.
Currently I have a text editor that has the open resource file target/MY_WEB_APP/WEB-INF/classes/my-resource.xml and I manually copy the modified file from my IDE into the editor. This is obviously a very, very silly way to work and there must be a better way.
How can this be done without the manual copy and paste?

Related

Maven not including class subfolder when changing build source directory

So I'm working on an old project that hasn't always been a Maven project, so the folder structure is not the Maven standard. Given this, in the POM was set that was not the folder that has all the source folders, but actually pointed directly at one of the source folders. This has been a pain since every Maven re-import I need to go change the project structure to have the sources be src/ and not src/folder1, src/folder2, src/folder3...
The fix was simple, to fix the path, but here comes the issue. In src/folder1/subfolder is Images folder, which contains images used by a class in subfolder. But now that no longer points to src/folder1 the Images folder no longer being included in the build output.
I can fix the issue by reverting the path and correcting it manually every time, but I'm here asking could I somehow keep the fix and still get the folder included too.

Why can I replace a file on Windows NTFS that I cannot delete

I came across a curious discovery a few days ago with my windows file system, which uses NTFS.
I have a folder within my file system my gradle projects use as a cache. Within this folder, are many different folders containing java .jar files used as dependencies for my project. Typically, these jar files are downloaded from the cloud storage system our project uses for storing these jars. There are three different ways I update these jar files.
I can do a complete refresh through my gradle project, in which every jar in my cache is updated. This takes alot of time and is only done when absolutely necessary
When I want to get the most recent version of a single jar, I will delete the jar file, and refresh my project. The project internally reaches out to the cloud storage system and downloads a new jar.
When I do local development and want to test my changes, sometimes I will replace these jars(overwriting the previous jar) with a jar I developed locally for testing.
However, if any of my java applications using these jars are open, I can only replace the jars, I am unable to delete them. If I attempt to delete them, I receive a The action can't be completed because the file is open in Java(TM) Platform SE binary. To delete the jar for following step 2, I have to close my entire project before deleting.
I have read here, here, & here on why this is the case, however I cannot find a concrete answer on why Microsoft NTFS will allow me to overwrite the jar with another when it is in use, however I cannot delete the jar while it is in use. Why is this the case?

Best directory for Gradle build resources (e.g. license header template)

I'm looking for the appropriate location to place resources that are used by the build, like a license header template file or a file with code formatter settings.
The buildSrc seems like the most appropiate place (e.g. buildSrc/src/main/resources), but I only found it mentioned in the context of Build sources.
Another option would be src/build/resources. Perhaps there are better locations I didn't consider.
What would be the most appropriate directory for these resources?
In many gradle builds the convention of using $rootproject/gradle as folder for build resources has been established. you can have a config folder to store your license files / checkstyle configs etc. in there.

Include files (.properties files) in gradle builld into the same of directory of the .class

The follow structure
src
service
service1
Service.java
Service.properties
I want that the output generated by gradle would be
classes
service
service1
Service.class
Service.properties
So, I need that the files(.properties) keep in the same directory of the class after build, but the gradle copy the files .properties (resources) to another directory
how can I do it?
I assume you are trying to place them there so they can be loaded from the classpath? The best way to make them available to your class loader is to place them into src/main/resources which is part of the standard directory layout. Gradle will find them there and they will be placed at the root of your jar (by default I believe it ignores property files in src/main/java).
It would also be good to move your java files to to src/main/java. Using the standard directory layout is a convention that will help other developers understand the code. It also allows you to use certain tools out of the box with less configuration because those tools can make assumptions about where things live.
So the new structure would be like:
service1-project
src
main
java
service1.java
resources
service.properties
If you use the standard directory layout, I think you will achieve the end-result of what you are trying to do (which is really to load the properties file within Java). If for some reason you have to avoid the standard directory layout, then you have to start doing custom configuration (a downside of using a non-standard project layout). In Gradle, you should be able to do this by hooking into the Java Plugin's processSourceSetResources target.

Copy static resources (js and css) from a war dependency to Grails application's web-app directory.

I have a project in Grails 2.1.3 and I'm trying to copy static resources like javascripts and css files from a war dependency to my Grails application's web-app/ directory. I'm trying to achieve something like war overlay. I tried generating the pom and using overlay feature of maven-war-plugin but it doesn't seem to work. Please, suggest a solution.
You could download the WAR file, then extract the contents with WinZip/WinRAR/7zip (or even with command line).
Then just copy over the files you need into your project's web-app directory.
This is, of course, assuming that you only need to copy these files over once, and not every time the app is run.

Resources