Should I turn off "Build Automatically" in Eclipse - java

Even I disabled the "Build Automatically", the realtime syntax checking still works, so seems the "Build Automatically" is useless?
Should I just turn it off?

Build automatically helps you know if there are any compile errors.
Its always a good practice to keep build automatically on as to ensure that you dont checkin any code that causes compile issues

Syntax checking isn't the same as building.

Do you really want to wait for the compilation cycle whenever you want to run your program after small changes? "Automatic build" does this compilation in the background and therefore saves your precious time when launching the application.

If you use maven and you edit some classes during mvn build and autobuild is on, it can break build and leave it in unexpected state (doesn't have to end with error). But i still have it turned on, just not changing code while mvn building.

It is a 'nice to have' feature because it gives you compile errors real-time. People also hate it because they complain it distracts them while they are typing out a lot of code and half way through typing the screen is filled with a bunch of red lines.
But this nice feature comes at the cost of your CPU. If I am on a slower machine or if I have other processes running that are CPU intensive then I turn off the auto-build feature. At that point you have to manually hit the shortcut key to build your code. Honestly you just get used to hitting the shortcut without even thinking after a while.

Related

What happens when i start an ant build and keep coding, are my changes (after running ant build) neglect or not?

I'm using Intellij IDEA, working on a Hybris project. We use ant for build, but the build takes too long (about 15 min), so when i start the build, I must stop coding, so i lose a lot of time.
My question is, can I keep coding while the build is running? Or will my uncomplete extra code make the build fail?
Thank you
can I keep coding while the build is running?
No, you should not change the code while the build is going on. Yes, you can keep changes unsaved :)
will my uncomplete extra code make the build fail?
Yes, it might.
I lose a lot of time.
Use code hot-swapping tools, like Jrebel(Licenced), DCEVM(opensource).
It is simply not possible to edit while building. You might end up with an inconsistent build. If you want to speed up development, try to set up something like jRebel.
you can just separate editing from building process by build on another computer device or try CI while you are using any CVS like GitLab, GitHub.

Can you make maven build until you get a successful build?

Sometimes, I want to be away from keyboard for a while and before I go away I start my maven build, hoping that I can come back to see that the build has been successful.
But sometimes I come back and it says "build failed" then I build my project again and get "build successful", there are various reasons for this, maybe your antivirus was running and blocking access to a certain folder at the time of build or something like that.
Is it possible to make maven retry build command until you get "build successful"?
You can write your own script to launch the command for the build process but there are some considerations to do before doing it:
Does it makes sense to expect that a failed build may succed without a code modification?
How frequent the retry should be? If it is too much than you can potentially cause problems on the machine that you are running the script.
If you expect that 1) is possible than for 2) you can implement a non linear pollicy; for instance you can use exponential retry; similar to the policy done in Spring for the annotation #Retryable.

Performance measuring

I wanted to know if there is a way to measure the overhead of a specific function or even the running time of an application in Eclipse (with the capability to run the test for arbitrary times to get the average time).
I have a code that should be executed in Eclipse therefore looking for such a thing. I know that we have Jmeter in Netbeans and I'm looking for something similar in Eclipse.
Thanks
I have had good experiences with JProfiler. It should be precise enough to give usable data even when you run your function only once, depending on how you set it up. It also optionally integrates with Eclipse.
It's not free, but there's a fully functioning trial available.
I used Traceview before and it worked quite good to me.
It quite easy to use, just open the DDMS view in eclipse and look for the icon with three arrows with a red dot (Start Method Profiling). Click the icon and test your app as you want. When you are done click on stop. The trace should open in a new tab.
You could use the following
http://www.jvmmonitor.org/
It's called Java Monitor and comes as an eclipse plugin. You can install it from eclipse market place.

To find an execution line-counter for Java IDE

Is there any plugin to some IDE that show the number of times a line is run in the code?
Eclipse's ECLemma does not seem to have a setting to show execution times at the left-hand-side bar, like in the service WebCat.
I think the eclipse test and performance tools plateform would be able to help you with this. It includes a profiler which will instrument your code and provide the information you want.
Careful with profiling, it can be a heavy performance hit depending on how many functions/classes you monitor
Have a look at the breakpoint properties in eclipse may be you can configure a variable to capture the hitcount
What's wrong with writing to a log file or to screen or using a counter?
The focus of code coverage is only if a line is executed or not. Nothing more.
To get counters you would have to look at profiler software and not code coverage.
There are plugins for both Eclipse and Netbeans. I am not sure if they show counters per line, but I think that they show counters per method, which might be what you want...
(source: free.fr)
In NetBeans 6.8 there is a nice code coverage tool which does pretty much that what you want but actually only for ruby. (right click project -> code coverage)
But could you use an ant task or maven plugin? Then Take a look at this list

Infinite loop at compile time?

Is it possible to enter an infinite loop at compile time?
My program seems to enter an infinite loop when I attempt to compile it. I have a class with a class constructor that calls the method gameRun(). gameRun() calls itself at the end of its execution, but should have the appropriate checks to be able to break from it during run time... However when I attempt to compile the class, I actually seem to get an infinite loop then.
My understanding of compilation is that it does not actually execute the code... Which would mean it would be impossible to enter an infinite loop unless there is actually a serious bug in the compiler's source. Is this correct?
I am writing in Java, and am using BlueJ (a beginner's IDE which I am growing out of) as my IDE.
Thanks in advance.
.....................................
Thanks to you all for so many helpful responses. Just thought I'd post an update, as this seems to have perked some interest, and I am curious about it myself.
I have not done a whole lot with BlueJ or this error since I posted the original error, becuase I had taken the source files from the project, and was able to successfully compile and run them with eclipse. This suggests to me that it is a BlueJ (or related) problem. I have continued to work on this project with eclipse without any more problems of this nature. I will follow up with more detail on the problem when I am able to use the machine with the original project on it again. (Nothing should have been changed since)
.....................................
As an afterthought... Is there any way I can link this question to an account I have created and registered since this was posted? I can't find a way to do that, and it would make keeping track of this more convenient...
Some languages do allow the compiler to enter an infinite loop. Java isn't one of those languages. :-)
You're right, the compiler doesn't execute the code, and would only enter an infinite loop due to a bug. I'm confident that the javac compiler from Sun doesn't have such a bug.
I don't know what compiler BlueJ is using "under the covers", but I have seen a problem when Ant runs javac that makes it take a really long time to compile. Simply stated, there are some cases where Ant will direct the compiler to load every class under a given directory. If that directory contains hundreds of third-party libraries, it can take a while… or even run out of memory.
Does your compilation hang (loop) if you just use javac ?
I've never seen a compilation hang indefinitely whilst compiling Java and I'm wondering if BlueJ is having a problem instead.
It would be theoretically possible to do if, for example, to compile a file, the compiler first had to have finished compiling that file. (Ahhh... Recursion).
But I'd imagine checking for that kind of madness would be the first thing a real-world compiler would handle.
But I wouldn't think it would happen on a method/function, unless (postulating) the compiler was trying to resolve tail-recursion to an simpler implementation, and failing. But, again I can't imagine that would be an issue with a modern Java compiler, even if it exists at all. Certainly I'd imagine that the compiler would eventually give up and post an error rather than infinite looping.
It's far more likely to be the IDE than the compiler. At a guess, the IDE might be trying to trace a warning/error to its source in the code in order to highlight it and getting trapped. Does BlueJ have text-highlighting on compiler errors/warnings? You could try turning it off.
Although, as many others have already suggested, the first real test is to compile from the command line using
javac *.java
Or whatever files your code uses.
EDIT: Sorry I never got back to you. For future reference, to compile from the command line (I'm assuming Windows as your OS):
Open the command line by going to the start menu and select Run...
Type cmd into the Run dialogue, and click OK.
This should bring up a cmd.exe console.
From here, use the "cd" command to change directory to the directory containing your java files.
(cd "My Documents\Java\Monster Battle\core")
Once you're in the right directory, type "javac *.java". This will run the compiler without needing to deal with the IDE. It should pause while compiling, and when it's done, you get the command prompt back.
If you type "javac *.java -verbose" you get full output, in case you get your infinite loop.
If that works fine, it's an IDE bug. Send them a bug report. If it doesn't, congratulations! You've found something really interesting, that will probably tie up some poor Sun developer for a month.
If BlueJ does use its own compiler, you may have found a bug in it, or in BlueJ's build tools that surround it.
You might take a BinaryChop approach to this one: break your program into pieces, compile them individually, and see if the compiler-hanging behavior can be isolated to a small, specific testcase. At the end of the day, you'll either have an excellent bug report to show the BlueJ people, or you'll find that your program actually does compile (yet you'll be scratching your head).
AFAIK, Standard Java cannot be compiled infinitely.
Are you sure that the problem is at compilation rather than at some other feature that BlueJ provides? Many Eclipse-based IDEs perform multiple actions during a rebuild, and that compilation is just one of them. It is possible that something else does.
What exactly do you see? An unending Eclipse task?
Try to make the source code you are compiling as small as possible and still exhibit the behaviour you describe. The process of doing so, may help you identify what the problem is.

Categories