How to update folders automatically with IntelliJ - maven

I have a Maven configuration that copies my web resources to a directory in target. From there it is read by Jetty. What I want (and what Eclipse always did for me) is update the target/web directory when something in the src/main/webapp directory changed. I can't get IntelliJ to do the same:
The resource configuration like this:
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>less/</exclude>
</excludes>
<filtering>false</filtering>
<targetPath>${project.build.directory}/web</targetPath>
</resource>
Right now I have to run the Generate sources and update folders everytime I make a change. Can't IntelliJ Detect this automatically?
Notes:
I do not build a war but a folder distribution.
I already tried moving it to target/generated-sources/web but that makes no difference.
The target/web is not marked as excluded in the module configuration.
The folder is marked as a resource folder. I tried marking it as a source folder but that made no difference.

The problem can be solved by using the File watchers plug-in. This plug-in doesn't ship with IntelliJ by default but it is very useful. From there, you can watch your *.less/html/js files and re-generate them if you edit them. In my case I run the appropriate Maven goals but you can also call the less compiler directly if you want to.
In the configuration set "Output paths to refresh" to the the custom directory you are using (in my case $OutputPath$/web). After that, any change should be refreshed automatically.

I think, yes: try pressing Ctrl+Shift+A, type "Import Maven", click the checkbox "Import Maven project automatically". This will enable auto-import which copies resources as well.

Related

How do I specify a directory prefix on a set of resources in maven's pom.xml

I have a set of files I'd like to include in the .jar generated by mvn compile. Unfortunately, I would like them to be placed in a specific path inside the .jar. For example, I want shaders/main.glsl to be in the .jar file as com/purplefrog/expglsl/castle/main.glsl
How do I specify this mapping in the pom.xml ? I can not mess with the directory heirarchy of the source project without throwing a wrench into other coders' workflows.
During the process-resources phase non-compilable files can be moved (by the maven-resources-plugin). What you should do is add a resource-block to your pom. Here you need to specify the directory. You can also add a targetPath. All together it would look like
<resource>
<directory>shaders</directory>
<!-- include all ore just a couple of files? -- >
<includes>
<include>main.glsl</include>
</includes>
<targetPath>com/purplefrog/expglsl/castle</targetPath>
</resource>
Now these files are copied to the target/classes and during the package phase they'll become part of the jar.
Take a look at the Maven Resources Plugin and this question.
Sounds like that should handle what you're looking to do if modifying the project structure up front isn't an option.

JavaFX Self Installer With Inno Setup 5 - Allow user to change install directory

I am using Ant to build a self deploying EXE for a JavaFX application.
Currently Inno Setup places the EXE here: C:\Users\username\AppData\Local\application name
I would like to place this in a different location, and provide the user the option to override this. However I can't seem to find the ant settings to change this.
Is this possible?
Thanks!
Actually you can't change this using ANT. However, as you already know the deploy mechanism uses Inno Setup and you can modify its behaviour.
During the fx:deploy ANT task a default ApplicationName.iss file is created. This default file contains e.g. the setting, which is responsible for the install directory. This default file is only created, if you don't provide any customized on your own. So, I would recommend to run the ANT script, copy the default file and modify it. If you enable the verbose flag of the fx:deploy task you can use the console output to find out, where the default file is created and where the ANT task searches for your customized file before creating the default one:
<fx:deploy
...
verbose="true">
<fx:info title="${appname}" vendor="${vendor}"/>
...
</fx:deploy>
In my case I found the default file in
C:\Users\gfkri\AppData\Local\Temp\fxbundler3627681647438085792\windows
and had to put the customized file to
package/windows/ApplicationName.iss
relative to the ANT build script.
If you got so far, you'll find the line DisableDirPage=Yes in your ApplicationName.iss file. Change it to DisableDirPage=No and the user gets the possibility to change the install directory.
Further you will find the parameter DefaultDirName. If you want to install your Application to C:\Program File\ApplicationName by default you can use the constant {pf} e.g.: DefaultDirName={pf}\ApplicationName.
The original answer is not true anymore, because that feature got added to the JDK (just dont know when, but it was there when using 1.8.0u60 or so).
Just add <installdirChooser> as some <bundleArguments> and set it to true:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.4.0</version>
<configuration>
<mainClass>your.mainclass</mainClass>
<verbose>true</verbose>
<bundleArguments>
<identifier>SOME-GUID-USED-FOR-UPDATE-DETECTION</identifier>
<installdirChooser>true</installdirChooser>
</bundleArguments>
</configuration>
</plugin>
Disclaimer: I'm the maintainer of the javafx-maven-plugin

Maven webapp with non-default web resource directory

Maven sets the default webapp directory to src/main/webapp as per http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.
We use a IDE-configured server for development, which uses the files from this directory to serve. The server doesn't work from another directory and serves directly from the file system. This has the benefit that every change we make to the source files is visible instantly.
However, all the files in the webapp directory are not minified, not concatenated, etc. I have currently setup grunt to take the files from the webapp directory and put the deployment-ready resources in src/main/webapp/dist.
The problem: when building a war, the contents of src/main/webapp are copied into the war, but I want only the deployment-ready files from src/main/webapp/dist to be copied into the war.
I've tried countless google searchs for the topic and I'm feeling stupid. As already stated, I found "http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html", which says "these settings can be overridden via the project descriptor", but it does not show how. I found http://maven.apache.org/pom.html#Build_Element which doesn't show the webapp directory. I've found "http://maven.apache.org/guides/mini/guide-using-one-source-directory.html" which again, doesn't specify how to change the directories.
I know I can just specify src/main/webapp/dist as an additional resource directory and it will be copied into root war directory. But I don't want all the development files available in the production build.
Also, if someone knows of a better way of handling my general approach, I would like to hear it as well.
I found the setting, finally. http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
Add
<warSourceDirectory>src/main/webapp/dist</warSourceDirectory>
to the maven-war-plugin configuration, like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/webapp/dist</warSourceDirectory>
</configuration>
</plugin>

maven is src/main/resources always picked up?

I have a custom properties folder for each build environment. I have defined profiles for it and added the different folder. They get picked up properly. However the resources in src/main/resources is not being picked up. I am using netbeans 8 if it makes a difference. My question is once a different profile is activated, should the main resources or test resources need be specified again in the profile? Thanks.
I am developing a java web project using maven. There are some xml files (handlerchain.xml) for some web services that need to be redeployed. These files reside in the same source directory as the java files which do not get copied. Hence I put these files into src/main/resources directory so that they will be deployed properly when it is time to build/test...
I also have a custom resources directory where I hold a set of properties files for each build case. They are all named the same but reside in different directories such as dev, prod, etc.. To deploy these into the build, I am using profiles and hence I have one profile set up for dev, prod, etc. In these profiles, I have added the custom resources directory with the proper directory such as custom-resources/dev for dev profile and custom-resources/prod for production profile.
I have noticed that the src/main/resources do not get deployed when I am using dev profile. It only gets deployed when I specifically add it as a resource in the profile/build/resources path. Is this because since I am using a custom profile and did override resources, I have to specify it?
In other words, I did not have to tell Maven where my java files are so why do I have to specify the directory for src/main/resources? Thanks.
Once you declare an explicit resource in the pom.xml Maven forgets that src/main/resources ever existed. You must now put it back explicitly:
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>

Maven jetty plugin using wrong resource file URL

I am running a project within a vagrant box setup over my eclipse workspace. I am working on setting up a new maven project but I am having problems with the plugin using windows paths instead of the vagrant path. My windows workspace is setup in C:\Dev, so when I 'vagrant up', my entire workspace is available within my VM. In other words, /vagrant in the VM contains the contents of C:\Dev.
When I execute mvn jetty:run, everything starts up fine and all paths use the vagrant versions (/vagrant/mvn_project/target...). However, once the plugin starts scanning the project for changes, it throws the following error:
2014-02-26 01:18:53.756:WARN:oejw.WebAppContext:Scanner-0: Failed startup of context o.e.j.m.p.JettyWebAppContext#591f46d8{/,[file:/vagrant/mvn_project/web, file:/vagrant/mvn_project/target/webapps/ROOT/],STARTING}{/ROOT/]}
javax.servlet.UnavailableException: Malformed URL 'file://C:\\Dev\\mvn_project/target/webapps/ROOT/WEB-INF/dtd/web-app_2_3.dtd' : For input string: "\\Dev\\mvn_project"
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:351)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:840)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:300)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1347)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:532)
at org.eclipse.jetty.maven.plugin.JettyRunMojo$1.filesChanged(JettyRunMojo.java:485)
at org.eclipse.jetty.util.Scanner.reportBulkChanges(Scanner.java:681)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:539)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Is this a bug with the plugin or is there a configuration setting I can use to set this value?
Edit: A little more context... It seems that the problem has something to do with filtered resources.
<resources>
<resource>
<directory>${project.basedir}/src/main/filtered-resources</directory>
<filtering>true</filtering>
<targetPath>${project.basedir}/target/webapps/ROOT</targetPath>
</resource>
</resources>
Changing ${project.basedir} to /vagrant/mvn_project seems to fix the problem, but clearly this is just a workaround and not a solution (won't work in CI for example).
UPDATE: It turns out, the blame is on Eclipse. Eclipse is occasionally building the project and when it does so, ${project.basedir} refers to C:\Dev\mvn_project instead of /vagrant/mvn_project. Is there a way to override ${project.basedir} without hard coding?
Simple answer: disable builds in eclipse. Uncheck Project -> Build Automatically. Always run builds from within vagrant (mvn compile). JSP hot changes still work automatically.

Resources