How to (manually) disable Eclipse jdt.ls compilation in Maven/Java projects - java

I currently have a Maven Java 11 project that builds fine. However, I use Eclipse's implementation of the language-server for editing the code within Emacs. This works fine, everything that I really need is available.
However, my question, is how can I disable the Eclipse LSP/compiler from attempting to auto-compile the project? It's not always an issue, but often the JDTLS seems to be recompile everything all the time to the point that when I run Maven, it has to recompile everything again. At best, this is a slowdown in the develop->test cycle. At worst, I have to clean build frequently.
Eclipse has an option in its GUI which "builds automatically". I am curious, is there a text file I can toggle this setting with?

According to the lsp-java documentation, the setting you are looking for is lsp-java-autobuild-enabled.
However, if there is a way to run the tests directly rather than via Maven, it would be faster since Maven does not support incremental compiling like JDT does (ideally, compiling should be done incrementally on save and not when running the application or a test).

Related

Update Gradle in an existing java servlet jsp project

First a little background. I can go from netbeans 8.0 to 12 and open an existing older project that was built with netbeans native builder (pretty sure it's ant), do a clean and build, and the project runs perfect with zero problems. You can totally be unaware of build.
Now the problem, gradle. I did my first gradle project, all was good, ran fine. Then a few days later netbeans informed me there was an update to gradle, I updated, restarted the ide, and nothing. The project would not build anymore, etc.
How, and I plea for help here, how do you make it so you can update gradle, and just press on with a clean and build?
Meaning, I want to be unaware that gradle even exist, I should not have to spend time fixing a build tool, I should be able to update, and forget Iā€™m even using it. Any help is appreciated.
Been using netbeans for years, and never encountered such a mess.
Also if it's not possible in netbeans, I'll use eclipse, but I'd like to not even think about the build tool just like in the past. Any hints, tips?
Or after an update to gradle, is there some little thing that needs to be done?
I have used native build for years, mostly netbeans and some in eclipse and never needed to read one word of the ant documentation, it just always works.

Eclipse-project to makefile for ant/maven/gradle/

Today I faced problems in starting eclipse (reinstall etc. did not work). I had to use a vanilla eclipse and with luck it was working.
With that I experienced the problem of an IDE that is not working. That can be a mess if you need a quick bugfix for a hot system.
Is there a tool that takes an eclipse-project and converts it into a makefile for a more basic tool (like ant, maven, gradle, ...) that work from the commandline?
Sure I can make it by hand but because it should be only a safety I would prefere the automatic way and keep the development-work in the IDE.
EDIT:
Or maybe: Is there an build-command that works on the commandline without starting the IDE?
Thanks!
Running "gradle init" from the command line will attempt to create a build.gradle for your project. If your project layout is "conventional" it might do a good job. If it finds anomalies it tends to give up. Constructing a simple Gradle build script for a simple project takes a few minutes once you get used to it. Searching the web with intelligent queries will tend to find lots of examples.
Adding the "Gradle Nature" in Eclipse is simple if the project is buildable from the command line with Gradle.
You can use m2e eclipse plugin to convert your existing projects to maven projects. But you have to do it before hand(while your eclipse is still working)
https://crunchify.com/how-to-convert-existing-java-project-to-maven-in-eclipse/

Creating a program that will run before and after compilation in Eclipse

I am currently working on a small program that should comment out some code used for testing.
I want it to auto run before the compiler while compiling the release version and another program that will comment the code back in after compilation was over.
The program works the only thing I am missing is to add it to the build process.
Thanks to all helpers!
In Eclipse, right-click a project, choose Properties ā†’ Builders and click New. You can add an Ant script or a command line that Eclipse will trigger when building the project. You can also control the order of builders in the same dialog.
However, I agree with JB Nizet ā€“ there are many advantages to having Ant or Maven build your project.
Don't use Eclipse to build the release version of your app. Use Ant, Maven, or any other build tool that is much more flexible than Eclipse, doesn't need a GUI, can be scripted and used by a continuous integration server.
All of these tools should easily be used to include your pre-compilation and post-compilation tasks in the build process.
That said, you could just use a public static final boolean constant FOR_TEST, and include all your testing code in
if (TestUtil.FOR_TEST) {
}
You would then have just a single place to change in the code to have all the test code removed from the compiled version. No need for a complex Java program to do that.
Or you could let all the testing code in the released version, and activate it when testing using a system property, for example. This wouldn't even need any precompilation/postcompilation phase, and would probably have a negligible cost.

Eclipse building the code again and again (without any changes)?

I am noticing a strange issue with Eclipse Indigo. It is Building Workspace again and again even though there is no change in the code!
In Progress bar it prints
Building Workspace 44%
..
Building Workspace 10%
..
Building Workspace 33%
Any idea what is going on here? For the time being I have unchecked the 'Build Automatically' flag.
I have tried the following trick couple of times and this seems to work more often than not:
Uncheck Build Automatically flag
Refresh all the projects in the workspace
Re-enable the automatic build after sometime by checking the Build Automatically flag
Note that as I mentioned earlier this is a trick and not a resolution. But, hope others facing these issues will find this helpful.
Yes, I have noticed that too and it can be rather annoying. I have reverted to manual compiling in Eclipse by switching auto-building off (under project).
Compiling manually is a bit old-school, but it works for me. I prefer to compile, package and test the code at the command line using maven.
(I'll probably get a downvote for this approach (i.e. not using integrated tools, etc.), but it works for me and it works well! At least I'm not using VIM for coding Java! :))
If you are using Windows 7, then the Windows indexing in some directories can cause automatic rebuilds in Eclipse: see Bug 342931 - Windows 7 Libraries trigger rebuilds.

How to see full compile path in Eclipse?

I have looked for an answer for this nearly every where that I can think of, but there doesn't seem to be any way to actually SEE what Eclipse "runs" to compile the projects (as it does need the JDK installed and visible to actually build). I ask because I imported a few jars into my project, and even though I've looked through all the javac documentation, I can't seem to figure out how to mimic it quite like Eclipse does. I really, really need to be able to compile on the command line in this case - Eclipse or any other IDE just isn't what is needed.
I started to look through the Eclipse source, and although this sounds lazy, I just became overwhelmed and figured I would ask here first, hoping someone else had the same question at one point.
Eclipse JDT does not require the JDK and does not use javac - it uses it's own compiler.
You can see the classpath by reading your project .classpath file. The various builders that are used to perform build operations (Java, or whatever the project builds) are listed in the .project file. (These are also listed in the project settings.)
It is possible to invoke Eclipse to build your project in headless mode, or write Ant scripts that can be executed both with the JDK and within Eclipse, or install Maven support for internal and external building. It is also possible to configure the project builders to rely only on external tools.
Look at these two articles.
http://www.eclipse.org/articles/Article-Builders/builders.html
http://www.eclipsepluginsite.com/builders-natures-markers.html
Look at your .classpath file and start building an ANT build.xml. You need to do this to be able to have consistent builds on a build machine anyways. It is unlikely that a build server would have eclipse installed on it anyways.
Maven is also another tool that is used for builds. In our shop we use Ant.
Have a look at ant4eclipse - this project allows for generating the appropriate ant data structures for invoking <javac> from the .classpath files and a projectSet.psf file.
By using this we can use Eclipse "natively" and bend ant to conform to Eclipse. The usual approach is the other way around.

Categories

Resources