Pre-Debug script in Eclipse - java

I use Eclipse to code my project and in order to debug\run it I have a "Maven Build" configuration with a goal.
My question is: How can I run a script file that deletes my log files before the debug starts?
Thank you.

You can't do it automatically buy you can use a script or an ant file linked from your external tools menu. So before debugging you would need to run that external tool.
Maybe there is another way. You can delete it from a maven goal if you launch the app with maven. I don't know exactly how. You can launch with maven with the exec plugin. Codehouse site is down (terminated) so I link this tutorial:
http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/
EDIT:
You can delete the files using Apache Maven Clean Plugin:
http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html
You need to make both steps (delete logs and run with both plugins) execute when you build with the same goal and in the right order. I don't know how to do it but I am quite sure it is possible.

Related

IntelliJ does not recompile/build maven project

I am running into problems when using IntelliJ for Spring development. At first, the IntelliJ build command works fine and picks up changes I make to the source code. At some point, this stops working and I can only compile my sources through maven, as the build or rebuild project commands seem to do nothing anymore.
I am confused, as it works as desired at the start but then stops working at some point.
Steps to recreate:
Create a new Spring project using Spring Initializr:
curl https://start.spring.io/starter.zip -d type=maven-project -d javaVersion=11 -o demo.zip && unzip demo.zip
Start IntelliJ from the command line in that folder, this will auto-import the project: idea64 .
Write a log message in the main class and run the project using Run->Run 'DemoApplication'. This compiles the sources to the target folder and starts up the project. You should see the log message
Alter the log message, run again and the changes should be visible (so far so good)
Now re-compile the sources via maven command mvn compile and restart IntelliJ
From now on, running build or rebuild project within IntelliJ will not pick up any changes I make to any of my source files. In fact both commands don't seem to do anything at all. I have to compile via maven in order to properly compile my sources
I tried a few things to overcome this problem, but without success:
Invalidated caches/restart
Checked project settings for Project Compiler Output and set it to <project-folder>/target
Checked project settings/modules for output path and test output path and put in the path as above
Used Reimport All Maven Projects
Deleted the .idea folder within the project folder. This seems to work, but is very inconvenient and surely no intended behavior. Also it breaks again if I recreate the steps detailed above.
Is anyone experiencing similar problems and/or has a solution?
So for anyone running into the problems I described above:
Apparently deleting the .idea folder and restarting IntelliJ does indeed do the trick. The folder is recreated on restart and afterwards I'm able to switch between compiling within IntelliJ using run, build or rebuild project and compiling through maven goals (mvn compile, mvn test, mvn surefire:test, ...). This persists through restarts of IntelliJ such that I don't have to repeat this everytime I open a project.
I still don't know why this behavior happens, but it's a solution I'm happy to work with as long as I only have to do it every now and then for a project.
Sounds like do don't want Intellij's default build. You want Intellij to forward the build command to mvn. I assume this because you do not mention this step in your question.
Here's a screenshot that shows how to enable it:
More detail is available in the Intellij documentation https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#delegate_run_action

Automate generating SVN Tags

I'm working on automating SVN Tag generation through JAVA and need some suggestions to start of with. This is how we do it manually - Check out a maven project/plugin from SVN repo and run a set of maven commands (mvn clean test, mvn release:prepare) to generate SVN tags, mvn release:prepare is the final command that would run unit tests, generate the tag and commit it to SVN and I'm working on automating this process.
I had a look at svnkit api which I can make use of to check out a project to the local file system and find a way to run the set of maven commands to generate tag URL, is there a maven JAVA plugin through which I can trigger maven commands? Or is there a much better way to do this other than JAVA?
I did my research on svn kit but could not find any relevant info to automate the maven process, probably I'm missing out on something.
It seems that you are looking for continuous integration.
I would recommend you to evaluate the use of Jenkins, which can be configured to periodically poll changes from SVN and launch a Maven build. Then, if the build succeeded and you decide to release it, you can perform a Maven release from Jenkins, which would take care of invoking the corresponding Maven goals. You can also configure a post-commit hook in SVN in order to launch a build after each commit.

Creating a Site Using Eclipse Maven Plugin

I would like to create a 'site' containing test reports for my Maven Java project. However, all the online resources that I found were talking about the command 'mvn site'. I do work on Windows, though, therefore I would like to avoid any interaction with its console.
Can I do it using solely the Eclipse Maven Plugin? If I want to tell Maven to build my project, I can right-click it and then choose 'Run As' 'Maven Install'. Is there something similar for generating sites?
Thank you all in advance!
Why the hate for specifically the Windows command prompt? What has it done to you to deserve a cold shoulder?
In any case and more seriously: Eclipse allows you to define run configurations yourself. run -> run configurations. Under "maven build" you can add a new configuration to do a mvn site. This page gives an idea by demonstrating how to do a clean install:
http://books.sonatype.com/m2eclipse-book/reference/running-sect-running-maven-builds.html

delete eclipse project using ant

do somebody know how to delete eclipse project using ant?
I'm using eclipse in silent mode, to run ant build scripts and before build I'd like to delete 2 project which are generated automatically by eclipse. Is there any option? (Something like <eclipse.deleteProject />)
thanks in advance
There's nothing eclipse exposes by default to ant, AFAICT. I'd use ant to delete the folder (as suggested) and then use the eclipse.refreshLocal task on the workspace root. For what eclipse does expose, see Ant tasks provided by the platform.

Eclipse m2eclipse clean, build projects, build automatically commands, what are they?

What is the command that m2eclipse runs when you
highlight a project -> Menu Project -> Clean -> Select anything -> Ok ?
It then goes on to "Building Workspace".
What is the command that allows it to do so?
The reason I am asking is that I am trying to do this from outside Eclipse, from the command line. I am trying to automate all maven stuff in a Groovy script. I am on Windows xp.
EDIT:
Also, the command update maven dependencies would be nice to have as well.
Thanks!
Maven-invocations are put in the Run and Debug menus. Just building the workspace does not run maven - it just does all the work Eclipse needs to do to know your files.
For your purposes these will suffice for the command line build:
cd /to/where/pom.xml/is
mvn clean
mvn install
No commands are directly run. Instead, the m2e plugin uses the configuration in the pom to create equivalent configurations in eclipse.
For example, if you change the source directories it will update the eclipse source directories for the java builder. If you change the target directories for the source compilation, it'll ensure that when you do a Project -> Clean, the plugin knows which directories to clean.
If you are trying to do this though a scripting language, I would recommend just running commands on the command line. The alternative would be to add the maven libraries to the classpath and to use them.

Categories

Resources