Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:11:48+00:00 2026-05-31T05:11:48+00:00

I created my first Ant script and it’s working pretty well. It compiles all

  • 0

I created my first Ant script and it’s working pretty well. It compiles all my java sources, creates a .jar file and runs the program without even any warning.

But when i try to run my .jar from command line i get NoClassDefFoundError exceptions.

So, how to translate this Ant snippet to work from command line?

<property name="main.class" value="de.bfs.radon.omsimulation.OMMainFrame"/>

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

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

This is the command line:

# java -classpath lib/ -jar bin/omsimulation-0.4.45-beta3.jar

Throws:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/toedter/calendar/JDateChooser
    at de.bfs.radon.omsimulation.OMMainFrame.(OMMainFrame.java:133)
    at de.bfs.radon.omsimulation.OMMainFrame$1.run(OMMainFrame.java:106)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)

Why does my .jar file not work with the defined classpath? Further down the Ant script:

<target name="jar" depends="manifest">
  <mkdir dir="${bin.dir}" />
  <jar jarfile="${bin.dir}/omsimulation-${version}.jar" manifest="${src.dir}/omsimulation.manifest" compress="no" basedir="${build.dir}" includes="de/**" />
</target>

<target name="manifest" depends="compile">
  <manifestclasspath property="manifest.cp" jarfile="${bin.dir}/omsimulation-${version}.jar">
    <classpath refid="classpath" />
  </manifestclasspath>
  <manifest file="${src.dir}/omsimulation.manifest">
    <attribute name="Built-By" value="${author}"/>
    <attribute name="Main-Class" value="${main.class}"/>
  </manifest>
</target>

Again, running the Ant script works fine. I even tried adding the said libraries to my .jar but that only blows up the file size, the problem still persists.

<jar jarfile="${bin.dir}/omsimulation-${version}.jar" manifest="${src.dir}/omsimulation.manifest" compress="no" basedir="${build.dir}"> <!-- includes="de/**" /-->
  <fileset dir="${lib.dir}">
    <include name="**/*.jar" />
  </fileset>
</jar>

Any ideas on this?

Thanks a lot,
donc_oe

SOLVED: Thanks to perception, the unix command line i was looking for is:

# java -cp lib/*:bin/myjarfile.jar my.package.MyMainClass

And for Windows (note the ; semicolon):

# javaw -cp lib/*;bin/myjarfile.jar my.package.MyMainClass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:11:49+00:00Added an answer on May 31, 2026 at 5:11 am

    The relevant thing to note from your build script is this:

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

    With that little snippet you have defined a path construct in Ant, which you then refer to in your run task:

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

    This is in effect executing:

    java -cp ${lib.dir}/*.jar:${bin.dir}/omsimulation-${version}.jar ${main.class}
    

    Of course, it does so without the squigly lines and the path(s) fully substituted. The main point being that the command you are trying to run yourself is not equivalent at all. When attempting to invoke from the command line you will need to include in the classpath all the necessar JAR’s containing your code and all third party libraries. Assuming everything is still bundled in the Ant created folders, something like:

    java -cp <full-path-to-lib>/* -jar <full-path-to-bin>/omsimulation-0.4.45-beta3.jar
    

    Or:

    java -cp <full-path-to-lib?/*:<full-path-to-bin>/omsimulation-0.4.45-beta3.jar <MainClass>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a buildr script that first loads a java properties file, then creates
I recently created my first bash script, and I am having problems perfecting it's
I created the following script to query a table and return the first 30
I'm trying to make an executable war file ( java -jar myWarFile.war ) that
I have an ant script created by a previous employee of our company and
I have a folder with these files: alongfilename1.txt <--- created first alongfilename3.txt <--- created
I've just created my first Preview 5 error and it doesn't seem to place
I just created my first MVC2 project using the standard template. I need to
I am new to Qt I created my first form and I want to
Python's convention is that variables are created by first assignment, and trying to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.