During my Java source-code I wish to use different classes from java archives (.jar) saved during my application's "lib" directory. But when I actually do "ant run" i quickly always obtain a "java.lang.NoClassDefFoundError" message. I attempted a number of things to repair it but nothing labored... Maybe someone here might help me?

This really is my build.qualities file:


This really is my build.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="My Project" default="run" basedir=".">
  <description>My description.</description>

  <property file="build.properties" />
  <path id="classpath">
    <fileset dir="${lib.dir}" includes="*.jar"/>

    <!-- Initialization -->
  <target name="init" description="Prepare needed directories.">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${classes.dir}" />
    <mkdir dir="${jar.dir}" />
    <mkdir dir="${dist.dir}" />
    <mkdir dir="${lib.dir}" />

    <!-- Cleanup -->
  <target name="clean" description="Remove all files created by the build/test process.">
    <delete dir="${classes.dir}" />
    <delete dir="${dist.dir}" />

    <!-- Compile application -->
  <target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="yes" includeantruntime="false">
      <!-- <classpath refid="classpath" /> -->

    <!-- Java Archive -->
  <target name="jar" depends="compile">
    <!--<delete file="${jar.dir}/${app.name}-${app.version}.jar"/>-->
    <delete dir="${jar.dir}"/>
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${app.name}-${app.version}.jar" basedir="${classes.dir}">
        <attribute name="Class-Path" value="${lib.dir}"/>
        <attribute name="Main-Class" value="${main.class}"/>

    <!-- Run application -->
  <target name="run" depends="jar">

    <java jar="${jar.dir}/${app.name}-${app.version}.jar" fork="true">
    <java fork="true" classname="${main.class}">
        <path refid="classpath"/>
        <path location="${jar.dir}/${app.name}-${app.version}.jar"/>

It might be nice if anybody may help.



I see you have been attempting to set your classpath for that <java> task.

Perhaps you have attempted:

<java jar="${jar.dir}/${app.name}-${app.version}.jar" fork="true">
  <classpath refid="classpath" />

EDIT: make sure the values inside your qualities file. Have you got trailing spaces for the need for lib.dir or jar.dir?


ant unsuccessful to construct my program via javac even if I place the needed jars within an exterior build.qualities file and reference them by pathelement or classpath refid.

When ant loads qualities from an exterior file it does not touch the worth of qualities, trailing blanks won't be trimmed for instance.

When the value signifies personal files path, just like a jar required to compile, the job which necessitates the value, javac for example would neglect to compile because it aren't able to find the file because of trailing spaces.