Build Eclipse project automatically in a batch process - java

My project needs periodic source downloading from a shared drive. That is in the form of a zip file. After extracting them, I need to checkout some sources from SVN as well. But time shouldn't be spent during office hours for that. Hence a bat file is created which does all these including zip downloading, extraction, SVN checkout, compilation and opening eclipse.
In the process of compilation, I get the following error
unable to access jarfile /plugins/org.eclipse.equinox.launcher_1.3.0
But this is bypassed and eclipse is opened without the option "Build Automatically" checked. Because of this the workspace doesn't get compiled and hence need to spend sometime for building the workspace.
Any idea to set the Build Automatically true without manual intervention?
Otherwise it would be appreciated if the source files could be compiled without the above said error.
Thank you

You should probably not use Eclipse to build your project in a batch process. First, you run in the type of problem you are describing, but you also have the problem of the additional overhead of running eclipse, and this make your build system very platform-dependent.
A cleaner solution would be to call javac from your batch process. See the doc here. Also a useful post here.
An even better solution would be to implement your build script in Ant, instead of batch. Ant is supported by Eclipse, but can be run independently on any platform. It supports doing everything you describe in your build process:
Downloading: Get task
Extracting: Unzip task
SVN checkout: SVNAnt
Compiling: Javac task
Jar: Jar task
etc...

Related

Run Maven Project (with ant) in a single go using Remote Debug Configuration of IntelliJ

I have a Maven Project, Ant Project which are somehow coupled. If I have to make any change in maven project and test it I have to do following steps every time, which is very time consuming.
Steps
ant stopserver
mvn install
ant startserver
Access it on localhost:8080
And to debug anything I have to create a Remote Debug Configuration which connects to port 8000 and start ant server in debug mode.
All this is new to me as I have only worked on microservices based out of maven when there is a #SpringApplication class with main method which I could directly run/debug. In this project, there is no class with main method. It's a legacy spring mvc project.
I seriously want some way to do the same with current project. I tried going though the build.xml but ant steps are hardly taken less than a second.
Is there a way possible? Can it run like a normal maven project? Ant is probably building some db and ui parts (not very sure). But I only work on Java side.
Please help. Anything that could get rid of me having to run mvn install with every small change would also be helpful. To reduce the time taken by mvn install I used the script from this answer here and added that as well, as one of the before launch steps but the time taken is still the same.
I have tried following post but it did not work for me How to build maven project with ant script?
Open the lid and find out what exactly ant startserver does, and then create a launch configuration in your IDE that does the same thing. You might be able to cheat a bit and investigate the process in the operating system using its tools to get the invocation commandline.
Then run that launch configuration in the Debugger and tell your IDE to tell the JVM to hotswap newly compiled classes.
You should now have a much improved experience.
You may want to take the opportunity to teach Maven how to launch your server as that might enable the IDE to pick this up directly.
I was able to achieve at least one click start by Adding ant targets as part of the "Before Launch" inside "Run/Debug Configurations". To reduce the time taken by mvn install I used the script from this answer here and added that as well, as one of the before launch steps.
By enabling Logs, this also became user friendly.
Here is how my config looks like now,
However, I still have to do maven install.

Generating executable file in IntelliJ for Windows

I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.
It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.
I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.
Am I missing some setting for building the project? I am using IntelliJ 2018.3.2
Here are some screenshots:
I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.
There was a log message which helped fixing this:
The process complained about the Inno Setup Compiler missing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.
Detected [iscc.exe] version 0.0 but version 5.0 is required.
After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.
Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...
The best solution for this is using exe generator software.
There is plenty of exe generators out there.
EXE4J is the most simple & easy tool to use.
In EXE4J,
You can upload your main jar file and select the main class.
I think this will be solved your problem.
This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one

Checkstyle & Findbugs Install

I have javac version 1.6.0_16 already installed on Windows XP and I'm using both Dr.Java and command prompt to compile and run Java programs.
I downloaded and extracted Checkstyle 5.5 and Findbugs 2.0.1. I'm trying to install Checkstyle and the instructions stated that I need to include checkstyle-5.5-all.jar in the classpath.
My question is, should I place the Checkstyle directory in the lib folder of the jdk1.6.0_16 directory and set the classpath as follows:
C:>set classpath=%C:\Program Files\Java\jdk1.6.0_16\lib\checkstyle-5.5\checkstyle-5.5-all.jar
Is this correct? Should I do the same for Findbugs? Thanks in advance
EDIT: When I added the above path using the environmental variables, and ran checkstyle hello.java, I got the error: 'checkstyle' is not recognized as an internal or external command, operable program or batch file
Maven will solve this problem for you
It sounds like you're just getting started in the world of Java. To that end, I'd suggest that you look into Maven for your build process. Also, you should be using at least JDK1.6.0_33 at the time of writing.
Essentially, Maven will manage the process of running Checkstyle, Findbugs (and you should also consider PMD) via standard plugins against your code. It will also manage the creation of the Javadocs, linked source code and generate a website for your project. Further, Maven promotes a good release process whereby you work against snapshots until ready to share your work to the wider world.
And if I don't use Maven?
Well, just create a /lib folder in your project and stuff your dependencies into it. Over time you will create more and more and these will get intertwined. After a while you will enter JAR Hell and turn to Maven to solve the problem.
We've all been there.

Java on demand build system

I have a vague memory that I've seen a build system for Java or some other JVM lang which you could run in continous mode (so to speak). This would make the build system run in the background, watching the source dir for changes. As soon as a source file changes, the build system kicks in and re-runs relevant parts of the build process to produce a fresh artifact.
Ring any bells?
Thanks
Is it the gradle daemon?
This keeps gradle running in the background because it has long start up times - and scans the file system to identify when files change.
There are lots of engines that support continual checkouts/building/testing (e.g. Jenkins nee Hudson, CruiseControl, TeamCity etc.).
If you're looking at JVM languages other than Java, then (for example) the Maven Scala plugin supports continuous building and testing upon file changes. e.g.
$ mvn scala:cctest
will run the compile/test cycle in a loop watching for source changes and acting upon them.
If your build tool or language doesn't support this natively, it's trivial to write a shell script to watch a directory structure and execute another script/tool upon change. See this SO question for solutions.
I figured out that it was in fact sbt that I meant. There is another question here on SO relating to how to build Java projects: Use SBT to Build Pure Java Project. Thanks everyone for your help.

Ant is not able to delete some files on windows

I have an ant build that makes directories, calls javac and all the regular stuff. The issue I am having is that when I try to do a clean (delete all the stuff that was generated) the delete task reports that is was unable to delete some files. When I try to delete them manually it works just fine. The files are apparently not open by any other process but ant still does not manage to delete them. What can I do?
I encountered this problem once.
It was because the file i tried to delete was a part of a classpath for another task.
It depends ...
The Ant process doesn't have enough permissions to delete the files (typically because they were created by a different user, perhaps a system user). Try running your Ant script as an administrative user, using Run As.
Windows is really bad at cleaning up file locks when processes die or are killed; consequently, Windows thinks the file is locked by a process that died (or was killed). There's nothing you can do in this situation other than reboot.
Get better tools to inspect your system state. I recommend downloading the SysInternals tools and using them instead of the default Windows equivalents.
Using Ant Retry task has helped me.
I've just wrapped it around the Delete Task.
You don't say if your build is run as the currently logged on user. If not, the fact that explorer.exe or other process has the directory shown can cause it to be locked as well. But deleting it in that same explorer.exe process would succeed. Try Unlocker from http://ccollomb.free.fr/unlocker/ to see what processes have the files/directories locked.
Is there something from the Ant process that is holding the files (or directory) open? This would cause the situation where you could delete them after running ant, but not during.
I faced the same problem.
I didn't have any classpath set to or antivirus running on my machine.
However, the ANT version I was using was 32 bit and the JDK I installed was 64 bit.
I installed a 32 bit JDK and the issue was resolved.
Ant versions before 1.8.0 have a bug which leads to random errors during delete operation. Try using Ant 1.8.0 or newer.
You can see the bug details here https://issues.apache.org/bugzilla/show_bug.cgi?id=45960
In my case my ant clean was failing from Eclipse, unable to remove build files. I see this from time to time. Usually succeeds on a repeat attempt. This time no.
Tried running ant clean from command line, failed Unable to delete"unable to delete".
It must have been Eclipse holding on to the problem file, when I exited Eclipse, cmd line was able to delete OK.
I've been having this problem a lot lately and it's random. One time it works, the next time it doesn't work. I'm using NetBeans (in case that matters) and I've added a lot of extra tasks to build.xml. I was having this problem in the -post-jar task. It would happen when I call unjar on the file, then delete. I suspect that NB is trying to scan the jar and this causes the lock on it.
What worked for me is to immediately rename the jar at the start of -post-jar and add a .tmp extension to it. Then I call unjar on the temp file. When I'm done I rename back to the desired jar name.
I too had the same problem and was tried of manually deleting the build directories. Finally I solved it by renaming the .jar artifact of my project to a different name from project name itself. For ex: my project was portal and my ant built script use to generate portal.jar, where eclipse ant was not able to delete this portal.jar. When i changed my build.xml to generate my .jar as portalnew.jar, eclipse was able to delete this portalnew.jar next time. Hope this helps.
You need to delete it manually in Windows. It worked for me. (Usually the files to be deleted are older versions of jar.. For example: if there exists httpcore.4.2.5.ja5r and httpcore.4.3.jar, it will try to delete 4.2.5.jar)
i faced this issue as the file the ant was trying to delete was being used by some other service/process.
I stopped the service, and then the ant build script did run through.
In my case, I stopped running Java process from Task Manager and re-run the Ant build file. The file was able to delete and build was successful.
I am seeing problems like this way too often since I switched to Microsoft Windows 10. Renaming the file immediately before removing it solved it for me:
<rename src="file.name" dest="file.name.old"/>
<delete file="file.name.old" />
For me, I am using mac so I tried sudo before ant cmd, sudo ant clean all and it did work perfectly fine.
As i've read javac will not have access to delete JAR files so you can either sudo it or find alternative.

Categories