ant - Could not find or load main class Java -


good evening stack overflow!

i started learning java quite few days ago, not using ide once computer bit slow. so, decided use sublime text, , compile things using ant on cmd, since seems reasonable thing do.

today started ( @ least tried ) follow along series of lwjgl tutorials (which cool), thinmatrix, can't manage solve error every time try compile 'project'.

this structure of project:

  • lwjgl

    • src
      • com
        • game
          • test
            maingameloop.java
          • renderengine
            displaymanager.java

    build.xml

and ladies , gentlemen... build.xml (following ant's official helloworld tutorial):

<project name="lwjgl" basedir="." default="main">  <property name="src.dir"     value="src"/>  <property name="build.dir"   value="build"/> <property name="classes.dir" value="${build.dir}/classes"/> <property name="lib.dir"    value="lib"/> <property name="jar.dir"     value="${build.dir}/jar"/>  <property name="main-class"  value="com.game.test.maingameloop"/>  <path id="classpath">     <fileset dir="${lib.dir}" includes="**/*.jar" />  </path>  <target name="clean">     <delete dir="${build.dir}"/> </target>  <target name="compile">     <mkdir dir="${classes.dir}"/>     <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" classpathref="classpath" /> </target>  <target name="jar" depends="compile">     <mkdir dir="${jar.dir}"/>     <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">         <manifest>             <attribute name="main-class" value="${main-class}"/>         </manifest>     </jar> </target>  <target name="run" depends="jar">     <java jar="${jar.dir}/${ant.project.name}.jar" fork="true">         <jvmarg value="-djava.library.path=lib/natives-win" />     </java> </target>  <target name="clean-build" depends="clean,jar"/>  <target name="main" depends="clean,run"/> 

every time run ant on command line, inside root folder of project, this:

[java] error: not find or load main class com.game.test.maingameloop [java] java result: 1 

i'm struggling understand root problem of this, kinda sexually abused google search trying find answer on java forums, blogs, , here...

i don't populating stack overflow noob questions, have admit don't know do.

thanks in advance!

your code depends on libraries. have added libraries in classpath compile code, , have created executable jar files containing classes. these classes depend on libraries run. , when running jar file, don't secify anywhere java should classes in libraries in addition jar file.

see generate manifest class-path <classpath> in ant how add class-path entry manifest of executbale jar file. beware: paths of libraries must relatie path of jar.

ant bit outdated. if you, i'd try using gradle, has neat application plugin doing you, , more.


Comments