I created a project in IDEA. I have resources: images (png) and text files (txt). In the program I work with pictures so

URL url = MyClass.class.getResource(shortName); ImageIcon icon = new ImageIcon(url); 

Everything works well. But if I try to get the URL for a text file resource in the same way, it will be equal to Null . It turned out that the program takes resources from a directory with classes (class files) and for some reason there when compiling files with the png extension are copied, and text files are not. How to fix?

    1 answer 1

    Refer to them in the bin folder and put all resources in the resource folder, and instead of simple compilation, better create a simple ant-script that will collect the jar-archive and run it.

    Folder structure:

     Project | |--ant | | | -- build.xml |--bin |--lib ---src 

    build.xml:

     <project default="main" basedir=".."> <tstamp> <format property="now" pattern="dd/MM/yyyy hh:mm:ss" /> </tstamp> <target name="main" depends="compile"> <checksum totalproperty="version_md5"> <fileset dir="bin" /> </checksum> <antcall target="makeJar"><param name="jarName" value="executableJAR"/></antcall> </target> <target name="compile"> <javac srcdir="src" destdir="bin" classpath="."> <classpath> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> </classpath> </javac> </target> <target name="makeJar"> <jar basedir="bin" destfile="jars/context_${jarName}.jar" encoding="utf8"> <include name="**/*.class" /> <manifest> <attribute name="Bundle-Version" value="${version_md5}" /> <attribute name="Class-Path" value="lib/SOME_LIB.jar"/> <attribute name="Main-Class" value="package.${jarName}"/> </manifest> </jar> </target> </project> 
    • And without Ant in any way? - angry