Building java from MSBuild
We are using MSBuild to run our build which compiles and outputs a number of .NET projects/assemblies. Now we are faced with the need to also include a jav开发者_运维技巧a version of on of our assemblies and are unsure how we should go about integrating the building of this java source into MSBuild.
There is always the option to shell out to a command prompt and have it perform the compilation and jar'ing manually, but are there any other and more elegant ways to go about consuming java building in MSBuild?
The Exec task is the perfect thing. Easy, works. Not sure if that's what you mean by "Shell out".
I'm using Microsoft's Team Foundation Server Build Extensions Power Tool December 2011
It has an Ant task for MSBuild.
The documentation seems scarce but it's derived from Teamprise Build Extensions which has a nice pdf manual.
@tsu1980's post has a nice MSBuild code sample.
Creating your own msbuild task to compile java is possible (I have made one to compile VB6 code with MSBuild), but if it is a good idea is another question.. (YAGNI and all that)
If shelling out to the command line does work it may just be an OK thing to do.
My gut is saying shell out to an Ant process since Ant knows a little bit more about Java.
I'd write custom task to call 'Ant' from MSBuild.
https://github.com/sumi2/AntTask
You can call Ant script like following
<PropertyGroup>
<JavaHome>$(MSBuildProjectDirectory)\build\tools\jdk1.6.0_25</JavaHome>
<AntHome>$(MSBuildProjectDirectory)\build\tools\apache-ant-1.8.2</AntHome>
</PropertyGroup>
<!-- Call Ant with 'jar' target. -->
<Ant
BuildFile="$(MSBuildProjectDirectory)\YourJavaProject\build.xml"
Target="jar"
AntHome="$(AntHome)"
JavaHome="$(JavaHome)"
/>
精彩评论