2015-07-03 86 views
0

我有一个名为jarPLCExample.xml的ant文件,它需要一些类文件并生成一个jar文件。这个文件的<jar>标签部分在sbt中看起来像什么?将创建jar文件的ant脚本转换为sbt

<project name="jar_myplc" default="jar_myplc" basedir="."> 

<property file="../resources/v2.properties"/> 

<property name="dist.dir" value="C://where_jar_files_go/lib"/> 
<property name="dist.file" value="${dist.dir}/PLC.jar"/> 

<target name="jar_myplc"> 
    <tstamp> 
    <format property="TODAY" pattern="dd/MM/yyyy hh:mm aa" locale="au"/> 
    </tstamp> 
    <delete file="${dist.file}" quiet="true"/> 
    <jar destfile="${dist.file}"> 
    <fileset dir="${v2.out.root}" includes="com/companyname/server/applic/**/*.class"/> 
    <fileset dir="${v2.out.root}" includes="com/companyname/common/utils/SeaDef*.class"/> 
    </jar> 
    <copy file="${dist.file}" todir="C:/deploy"/>   
</target> 

SBT组装没有好这个,因为它似乎可以排除与包括广口瓶,但没有源文件包和源文件名作为需要在这里完成。

对'随流'显然很重要:我期望sbt将要从源代码编译,因此不需要显式使用.class文件作为上面的ant任务。

我已经在基本目录中有一个build.sbt,并且将这个文件称为jarPLCExample.sbt是明智的,但我不知道如何让sbt加载一个特定的文件。因此,我将在一个文件中包含两个项目,并通过更改顺序手动设置当前项目。 (因为他们都有相同的密钥,第二个似乎覆盖第一个--命令将始终只显示一个项目)。

回答

0

这个答案有两个缺点。它仅包含applic目录,而不包括applic以下的所有目录(递归)。无论他们在哪个目录中,它也会接收所有SeaDef*.class

def filter3(file: File, greatGrandParent:String, grandParent:String, parent:String, excludes:List[String]):Boolean = { 
    file.getParentFile.getName == parent && 
    file.getParentFile.getParentFile.getName == grandParent && 
    file.getParentFile.getParentFile.getParentFile.getName == greatGrandParent && 
    !excludes.exists(_ == file.getName)  
} 

/* 
* <fileset dir="${v2.out.root}" includes="com/companyname/server/applic/**/*.class"/> 
* <fileset dir="${v2.out.root}" includes="com/companyname/common/utils/SeaDef*.class"/> 
*/  
lazy val jarPLCExample = project.in(file(".")). 
    settings(commonSettings: _*). 
    settings(
    includeFilter in (Compile, unmanagedSources) := 
     new SimpleFileFilter(file => filter3(file, "companyname", "server", "applic", List())) || 
     new SimpleFileFilter(file => file.getName.startsWith("SeaDef")) 
)