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

  • SEARCH
  • Home
  • 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 6890269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:15:38+00:00 2026-05-27T06:15:38+00:00

I’m trying to construct a jar file using the Amazon Mechanical Turk API. The

  • 0

I’m trying to construct a jar file using the Amazon Mechanical Turk API. The SDK comes with a helloworld file that I’m trying to jar up as a sanity check – it is located here:

http://aws.amazon.com/code/SDKs/695

After setting everything up, I’m able to use ant to build and execute correctly, using the supplied build.xml file.

bash-3.2$ ant helloworld
ant helloworld
Buildfile: /Users/astorer/Work/dtingley/java-aws-mturk-1.2.2/build.xml

compile-sample:
     [echo] Compiling the sample java source files...
    [javac] /Users/astorer/Work/dtingley/java-aws-mturk-1.2.2/build.xml:252: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

helloworld:
     [echo] Running the Hello World sample application...
     [java] Got account balance: 10000.00
     [java] Created HIT: 2RB2D5NQYN5F41KJ2IKYPNCW2H3A60
     [java] You may see your HIT with HITTypeId '22R58B727M0IHQ4HZEXYISVF4XCWBC' here: 
     [java] http://workersandbox.mturk.com/mturk/preview?groupId=22R58B727M0IHQ4HZEXYISVF4XCWBC
     [java] Success.

BUILD SUCCESSFUL
Total time: 11 seconds

I want the helloworld to be executable by someone else without needing to install the libraries. It seems like the “correct” way to do this is to construct a jar from within ant.

My understanding is that I need to include:

  • the necessary libraries, build from the sdk itself (and provided as a .jar)
  • the built helloworld class file
  • the manifest attribute specifying the main class to run

I don’t know if I need to include anything else. I know that there is a big, complicated classpath at runtime, and that I can specify the classpath on the command line, but I suspect hard coding the classpath will prevent me from distributing the .jar file, which is the entire point.

Here is the build.xml snippet for the jar:

  <target name="hellojar" depends="helloworld" description="Creates Jar of helloworld" >
    <jar destfile="helloworld.jar">
      <fileset file="${sdk.jar}" />
      <fileset dir="${sample.classes.dir}/helloworld/" />
      <fileset dir="."/>
      <manifest>
        <attribute name="Main-Class" value="MTurkHelloWorld" />
      </manifest>
    </jar>
  </target>

This builds. When I run the jar, it crashes, however:

bash-3.2$ java -jar helloworld.jar 
java -jar helloworld.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: MTurkHelloWorld (wrong name: helloworld/MTurkHelloWorld)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

This makes sense, because my MTurkHelloWorld is actually in the helloworld package. Thus, I should change to:

  <manifest>
    <attribute name="Main-Class" value="helloworld.MTurkHelloWorld" />
  </manifest>

This builds successfully. When I run it:

bash-3.2$ java -jar helloworld.jar 
java -jar helloworld.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/MTurkHelloWorld
Caused by: java.lang.ClassNotFoundException: helloworld.MTurkHelloWorld
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

We can investigate the files within the jar:

jar tf helloworld.jar | grep hello
build/private/classes/samples/helloworld/
samples/helloworld/
build/private/classes/samples/helloworld/MTurkHelloWorld.class
samples/helloworld/MTurkHelloWorld.java

Which suggests that maybe if the classpath were set to build/private/classes/samples/ it would work properly:

<attribute name="Class-Path" value="build/private/classes/samples/helloworld" />

This leads to an identical error. I think there is something pretty fundamental that I’m missing here, and I’d appreciate any help!

  • 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-27T06:15:39+00:00Added an answer on May 27, 2026 at 6:15 am

    Your package-folder have to start directly, you can’t put them in any sub-directory in the jar file:

    It would have to look like this:

    helloworld/
    helloworld/MTurkHelloWorld.class
    

    Your jar-task would have to look like this:

    <jar destfile="helloworld.jar" basedir="${sample.classes.dir}">>
      <manifest>
        <attribute name="Main-Class" value="MTurkHelloWorld" />
      </manifest>
    </jar>
    

    The basedir is the source of your compiled packages.
    With <fileset /> you just add normal files.

    Furthermore, you can’t put external libs into jar files. They have to be in the same folder as the jar, in the java classpath or in a folder specified by the classpath-attribute of the manifest.
    Or you could use the one jar task, to include the classes into your jar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.