|
You last visited: Today at 17:27
Advertisement
[Buildfile] Apache Ant
Discussion on [Buildfile] Apache Ant within the Java forum part of the Coders Den category.
02/23/2015, 14:30
|
#1
|
elite*gold: 13849
Join Date: Oct 2014
Posts: 673
Received Thanks: 219
|
[Buildfile] Apache Ant
Hey Leute,
ich versuch mich das erste mal an Apache Ant und scheitere beim erstellen einer ausführbaren Jar datei.
Also er erstellt zwar die Jar, aber die is 150kb groß, statt wie wenn IntelliJ es macht 7MB, die Jar funktioniert auch, mein Programm geht auf, aber irgendwie Funktionieren die Funktionen nicht.
Hier mal meine Build.xml
Code:
<project xmlns:ivy="antlib:org.apache.ivy.ant"
name="transfer-mainline" default="main" basedir=".">
<description>
Build XML Validation for Okto-tranfser-mainline
</description>
<property name="projectName" value="XMLValidation" />
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="dist.dir" location="dist" />
<property name="dist.lib.dir" location="dist/lib" />
<property name="lib.dir" value="C:\Users\xxxx\IdeaProjects\Libraries" />
<property name="main-class" value="net.oktopos.transfer.Main" />
<target name="init">
<mkdir dir="${build.dir}" />
</target>
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
</fileset>
<pathelement location="${lib.dir}/commons-codec-1.6.jar" />
<pathelement location="${lib.dir}/commons-logging-1.1.3.jar" />
<pathelement location="${lib.dir}/fluent-hc-4.3.6.jar" />
<pathelement location="${lib.dir}/guava-18.0.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="${lib.dir}/httpclient-4.3.6.jar" />
<pathelement location="${lib.dir}/httpclient-cache-4.3.6.jar" />
<pathelement location="${lib.dir}/httpcore-4.3.3.jar" />
<pathelement location="${lib.dir}/httpmime-4.3.6.jar" />
<pathelement location="${lib.dir}/ini4j-0.5.2-SNAPSHOT.jar" />
<pathelement location="${lib.dir}/ini4j-0.5.2-SNAPSHOT-jdk14.jar" />
<pathelement location="${lib.dir}/jcalendar-1.4.jar" />
<pathelement location="${lib.dir}/jgoodies-common-1.2.0.jar" />
<pathelement location="${lib.dir}/jgoodies-looks-2.4.1.jar" />
<pathelement location="${lib.dir}/joda-time-2.4.jar" />
<pathelement location="${lib.dir}/json-simple-1.1.1.jar" />
<pathelement location="${lib.dir}/junit-4.6.jar" />
<pathelement location="${lib.dir}/junit-4.10.jar" />
<pathelement location="${lib.dir}/mockito-all-1.9.5.jar" />
</path>
<target name="compile" depends="init" description="compile the source ">
<echo message="${lib.dir}" />
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
</target>
<pathconvert property="classpath.name" pathsep=" ">
<path refid="classpath" />
<mapper>
<chainedmapper>
<flattenmapper />
<globmapper from="*.jar" to="lib/*.jar" />
</chainedmapper>
</mapper>
</pathconvert>
<target name="copy-dependencies">
<copy todir="${dist.lib.dir}">
<fileset dir="${lib.dir}" includes="**/*.jar" excludes="**/*javadoc.jar" />
</copy>
</target>
<target name="jar" depends="compile, copy-dependencies" description="package, output to JAR">
<echo message="classpath.name : ${classpath.name} " />
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${classpath.name}" />
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="main" depends="clean, compile, jar" />
</project>
|
|
|
02/23/2015, 15:24
|
#2
|
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228
|
Hmm, imo siehts auf den ersten Blick richtig aus..
Packt er alle Klassen, depencies usw in die jar?
Ich poste dir mal eine Vorlage von mir die ich benutze und dann immer weiter ausbaue:
Kannst es dann abgleichen:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ANT Bsp" default="compile" basedir=".">
<property name="src.dir" value="src" />
<property name="lib.dir" value="lib" />
<property name="classes.dir" value="build/classes" />
<property name="build.dir" value="build" />
<property name="doc.dir" value="build/doc" />
<property name="test.dir" value="build/tests" />
<path id="main_classpath">
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-core-1.3.jar" />
<pathelement path="${java.class.path}" />
</path>
<!-- Source files kompilieren -->
<target name="compile" depends="clean" description="Compile project.">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="main_classpath" />
</target>
<!-- build Ordner leeren/loeschen -->
<target name="clean" description="Clean build products.">
<delete dir="${build.dir}" />
</target>
<!-- Javadoc erstellen -->
<target name="create-doc" description="Create javadoc.">
<javadoc sourcepath="${src.dir}" destdir="${doc.dir}" />
</target>
<!-- Javadoc loeschen -->
<target name="clean-doc" description="Delete javadoc.">
<delete dir="${doc.dir}"/>
</target>
<target name="test" depends="run-tests" description="JUnit test.">
<mkdir dir="build/report"/>
<junitreport todir="build/report">
<fileset dir="build/report">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="build/report/html"/>
</junitreport>
</target>
<target name="run-tests">
<junit printsummary="yes" haltonfailure="false" haltonerror="false" fork="yes">
<classpath>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-core-1.3.jar" />
<pathelement path="${classes.dir}" />
</classpath>
<batchtest fork="yes" todir="build/report">
<formatter type="xml" />
<fileset dir="${classes.dir}" >
<include name="**/*Test*.class" />
</fileset>
</batchtest>
</junit>
</target>
<!-- jar erzeugen -->
<target name="jar" depends="clean, clean-doc, compile, create-doc" description="Creates jar file.">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="package.ClassName"/>
</manifest>
<fileset dir="./build" includes="doc/**" />
</jar>
</target>
</project>
(JUnit tests sind hier mit inkludiert)
|
|
|
02/23/2015, 15:32
|
#3
|
elite*gold: 13849
Join Date: Oct 2014
Posts: 673
Received Thanks: 219
|
Quote:
Originally Posted by XxharCs
Hmm, imo siehts auf den ersten Blick richtig aus..
Packt er alle Klassen, depencies usw in die jar?
Ich poste dir mal eine Vorlage von mir die ich benutze und dann immer weiter ausbaue:
Kannst es dann abgleichen:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ANT Bsp" default="compile" basedir=".">
<property name="src.dir" value="src" />
<property name="lib.dir" value="lib" />
<property name="classes.dir" value="build/classes" />
<property name="build.dir" value="build" />
<property name="doc.dir" value="build/doc" />
<property name="test.dir" value="build/tests" />
<path id="main_classpath">
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-core-1.3.jar" />
<pathelement path="${java.class.path}" />
</path>
<!-- Source files kompilieren -->
<target name="compile" depends="clean" description="Compile project.">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="main_classpath" />
</target>
<!-- build Ordner leeren/loeschen -->
<target name="clean" description="Clean build products.">
<delete dir="${build.dir}" />
</target>
<!-- Javadoc erstellen -->
<target name="create-doc" description="Create javadoc.">
<javadoc sourcepath="${src.dir}" destdir="${doc.dir}" />
</target>
<!-- Javadoc loeschen -->
<target name="clean-doc" description="Delete javadoc.">
<delete dir="${doc.dir}"/>
</target>
<target name="test" depends="run-tests" description="JUnit test.">
<mkdir dir="build/report"/>
<junitreport todir="build/report">
<fileset dir="build/report">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="build/report/html"/>
</junitreport>
</target>
<target name="run-tests">
<junit printsummary="yes" haltonfailure="false" haltonerror="false" fork="yes">
<classpath>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-core-1.3.jar" />
<pathelement path="${classes.dir}" />
</classpath>
<batchtest fork="yes" todir="build/report">
<formatter type="xml" />
<fileset dir="${classes.dir}" >
<include name="**/*Test*.class" />
</fileset>
</batchtest>
</junit>
</target>
<!-- jar erzeugen -->
<target name="jar" depends="clean, clean-doc, compile, create-doc" description="Creates jar file.">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="package.ClassName"/>
</manifest>
<fileset dir="./build" includes="doc/**" />
</jar>
</target>
</project>
(JUnit tests sind hier mit inkludiert)
|
Dank erstmal.
Habs verglichen und es ist auch richtig, ist halt komisch IntelliJ generiert die Jar mit knapp über 7MB und das Ant Build machts nur mit 150KB.
Ich denke das irgendwo ein Include/Verweiss oder sowas fehlt, aber dann müsste der Compiler sich ja beschweren..
Und die .class Files die erstellt werden sind auch kleiner als meine.
15,9KB von Ant Build und IntelliJ 25KB.
|
|
|
02/23/2015, 15:41
|
#4
|
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228
|
Quote:
Originally Posted by The Notorious B.I.G
Und die .class Files die erstellt werden sind auch kleiner als meine.
15,9KB von Ant Build und IntelliJ 25KB.
|
Hm, das ist komisch, wenn du die Main-Class mal manuell ausführen würdest(nach dem compilen mit ant), funktioniert dann das Programm richtig?
Wenn es funktioniert dann wird das jar File nicht richtig erstellt^^
|
|
|
02/23/2015, 15:48
|
#5
|
elite*gold: 13849
Join Date: Oct 2014
Posts: 673
Received Thanks: 219
|
Also habe den Bug gefunden es lag nicht an dem Ant Build sondern dass ich im Source Code eine Resource nicht geladen werden kann aus irgendeinen Grund.
Main.class.getResource(""); <- war der übeltäter.
|
|
|
02/23/2015, 15:51
|
#6
|
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228
|
Oh^^ Ja so ein Problem hatte ich auch beim SecurityManager als ich das Policy file geladen hab. Musste dann mit System.class.getResource().toString() arbeiten, und dann ging das jar file auch.
Aber um ehrlich zu sein, zu dem Moment hat bei mir das Build-Script beim compilen gemekert, konnte es also schnell beheben, in deinem Fall hat er nicht gemekert hm  ^^
|
|
|
02/23/2015, 16:07
|
#7
|
elite*gold: 13849
Join Date: Oct 2014
Posts: 673
Received Thanks: 219
|
Ja war schon komisch, was man noch erwähnen kann bezüglich der größe ist, dass die per Ant-Build extern sind, also meine Jar includiert quasi den Ordner "lib".
Falls irgendjemand auch mal sich fragt wo die Jar dann so klein ist..
|
|
|
03/22/2015, 07:02
|
#8
|
elite*gold: 176
Join Date: Apr 2011
Posts: 119
Received Thanks: 10
|
i need help for android
|
|
|
 |
Similar Threads
|
apache?
05/16/2012 - Metin2 Private Server - 0 Replies
Hey ich hab auf meinem freebsd 8.2 64bit server
apache,php5,php5session
installiert ich habe die "httpd.conf" schon angepasst nur wen ich jetzt apache starte kommt das
http://i.imgur.com/UHi5J.jpg
please help :)
|
Apache.
11/20/2011 - SRO Private Server - 1 Replies
Hey guys, I'm using Apache 2.2.
I've got some scripts on it, and with disabled apache, I have 5-30% CPU Usage, with enabled, I have 70-100, after reaching 95 and higher, server starts to lag.
That's annoying, because I must close Apache, and that way players can not reach our web.
Any ideas for how to reduce CPU usage?
|
Apache
10/13/2010 - Metin2 Private Server - 2 Replies
Moin wen ich apache starte steht da kurz running dan gehts auf stopped was da los?
|
Apache
11/14/2009 - Metin2 Private Server - 10 Replies
Hallo,
Apche startet nicht weil Port 80 bestezt ist.
Wo sehe ich die Ports?
mfg
|
[Help]Apache
08/20/2008 - EO PServer Hosting - 5 Replies
hello well its from ahmed not Crusher i was setting up Alpha on the new dedicated server all runned good Alpha runned so good etc when i tryed to run Apache it opens it self then closes it self Imedieltly what can i do please help tryed to Install wamp again and make a copy from wamp Didnt work Any one have any idea Please Share it here
|
All times are GMT +1. The time now is 17:27.
|
|