maven eclipse automation
I'm using eclipse with maven. After running my configuration, I always do the same tasks (clean th开发者_运维知识库e project, then debug as java app). Is there a way I could add these 2 tasks to the maven configuration ?
Thanks
Maven is great if your work flow fits into the standard.
If that's not the case, your best bet is to add a build.xml
Ant build file to the project which you can use to write "macros" to run repetitive tasks.
Use the exec
task to invoke Maven from Ant.
If you can achieve everything with Maven command line options, another approach is to install the m2eclipse plugin. That allows you to create "launch configurations" which run Maven with the options you want.
The tab "Common" allows you to save the launch config as a file in your project. You can also add it as a favorite to the Run or Debug menu. That way, it always stays in the same spot in the menu which makes it more simple to hit with the mouse or a key combination.
[EDIT] You can't start the debugger from Maven or Ant but you can do the other three steps. Create a Maven launch config (Run... -> Run Configurations ... -> Select Maven -> New (+)") and put clean install android:deploy
in the field Goals
.
That runs all three in sequence. See my other comments above to make this more comfortable.
[EDIT2] You need a macro extension for that. See this question: Is there a Macro Recorder for Eclipse?
Also consider to use two target directories, one for Eclipse and one for Maven. If you run mvn clean
, this always confuses Eclipse which doesn't refresh the files in bin
or target
since no one is supposed to write there but Eclipse itself. See How to configure Maven project to use separate output folders in Eclipse.
Copied the important bits here to avoid broken links:
<project>
...
<build>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>
</build>
<properties>
<target.dir>target</target.dir>
</properties>
<profiles>
<profile>
<id>eclipse-folders</id>
<properties>
<target.dir>target-eclipse</target.dir>
</properties>
</profile>
</profiles>
...
I don't know of any support for Maven for cleaning the Eclipse project or debug.
Eclipse provides some Ant tasks that allow refreshing the workspace, or executing a "clean" build (see http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ant_eclipse_tasks.htm). These Ant tasks may be reused with the AntRunner, but it would be hard, as they are Eclipse-specific, and depend on some Eclipse plug-ins.
Sadly, I don't know of neither Ant task nor Maven option to execute a Run configuration (that is required for debugging)... Simply executing the Java app should be possible, but I'm not sure, that should be part of the build - it is really a different task in my opinion.
This seems to work, not the most optimal solution, You need m2eclipse plugin for this
First step is add maven-ant-run plugin to your pom.xml, If you look at the plugin config, It is set up to execute this plugin after compile phase
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<java classname="main class name">
<classpath>
<pathelement path="${runtime_classpath}"/>
</classpath>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
From eclipse debug menu select Debug Configuration
Maven Build ==> New ==> add clean compile in Goal (click Browse Workspace select workspace)
If yo click Debug, It will bring debug perspective and also takes you first break point in your app. It is not finding the source though, but if you click on edit source look up button and just select workspace it seems be able to let you see the source as u debug.
精彩评论