问题
I'm trying to setup deploy on save (or compile on save, or whatever I should setup) correctly in Netbeans.
I'm trying to achieve this:
1) hot-replace some class when needed if the structure didn't change (push the button, new code replacing the old one)
2) copy my jsf pages (.xhtml) to glassfish on save
1) works most of the time; it sometimes doesn't after I deploy many times (why?), or if Netbeans decides for whatever reason that it should deploy the whole thing (it does... sometimes) 2) works in some project, not in others
Seems like black magic.
How is it supposed to work? I can't seem to have 1) and 2) working on the same time for all my projects. How should I configure that? I must have done something wrong, I just need to know what the checklist is.
I opened this some time ago: https://netbeans.org/bugzilla/show_bug.cgi?id=218806
UPDATE: this is a maven project
回答1:
This update from the Jira issue should clarify it:
At the moment there are two important features: --> Compile on Save (will be referred as CoS) which basically means that your java files are compiled immediately when you save them (typically to the target/classes).
--> Deploy on Save (will be referred as DoS) is supplementary feature that enables you to deploy your .class file changes to the server immediately when you save them.
So currently you have few possibilities:
1) Turn on both (CoS and DoS) --> That means your changed .java files will be compiled on save and redeployed to the server and also your static resources (html, jsp etc.) will be copied to the server after the save.
2) Turn DoS off but let CoS on --> in such case you will loose everything related to "server refresh". Which means you should have actual class files compiled in the target/classes but you won't see any change in the browser
3) Turn both off --> NB let you to take care of build/deployment
--> It doesn't make semantic sense to have DoS activated while CoS is disabled which is why if you disable CoS, NetBeans automatically disables also DoS
How should I configure that?
So the conclusion here is, you are not doing anything wrong and you can't configure it that way.. NetBeans just don't support such possibility yet. BUT the good thing is I'm currently starting to work on issue 218345 which is exactly what you need. There will be a new check box (already available in Ant Web project) named "Copy static resources on save" that allows you to copy your html/jsp/jsf pages while having DoS disabled.
回答2:
I experienced exactly the same behavior. No problems with Ant but hot deployment with maven does not work properly. So far what you just wrote.
The answer was to switch to Eclipse >= 4. You can convert your NetBeans project in a console using maven:
mvn eclipse:eclipse
All you then need is an adapter for your app server e.g. for GlassFish. Try it, it's worth a try.
来源:https://stackoverflow.com/questions/18451517/netbeans-deploy-on-save-how-is-it-supposed-to-work