我不可能使用maven。在网上搜索没有maven的dropwizard教程,但是没有找到…
有谁知道一个好的教程开始使用ant和ivy代替maven的dropwizard吗?
就像正常的ant构建一样,插入目标:
<target name="compile-server" depends="clean, resolve, echo">
<javac srcdir="${src}" source="1.8" target="1.8" encoding="UTF8" destdir="${bin}" includeantruntime="false" debug="true" debuglevel="lines,vars,source">
<classpath>
<path refid="ivy.path-server" />
</classpath>
</javac>
</target>
<target name="resolve">
<ivy:resolve file="ivy.xml" conf="*" />
<ivy:cachepath pathid="ivy.path-server" conf="server" type="jar,bundle" />
<ivy:cachefileset setid="ivy.libs-server" conf="server" type="jar,bundle" />
<ivy:retrieve conf="server" pattern="${lib.dir}/ivy/[conf]/[artifact](-[classifier]).[ext]"/>
<ivy:cachepath pathid="ivy.path-client" conf="client" type="jar,bundle" />
<ivy:cachefileset setid="ivy.libs-client" conf="client" type="jar,bundle" />
<ivy:retrieve conf="client" pattern="${lib.dir}/ivy/[conf]/[artifact](-[classifier]).[ext]"/>
<ivy:cachepath pathid="ivy.path-test" conf="test, test-meta" type="jar,bundle" />
<ivy:cachefileset setid="ivy.libs-test" conf="test, test-meta" type="jar,bundle" />
<ivy:retrieve conf="test, test-meta" pattern="${lib.dir}/ivy/[conf]/[artifact](-[classifier]).[ext]"/>
</target>
添加/更新到ivy文件:
<configurations>
<conf name="server" description="server runtime dependencies" visibility="public"/>
<conf name="client" description="client runtime dependencies" visibility="public"/>
<conf name="test" description="unit test configuration" visibility="private" extends="server,client" />
<conf name="test-meta" description="sonar and jacoco" visibility="private" extends="test" />
</configurations>
<dependencies>
<dependency org="org.jacoco" name="org.jacoco.ant" rev="0.6.4.201312101107" conf="test-meta->default">
<exclude org="org.apache.ant" module="ant" />
</dependency>
<dependency org="org.codehaus.sonar-plugins" name="sonar-ant-task" rev="2.1" conf="test-meta->default">
<exclude org="org.apache.ant" module="ant" />
</dependency>
<dependency org="junit" name="junit" rev="4.11" conf="test->default"/> <!-- for builds outside of eclipse -->
<dependency org="org.mortbay.jetty" name="servlet-api" rev="3.0.20100224" conf="server->default" />
<dependency org="io.dropwizard" name="dropwizard-core" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-jersey" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-servlets" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-jetty" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-validation" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-configuration" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-jdbi" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-db" rev="0.7.1" conf="server->default"/>
<dependency org="io.dropwizard" name="dropwizard-jackson" rev="0.7.1" conf="server->default"/>
</dependencies>
也许你也有io.dropwizard.jackson的问题。
<!-- Dropwizard Hack for problem https://github.com/dropwizard/dropwizard/issues/455 io.dropwizard.jackson.Discoverable is used by seveal libs and is overwritten each time -->
<property name="dropwizard.hack.name" value="io.dropwizard.jackson.Discoverable" />
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${lib.dir}/ivy/test/ant-contrib.jar"/>
</classpath>
</taskdef>
<!-- Dropwizard Hack for problem https://github.com/dropwizard/dropwizard/issues/455 io.dropwizard.jackson.Discoverable is used by seveal libs and is overwritten each time -->
<target name="mergehack" depends="clean, unjar_mergehack">
<!-- for every filename do another merge -->
<var name="file.destination" value="${bin}/META-INF/services/${dropwizard.hack.name}" />
<delete file="${file.destination}" />
<touch file="${file.destination}" />
<merge tofile="${file.destination}">
<sourcefiles>
<fileset dir="./${tmp}/dropwizard.hack/">
<include name="**/${dropwizard.hack.name}" />
</fileset>
</sourcefiles>
</merge>
<!-- second one ... -->
<!-- copy and change above -->
<!-- third one ... -->
<!-- copy and change above -->
</target>
<!-- = = = = = = = = = = = = = = = = =
macrodef: merge
= = = = = = = = = = = = = = = = = -->
<macrodef name="merge">
<attribute name="tofile">
</attribute>
<element name="sourcefiles">
</element>
<sequential>
<tempfile property="temp.file" prefix="ant.merge." deleteonexit="true">
</tempfile>
<concat destfile="${temp.file}" fixlastline="true">
<sourcefiles>
</sourcefiles>
</concat>
<copy file="${temp.file}" tofile="@{tofile}">
<filterchain>
<tokenfilter>
<linetokenizer>
</linetokenizer>
</tokenfilter>
<sortfilter>
</sortfilter>
<uniqfilter>
</uniqfilter>
</filterchain>
</copy>
</sequential>
</macrodef>
<target name="unjar_mergehack" depends="clean, resolve">
<!-- Needed for counting -->
<var name="op2" value="1"/>
<var name="op" value="+"/>
<var name="opminus" value="+"/>
<var name="result" value="0"/>
<!-- What file should be searched in zipped file -->
<var name="searchfile.name" value="${dropwizard.hack.name}"/>
<for param="filename">
<path>
<fileset dir="${lib.dir}/ivy/server">
<include name="**/*.jar" />
</fileset>
</path>
<sequential>
<math result="result" operand1="${result}" operation="${op}" operand2="${op2}" datatype="int"/>
<!-- <echo>Result = ${result}</echo> -->
<var name="destination" value="./${tmp}/dropwizard.hack/${result}"/>
<echo message="1. Starting to read file: @{filename}" />
<echo message="2. unzip to: ${destination}" />
<unzip src="@{filename}" dest="${destination}">
<patternset>
<include name="**/${searchfile.name}"/>
</patternset>
</unzip>
</sequential>
</for>
<echo message="Ready" />
</target>
它解压缩库,在每个库中搜索所需的文件,然后将每个数据仅合并到一个文件中。此文件保存在bin文件夹中META-INF/services/{filename}