I always have to rebuild my project before running it - java

My project won't compile itself (says all files are up to date) even if I change my code.
My only solution is to rebuild every single time.
Does it have something to do with the fact that my project files are stored on a network drive at my work?

Try copying project files on your local machine and see if it works as required; also double check preferences -> Build, Execution and Deployment -> Compiler -> Make project automatically: if I recall correctly it is disabled by default.

Go to Run/Debug Configuration by combo box of in tools bar.
Then click on your project name and in bottom of Configuration tab exist a text area with Before lunch: Make, Activate tool window. click on + button and select Make option.
This means is before any lunch your project , intellij compile aging your all classes and make resources.

Related

Eclipse: import Java compiler preferences only for project

I have altered the Java compiler settings in my workspace, exported these settings as epf file and resetted the compiler settings workspace wide back to its default. Because I want these settings only in 2 projects in my workspace.
Now, how can I achieve this, importing the epf file for only one project? I am aware of the „enable project specific settings“ option and enabled it and right clicked on the project, imported the epf file but nothing happened. Neither did it change the compiler settings for the project nor for the whole workspace.
If I import it via file menu it works for the whole workspace. I want to share it with a colleague and not go through each option step by step (there are just too many) and using these settings for the whole workspace is insufficient because it then generates about 2000 errors.
I guess it is possible since it has an extra import settings option when right clicking on a project.

How do I know eclipse has already build complete my project (disabled auto build)?

I have disabled eclipse auto build, So I always manually build my project.
but, it always run silence after the build process if there is no error. that is NO message shows in console.
I have used visual studio c++ for many years. the compiler always show the compiling process to console, that is:
compiling xxxxx.cpp file...
compiling xxxxx.cpp flie complete.
build done.
How can I know that the build is complete ?
In your source code dir there should be a classes folder. I'm a fan of the Details view on windows and there I can see the timestamp for when I did the previous build
In your statusbar in the bottom right corner of the eclipse window all running tasks are shown.
If you don't have any pending tasks, this corner is empty. While the compiler work, you see the current task there.
Open Navigator view and check whether output folder(in my case it is bin) is empty or not. If it is empty then project was cleaned and/or not built yet. If non empty then project was built already BUT latest changes to the source code after build was done were not took effect.
If Project > Build Automatically option was disabled then it is your responsibility to build single/all projects(Wherever the changes were made) before you start debugging or running the project in eclipse.
I always make this option enabled. Build will take less time in my case even tough I have many projects in my workspace as eclipse uses incremental build type.
Note that:
You can check whether the current build is in progress or not by looking at the bottom right corner status bar as said by #Marcinek. If it has some message like Building XXX then the build is in progress wait till it completes.
You can check the output folder of your project by right clicking on the project and selecting Properties option. Check the build path configuration here.
If source folder modified time stamp is more than that of output folder time stamp then it indicates that you have to build the project for new changes to take effect.
See below pic

Is there any option to build a single java file in the project

I am doing my project in struts2 and hibernate. My project is little bit long and my problem is when done a small change in java file i have to clean and built the entire project and it is taking very long time to run the project. Is there any option to create the java class for the files that i have changed only, i am using netbeans editor as editor.
There is an option called compile on save in the project properties.The modified classes are automatically compiled by netbeans.
By default Netbeans is going to use its compile on save mode, as mentioned in this other answer. Everytime you modify and save a file, it automatically tries to compile it (as well as required dependencies if any).
While this mode is active, you have no per-file control on compilation and very little control over project compilation either. Your only option is Run -> Clean & Build which deletes any auto-compiled class, compiles everything again and builds a JAR out of your project.
As such, to control single-file compilation, you first need to uncheck the Compile on Save option in the Build/Compiling section of your project properties (right click on project in Projects tab, click on Properties). Once done, you get a new option in the Run menu: Compile File (associated to F9 by default). Of course, it also means you will now need to manually launch builds through the Run menu whenever it is necessary.
You could also use "Debug / Apply Code changes" as long as your class-structure is not modified.
Just right click the file in project explorer, and choose Run File
mac OSX: shift + F6 + (fn)

Purpose of the "Build Automatically" option in eclipse

What is the purpose of Build Automatically option in Eclipse (Project-->Build Automatically)? Mine will always be checked. But when ever I have some java code changes I still have to do a full build. I was told that it should always be checked. I don't see any benefit in doing so. Please somebody explain.
Eclipse has a good answer on their website:
You have two modes of working: auto-build mode and manual build mode. By default, you are in auto-build mode and Eclipse takes care of compiling source files automatically. Builds occur automatically in the background every time you change files in the workspace (for example saving an editor). Auto-build is convenient because it means problems view, binaries, etc. are are up-to-date at all times. The downside is that in large workspaces auto-builds can be time-consuming if you are changing files in projects with lots of downstream dependent projects.
If auto-build is taking too long and is interfering with ongoing development, it can be turned off. Once in manual build mode, the user is in complete control over when builds occur and what gets built. Project > Build All (Ctrl+B) can be invoked at any time to trigger what auto-build was doing automatically. This allows you to build up a larger set of changes before invoking a build (Eclipse remembers which files have changed so that it does not have to do more work than required when you do ask for a build.
Note that when they say "auto-build mode" they mean if you have checked "Build Automatically", when they say "manual build mode" they mean you do not have "Build Automatically" checked.
Yes, you still have to do a build - but it's done automatically when you save (not an external build like an Ant build, but the "internal" build). If you didn't want to build on save, you'd uncheck the box. Having it build automatically makes some people nervous, I believe.
NOTE
For C/C++ users it's told (from help.eclipse.org):
By default, the Eclipse workbench is configured to build projects automatically. However, for C/C++ development you should disable this option, otherwise your entire project will be rebuilt whenever, for example, you save a change to your makefile or source files. Click Project > Build Automatically and ensure there is no checkmark beside the Build Automatically menu item.
Project - Disable Autobuild option does not always mean autobuild is off. For example "Makegood" test automation plugin will trigger autobuild when Preferences - Run/Debug - launching - (General opt) Build before launch is ON. So turn it off if manual build needed.
One thing that people didn't mention here (and it took a while for me to figure this out too) is that eclipse build (either automatic or manual) would basically follow what you have outlined in the project's "Java Build Path" source tab. So when a file is covered in that build source tab, when you change the file, it gets copied/compiled to the output folder that was specified for that directory/file.
One more difference is:
Most of the time while working on JSPs it helps me when checking "Build Automatically". It automatically picks up the changes in JSPs.
But if you make changes in your java classes/XMLs you need a manual build.
Since I'm using resin server which is run outside eclipse via command prompt, i prefer checking the option.
When i have my server setup in eclipse, i turn it off and use Publish on server.
This is the way i use and the answer is based on my experience.
If Build Automatically is checked, the IDE will automatically compile your Java code whenever you modify and save a file. This does not mean it will completely build and package your entire solution as if you were going to deploy it such as if you are working in a Web project on a WAR module. It basically really just compiles your code.

Eclipse shows errors but I can't find them

I am trying to run my project, but Eclipse is saying I have errors. But there are no errors, just a red cross where the project name is. I have tried deleting the R.java and generating a new one, but that didn't work.
Take a look at
Window → Show View → Problems
or
Window → Show View → Error Log
Based on the error you showed ('footballforum' is missing required Java project: 'ApiDemos'), I would check your build path. Right-click the footballforum project and choose Build Path > Configure Build Path. Make sure ApiDemos is on the projects tab of the build path options.
This happens from time to time in Eclipse. In the "Project" menu there's a "Clean" option, that usually takes care of the problem.
Go to project>clean and select the project which display error from check box and click ok , it will clear the error for you.
Click the tab which display build automatically in the project menu
And if this also does not work than restart the eclipse and try again it will work.
For me, this happens with Maven and Eclipse/STS whenever I update my IDE or import an existing Maven project. Go to the "Problems tab" (Window -> Show View -> Problems) and see what it says. Recently, the problems tab showed Project configuration is not up-to-date ... and suggested that I use Maven to update my project configuration, and this solved the "red X" problem. To do this, in the "Project Explorer" view, trigger the context menu and select Maven -> Update Project, as seen in this screenshot:
If you see the error in problem panel it will say : Description Resource Path Location Type
Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the project context menu or use Quick Fix.
Solution : Right click on project > select : Maven->Update Project
Error gone.
Right Click on Project -> Build Path -> Configure Build Path. Check if Maven Dependencies is there in list, if not then update maven project by
Right Click on Project -> Maven -> Update Project
I had a red X on a folder, but not on any of the files inside it. The only thing that fixed it was clicking and dragging some of the files from the problem folder into another folder, and then performing Maven -> Update Project. I could then drag the files back without the red X returning.
Ensure you have Project | Build Automatically flagged. I ran into this issue too and turning that on fixed the problem.
I just removed all the private libraries in JavaBuildPath and added the jars again.. It worked
I came across the same issue while working on a selenium project(maven). The Project folder and pom.xml were showing red cross symbol. This was coming as i had the test datasheet open. I could remove the error by just closing the datasheet and the never faced the issue again
In my Spring Boot application, I right-clicked on my Application class -> run as -> Java Application -> Proceed(All errors will be cleared)

Categories