6753

'Could not find the main class error' in a build file

Question:

I have craated a Java application with an Ant build file containing the jar-task task that generate a jar file from the application.

<target name="jar-task" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="jar/guix.jar" basedir="${bin.dir}"> <fileset dir="${basedir}"> <include name="${basedir}/images/**/" /> </fileset> <manifest> <attribute name="Main-Class" value="IO.Deep.clk.GUI"/> <attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/> </manifest> <filelist dir="${basedir}" files="user.properties"/> </jar> </target>

When I execute on the command line however a NoClassDefFoundError stating

Could not find the main class IO.Deep.clk.GUI. Program will exit.

Now, the GUI file is exactly in the specific folder and in the same package, I really can't understand where the error may be...can anyone help?

Answer1:

The name images suggests, that the jar file will contain only images. But where is the actual code?

<blockquote> <fileset dir="${basedir}"> <include name="${basedir}/images/**/" /> </fileset> </blockquote>

This piece

<blockquote> <attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/> </blockquote>

will write full qualified pathnames into the manifest. Are sure, that this is correct? Also note, that the code will not find user.properties by putting the file on the classpath. The classpath can contain only directories or jar-files in which classes or other stuff will be searched for. But simple files won't work.

I'm also not sure about the lib/* part. Is the class IO.Deep.clk.GUI in one of the jar files in that directory? That would be a hint, that all directories must be listed explicitly. If that's not a problem - good.

<strong>EDIT</strong>: The classpath problems can be avoided by adding the task manifestclasspath (<a href="http://ant.apache.org/manual/Tasks/manifestclasspath.html" rel="nofollow">Ant docs</a>) before the call of jar and by using the generated classpath value inside the manifest attribute. Outline:

<manifestclasspath property="jar.class.path" jarfile="jar/guix.jar"> <classpath> <fileset dir="." includes="*.jar" /> <fileset dir="." includes="lib/*.jar" /> </classpath> </manifestclasspath> <echo message="Class-Path will be: ${jar.class.path}" /> <jar ....> .... <attribute name="Class-Path" value="${jar.class.path}" />

Answer2:

Are you sure your resulting filest inside the jar task contains all the files you need?

For debugging you can use a path convert to the fileset out of the jar task and echo it so that you can verfiy that you have the correct files. If this is OK then I don't see something else wrong in your file although I have limited experience with the jar task myself.

Recommend

  • How to associate a file type with a (my) Java application on OSX?
  • set header and footer in BlackBerry in VerticalFieldManager
  • Pyinstaller adding splash screen or visual feedback during file extraction
  • iPhone Phonegap based app load External website made of componentone
  • Which is Android/Java corresponding method to the C#/C++ method GetTickCount()?
  • Java EE 6 Login module
  • ZeroMQ poll thread safety
  • initializing array of variable size inside a class
  • Importing pyplot in a Jupyter Notebook
  • Python 2.7 on OS X: TypeError: 'frozenset' object is not callable on each command
  • css font-size and line-height not matching the baseline
  • Using Netbeans with Cygwin and SDL, including SDL.h creates strange error
  • Graceful pod termination
  • insert a picture into database(sqlite) with java code. what should i do?
  • Getting error java.io.FileNotFoundException (log4j log file) at the time of publish project on cloud
  • Python 3.2.2, error(scripts to exe)
  • Is it possible to define rest argument in OCaml?
  • How to get latest version of a artifact on Bintray using JSONP
  • C# fibonacci function returning errors
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • How to get current document uri in XSLT?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • What is the purpose of TaskExecutor in spring?
  • gspread or such: help me get cell coordinates (not value)
  • error importing numpy
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • java inputstream
  • Very simple C++ DLL that can be called from .net
  • Q promise. Difference between .when and .then
  • Numpy divide by zero. Why?
  • C# - Getting references of reference
  • Java static initializers and reflection
  • Authorize attributes not working in MVC 4
  • unknown Exception android
  • Busy indicator not showing up in wpf window [duplicate]
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • Converting MP3 duration time
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF