Is it a waste of time to use "Build Automatically" option for Java projects in Eclipse? - eclipse

I'm developing J2EE webapps in Eclipse (RAD, actually). I've always used the "Project > Build automatically" option. However, I noticed that this isn't always necessary because Eclipse seems to push out changes to my server when I save a file. This works great but I'm wondering why this would be checked by default.
I can think of a few times when it makes sense to fully build and deploy the app:
After changing a XML configuation file that gets loaded at app startup (application.xml, web.xml, bean configuration xml files, etc)
After changing a static variable on a class
Other than this, I can't think of other times when it would be crucial (or useful) to enable the build automatically option. Am I incorrect in my above assumptions? Am I just wasting a bunch of time by building automatically??

The automatic build compiles in the first-place. You can disable the automatic publishing (see screen) if you double-click on the server in the server-view. The automatic publishing has nothing to do with automatic build.

Related

Parallel execution of "Building" and "Load Target Platform"

I am working with a huge workspace (~1200 bundles/fragments) and a target platform (file) with about ~800 additional bundles. Settting up this workspace (switch branch, change target platform, etc.) and make it "green" takes a lot of time (20min-2hrs). During setting up this workspace I realized that some of the Eclipse internal tasks such as "Building" and "Loading Target PLatform" are executed in parallel.
But this doesn't make much sense to me, because I assume you cannot successfully build the workspace unless all required plug-in dependencies are resolved. This implies loading the target platform should be done in prior to building the actual workspace. The result is, that once "Building" and "Load TP" is finished, the workspace is a mess with >100000 errors and it requires some hardcore "Eclipse Dance"[tm] to make it "green".
My question is:
Could some sort of exclusion between those task solve this problem?
Is there a way to specify some sort of rules between those tasks from within the Eclipse IDE itself?
In case its only possible by manipulating the underlying Eclipse.org java classes, which one would that be and what would be a recommended way to do so?
The parallel building of projects can be enable in the preferences in General > Workspace > Build by setting Max simultaneous project builds to 2 or higher.
Please note that such slow building of projects as you describe is probably caused by something else:
Make sure your Eclipse (the platform and all plugins) is up to date. According to the screenshot, your Eclipse seems pretty old, so you will miss the numerous performance improvements that have been made in recent versions. For example, since EGit 5.6 only files actually modified instead of all files are refreshed when switching to a different branch.
Make sure it is not caused by a plugin you have installed. Some plugins can dramatically slow down building of projects, even when not used. So check it, whether you can reproduce it with an Eclipse without additional plugin.
Avoid circular dependencies since they can cause multiple build iteration (a project that has been changed triggers a build in the projects that depend on the project; which can result in a change that in turn can trigger the building of more projects; and so on): in Project > Properties: Java Compiler > Build set Circular dependencies to Error (which is the default).
Avoid project builder cycles. A project can have multiple builders (see Project > Properties: Builders). All builders will be executed until no file is changed. Touching a file without changing its contents is also a change. For Maven project, you can use the Maven Workspace Build view to debug this.
For large projects I disable "Build automatically" in the "Project" menu before updating from source code repository and building it with Gradle/Maven. After Gradle finished I enable "Build automatically" back.

Eclipse project build takes a long time

I'm working with a decent sized application (300-350MBs) in my Eclipse IDE. All is well, but when I modify a source file (i.e. MyServlet.java), I can't see any changes until I clean the project, which in turn runs a project build. Due to the size of my project, this build takes about 3-5 minutes.
I guess what I'm asking is if there's a faster way to update changes made to my source files, so that whenever I need to debug, I don't have to wait 5 minutes for every minor change.
What I've tried so far:
Restarting the server
Refreshing the project
Restarting Eclipse
Committing to the SVN
Clearing my browser cache
There is a dedicated tool for that: JRebel. Problem is that you need a licence.
But what you really need to do is to recompile changed class. In your case if this is a Servlet you also need to deploy it to server (+some servers support 'hot-deploy' and some don't, I.e. do you have to restart the server)

Is it possible to apply changes to JSF files without republishing?

I'm using IBM RAD version 8.0 and deploying the EAR applications to IBM WebSphere 7.0. Each time I change a JSF file, I need to republish the application, otherwise the changes are not visible.
Publishing takes some time, so usually it takes minimum a minute before I'm able to see the efects of even the most minor change. In 'normal' application development it's about a few seconds, and it's crucial for someone who is no JSF coryphee and still learns and needs to experiment...
Is it possible to use the JSF ability to re-load the JSF page definition without application restarting, when working with IBM RAD and WebSphere? Or I'll be forced to create second environment with Eclipse & Tomcat, for JSF experiments only?
This is normally to be configured in server configuration. Doubleclick the desired server in Eclipse's Servers view and head to Publishing section.
Note that you should take Facelet cache into account as well, particularly when using MyFaces which caches relatively agressively. If you make sure that javax.faces.PROJECT_STAGE context parameter is set to Development, then both MyFaces and Mojarra will relax the Facelet caching strategy, causing it to recompile the Facelet file almost instantly instead of using the cached version for a rather long time.
An alternative to Publishing setting is to use JRebel. It is able to publish changes in Java classes such as managed beans and EJBs as well, saving a lot of hotdeployment time. It has an Eclipse plugin as well.
This thread is old, but I still had the same problem, using eclipse and WebSphere.
One place to check is this. If you use JSF files with the .xhtml ending, you have to make sure that changes in these do not trigger automatic republishing.
In the tab "Servers" double-click on your server.
Open the "Publishing settings for WebSphere Application Server"
Click on "Set Advanced Publishing Settings...".
In the "List of file extensions that do not trigger the server to publish ..." insert or append ", *.xhtml".
Close these settings and restart the server.
In web.xml I have also added a parameter with the name javax.faces.PROJECT_STAGE and the value Development , which may have an influence on the offending behavior.

Getting Eclipse to automatically reload the JSP pages in my Java web application

I was given a template of a Struts project to work on, and I noticed that when I run the web project on integrated Tomcat in Eclipse and make changes to the .jsp viewpages, they don't automatically reload after a few seconds - which does happen in other projects I made myself.
So I figured this was a configuration issue and I did some research, I had a look at my Tomcat server settings:
(x) Automatically publish when resources change (1 second interval)
But because my own projects reload and I use the same server for them, I figured it must be an application specific issue.
So I looked at context.xml to see if there was anything to change here
<Context
...
reloadable="true"
...
>
Which I can only assume tells the server to indeed reload the application on changes.
So I really can't figure it out. It seems to me like everything is in order here. What am I missing?
From Apache Tomcat documentation about the Context attributes:
reloadable
Set to true if you want Catalina to monitor classes in
/WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically
reload the web application if a change is detected. This feature is
very useful during application development, but it requires
significant runtime overhead and is not recommended for use on
deployed production applications. That's why the default setting for
this attribute is false. You can use the Manager web application,
however, to trigger reloads of deployed applications on demand.
Also maybe this will be interesting for you: Using Tomcat Reload Features To Speed Up Development
I ran into the same problem, with a Java/Spring project that I imported via its Maven .pom files into Eclipse.
I found that I had to run the project with "Debug" instead of "Run" - only then, changes to my .jsp files were noticed, so that a reload of the web page would show the changes almost instantly.

Can I update the HTML files using Wicket and Eclipse without recompiling the classes?

I'm using Eclipse and Maven-2 and I'd like to be able to edit my HTML files without "it" (not sure if it's Eclipse or Maven) recompiling my application. I understand that usually Eclipse tries to do a hot replace of new compiled Java classes with Eclipse and Tomcat.
Can I use something like this?
getResourceSettings().setResourcePollFrequency(null);
I know I can turn auto update off for Tomcat in Eclipse but I'd like the HTML file to update and the classes not to update if possible.
BTW, my primary concern is that Tomcat tends to get Perm gen errors after I (hot) reload too many java classes.
You're sort of correct, you're supposed to use setResourcePollFrequency(Duration.ONE_SECOND); or similar. This link has more detailed information. However what I've found is that due to Wicket's caching internal cache containers like to get really messed up after any hotswapping so you may just have to learn the hotkey for restarting Tomcat or start doing Wicket development with the integrated Jetty and WicketTester.
You may want to consider increasing the permgen space when you run eclipse. There is a command line argument:
eclipse [normal arguments] -vmargs -XX:PermSize=64M -XX:MaxPermSize=128M
(copied from:)
http://wiki.eclipse.org/FAQ_How_do_I_increase_the_permgen_size_available_to_Eclipse%3F
I am not sure offhand how to prevent wicket from reloading HTML files but I will see if I can find it.
Edit:
If setting the poll frequency to null doesn't work, try using Duration.MAXIMUM. Also, you can uncheck "Build Automatically" in the eclipse Project menu, though this is more of a hassle then it's worth, IMHO.
According to the wicket FAQ, wicket only reloads changed markup files when you explicitly set the resource poll frequency:
http://www.wicketframework.org/faqs.html
I am not sure how to prevent eclipse from copying altered files to the output aside from disabling build automatically.
If Build Automatically is enabled (it is by default: Project->Build Automatically) then any modification to the project files will trigger the build, regardless of whether they are in source folders or not.
I always work with Build Automatically disabled as I find it too intrusive (for reasons like this), and just hit ctrl-B when I want the project to build, or alt-P N to launch the clean dialog if needed.
I understand you're using (and might want to keep using) Tomcat, but during Wicket development you can run the supplied Jetty server onder /src/test/java/com/your/package/Start.java in debug mode to get this behaviour.. Set Wicket to development mode to use this feature.
HTML files or jsp files?
Are you using tomcat? If you are editing only html files, go ahead and change them as you wish. As long as you don't deploy them somewhere else for tomcat to fetch them, you'll see the update(s).
If it's jsp, save your new file, delete the files under the old work folder. This will make tomcat think it's the first time the file is requested and it will re-compile the jsp on the fly.