Netbeans does not always update target/classes/*.class file on incremental compile on a Maven project - maven

I use Netbeans 9.0 with a Java Maven project with SpringBoot 2.1M4.
The application is running in a terminal window with Spring DevTools enabled so that it reloads every time a .class in target/classes is touched.
This setup generally works fine. Problem is, that sometimes, I notice that Netbeans stopps actually updating the class files. I change the source, save, have of course "compile on save" activated but a find target/classes -name "Foo.class" continues to show the old timestamp so DevTools have no chance to notice the change.
A complete build on the other hand executes Maven and that, of course, regenerates the target/classes files as expected.
Is there any mechanism in Netbeans that I'm not aware of that controls how the Netbeans "incremental compile" affects the class files?
(I experienced similar problems before with Netbeans 8.2 and various application servers or DCEVM/HotSwap, which also monitor file changes)

Related

Modules, Gradle Subprojects, and IntelliJ Woes?

I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ.
My project structure is as follows:
Root
- settings.gradle
- core
- build.gradle
- desktop
- build.gradle
- src/main/java/module-info.java
The desktop build.gradle file as a requirement on core as:
dependencies {
implementation project(":core")
}
There is no reference to the "core" project in the module-info.java files.
In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.
My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.
Would appreciate any insight.
P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?
I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.
There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:
In the Gradle tool window, click the top-left button Refresh all Gradle projects.
Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
Click the invalidate caches/restart in the main menu.
You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.
Hope these steps could help you.

spring-boot-devtools doesn't reload dependent modules in multi-module maven project

Before I start, I'd like to say that I already tried the solution proposed in spring-boot-devtools reload of multi-module maven project changes, which didn't work for me.
Problem:
I have a multi-module Spring Boot project of this sort:
The module launcher has a Maven dependency on module GUI. I launch my Spring Boot application from the main method in launcher.
When I run the application and change any HTML file in GUI module, the spring-boot-devtools dependency doesn't do a live reload of these changes for my running application. Not even manual restart of launcher helps. I need to compile GUI manually and then run launcher again.
What I tried:
I tried defining the spring-boot-devtools dependency first in
parent pom.xml, then in GUI module only and then in both at the same time.
I tried adding spring.devtools.restart.additional-paths=../gui in my application.properties file as suggested in spring-boot-devtools reload of multi-module maven project changes. This does indeed trigger the reload (according to the log), but those changes just don't propagate to the jar file of GUI dependency. Also, before I even made this project into multi-module, there was no need for reloading just because of HTML files (nothing is being compiled) and I could see the changes right away.
I use Netbeans GUI if that's of any help. I also tried running the project from command line, with no success. The Maven packaging on all modules is set to jar.
The fact that this works when you configure absolute paths in devtools tells me that this is mainly a work directory issue.
So this means that:
configured paths should be relative to where you launch the CLI
you should configure the same location as a work directory in the run configuration of your IDE (whatever configuration your IDE is using to launch your application should have such an option)
In your case: everything should be relative to your launcher module; this should be as well your work directory in your IDE.
I have no idea how it happened, but upon one revisit it started working without me knowingly changing anything. It doesn't even require the spring.devtools.restart.additional-path property set.
Could've been a problem of Netbeans IDE perhaps? Then again, it didn't work from command line either. If anyone has any explanation for this, it'd still be grateful as it may prevent this problem from happening in future.

How to pass on changements on server without to be forced to build manually all sub-modules changed?

Hello all !
In my team we currently use Eclipse but I am not satisfied and I wanted to discover netbeans (8 version). It seems very nice. There is a good management of webprojects( angularJS, requirejs). There is a full integration of maven project and Java EE project, it's free ( not like intelliJ) and it seems more intuitive than eclipse et less strange/magic , more compréhensible (because full integration of maven)
There is a lot of points who could push my team to adopt this IDE but there is a problem,a need that I can not satisfy.
I have maven modules projects with dependency mangement. A parent project (called 'webParent' that contains a reference of a big parent project of the team. 'webParent' also contains a sub project 'WebProject' that is a java Webproject that contains web resources( html, js, css) and a java rest webservice management.
'WebProject' use service by injection dependency of an other project called 'business'. 'business' is a part of an other parent project called 'core'. 'core' contains modules that are 'business' (business services of application), 'dataAccess' (gather all DAO), 'External' (gather all external webservice) and 'Authent' (authentication ..).
All these core modules are linked.
'business' need => 'dataAccess' , 'External', 'Authent'
'External' need => 'dataAccess'
'Authent' need => 'dataAccess'
Netbeans has perfectly integrated my project, no problem with that.
I could perfectly use my previous jboss install. Netbeans and jboss work perfectly together. but my problem is that my modifications are not take in account by jboss on redeploy.
I have installed this plugin in my webproject https://docs.jboss.org/jbossas/7/plugins/maven/latest/
Indeed it work fine. When I need to redeploy my project I launch jboss-as:redeploy and a war is regenerated and sent to jboss. Jboss restart speedly and it's cool. But if I modify the java code
in my sub-modules (ex: business) I am forced to click on build button (the hammer) on each sub project I modified. Wait that build say "nothing to compile (indeed the compile on save is checked for all project), regeneration of the jar module"
And I stop on this detail. The "jar". Indeed when I verify my local repository my module jar is not changed with compile on save, it's just the target folder of the project that is modified.
So when I launch the redeploy, the plugin launch the build of my webproject who search my modules jars on my local repository. And take a version not modified ..
This problem slowed a lot the developpement and because of it my team will never use netbeans in the future..
The other problem is that I am forced to lauch jboss-as:redeploy to redeploy web ressource (html, css, js) . For me its should be automatically repercuted on my server. But the problem is that jboss use a war that is generated on install.. What's the solution ? With eclipse it's not based entirely on maven (not cool) but the repercution of modification is very speed ( cool)
Help me to stay on netbeans ! ;)

Intellij Debugging picking up old version project files

I am debugging code in Intellij. I use maven to build the project and there are various versions of the project sitting in the local .m2 repository. Intellij keeps on picking the old version of the code from the previous snapshot of the project when I start debugging. How do I make IntelliJ debug the latest code from the local repository?
You can tell Intellij 2016 to ask you each time which source code to step through.
File->Settings->Debugger
Show alternative source switcher
Try removing .jar and .war files that contain your code from your ~/.m2/repository/
For me the issue is that I built something and it is now registered in Maven under what Maven considers a newer version, but isn't what I was currently working on. I compiled, say, version "2.1" to debug something and then went back to working on "sand-box-idea-SNAPSHOT". I keep thinking why isn't Intellij picking up my latest sand box change but it's because it's deferring to the Maven version 2.1 which Maven assumes is better than 'sand-box-SNAPSHOT'.
It may be that you have some plug-ins interfering with IntelliJ's build process. I know that the Google Protocol Buffers Plugin can cause my Intellij to be unable to detect dirty classes that need to be re-compiled.
I've met similar behavior, maybe it can help you :-)
I developed app (using maven) and during the time I change output packaging from jar to war. Maven repository than contained both versions, jar and war, because maven does not remove old jar when you change it. As project pointed to mvn repository, it still used old reference to jar but new version within war was updated.
I was really upset as maven compilation and tests worked fine but Idea used me old version. I've had rebuild idea project and it worked later fine.
I have seen this very recently after upgrading from IDEA 13 to IDEA 14. It seems like launching configurations created in IDEA 13 are no longer automatically triggering a mvn package prior to launch.
In order to fix this I manually added a mvn goal in the "Before Launch" dialog.

Update dependencies while in hosted mode in GWT

I have a GWT webapp split into two Maven projects where one is a dependency to the other. Each time I change something in the dependency and I'm running webapp in hosted mode I have to rebuild the subproject and restart hosted mode for changes to apply. It takes a lot of time so I'd like to ask you if there is any way to make GWT using "live" version of the dependency?
There are 2 cases:
for server-side code, assuming you use the DevMode's embedded server, rebuilding the app and then refreshing the server should be enough
for client-side code, AFAICT, you have to use the source and output directories of the dependency module rather than the JAR containing them (GWT will load the source from the classpath, but apparently it'll only see the modified sources if it comes from a folder rather than a JAR; at least that's what I found in my tests). This goes against The Maven Way™ but the only solution so far is to use a special profile that will import the sources of the dependency project as sources of the project you're running. You can see examples of that in my archetypes.
There's actually a bug opened for the gwt-maven-plugin, MGWT-332, to do that automatically when running a reactor build. I also mused about what's really needed, for the forthcoming official gwt-maven-plugin (rewritten from scratch, independent from the CodeHaus Mojo plugin).
If your dependency does not come from a reactor build, then you're out on your own: you chose to make it totally distinct, so that's how it'll behave: you'll have to release it (even a snapshot) each time you make a change to it, and use the new version in your app (which means re-launching the DevMode).
This can be circumvented by running DevMode on your own, without the help of the gwt-maven-plugin. You're left on your own managing the classpath though (using the Google Plugin for Eclipse, I suppose you could simply edit the launch configuration to add the source folders of your dependency project to the classpath, before the classpath provided by Maven, that would reference the JAR).
Remove the dependent other application jar file from the primary application lib folder under webapp.
Eclipse should then resolve the dependency using the other project in the workspace if you have added it to your primary application classpath.
As GWT build takes ages, we invested some money in a JRebel license. We have two separate Eclipse projects for our back-end and our GWT front-end. JRebel reloads the classes automatically and I never need to restart my local server while writing code. It proved to be a wonderful time saver. Definitely worth the investment.

Resources