Hello. I'm trying to include some resources (images and fonts) in my project. As of now is works if I run the project from Eclipse or if I export a runnable jar via Eclipse (all files in one jar). But if I build my project with ant it doesn't work.
Here is the addImage method:
which I call like this:public void addImage(String imagePath) { /* Carica l'indirizzo dell'immagine */ URL imageUrl = getClass().getResource(imagePath); /* Carica l'immagine */ Image myPicture = Toolkit.getDefaultToolkit().getImage(imageUrl); ImageIcon image = new ImageIcon(myPicture); /* Inserisci l'immagine nella gameText */ gameText.insertIcon(image); }
addImage("/jork/thegame/resources/images/intro-ork.png");
Here is the setFont method:
which I call like this:public final void setGameTextFont(String fontPath, int size) { /* Carica la risorsa */ InputStream in = Gui.class.getResourceAsStream(fontPath); try { /* Crea un nuovo font */ Font font = Font.createFont(Font.TRUETYPE_FONT, in); /* Applicalo alla gameText settando la dimensione a size */ gameText.setFont(font.deriveFont((float) size)); } catch (FontFormatException e) { /* Salva il messaggio di errore */ Logger.log(e.getMessage()); } catch (IOException e) { /* Salva il messaggio di errore */ Logger.log(e.getMessage()); } }
setGameTextFont("/jork/thegame/resources/fonts/LucidaTypewriterRegular.ttf", Constants.GAMETEXTFONT);
And finally here is my build.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." name="GestioneStudenti" default="compile"> <!-- default="sonar" --> <property name="src.dir" value="./src" /> <property name="build.dir" location="./build" /> <property name="lib.dir" location="./lib" /> <!-- Add the Sonar task --> <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> <classpath path="/usr/share/ant/lib/" /> </taskdef> <target name="clean"> <delete dir="${build.dir}"/> </target> <target name="prepare" depends="clean"> <mkdir dir="${build.dir}"/> </target> <target name="compile" depends="prepare" description="Compila tutte le classi"> <!--depends="prepare"--> <echo message="Compiling application sources..."/> <javac srcdir="${src.dir}" destdir="${build.dir}"/> <!-- classpathref = "compile.path" /--> </target> <target name="sonar" depends="compile" description="Invia il progetto a Sonar"> <echo message="WARNING::: Assicurasi che sonar sia in esecuzione!" /> <property name="sonar.sources" value="${src.dir}" /> <property name="sonar.java.source" value="1.6" /> <property name="sonar.java.target" value="1.6" /> <property name="sonar.binaries" value="${build.dir}" /> <property name="sonar.libraries" value="${lib.dir}" /> <!--property name="sonar.tests" value="${test.dir}" /--> <!--property name="sonar.dynamicAnalysis" value="reuseReports" /--> <sonar:sonar key="it.uniroma2:lmp" version="0.1" xmlns:sonar="antlib:org.sonar.ant"/> </target> </project>
Can anyone point out what I'm doing wrong?