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 7749261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:59:58+00:00 2026-06-01T10:59:58+00:00

This is a really silly question that I can’t fine a difinitive answer to.

  • 0

This is a really silly question that I can’t fine a difinitive answer to.

Background.

I’m using Eclipse (with one of the ANT plugins, on an XP terminal).

I have just started playing with ANT, in the [jar] directive I am setting the location of my finished JAR file and I get the following when I ‘unzip’ the file

META-INF/MANIFEST.MF
MyMainFile.class

which is consistent with that found on the oracle web site for the internal structure.
(here http://docs.oracle.com/javase/tutorial/deployment/jar/view.html )

But when I try to run my file I get a ‘main class not found’ error ?

I have seen some other posts where people have ‘unzipped’ the JAR file and ended up with a structure of the following…

META-INF/MANIFEST.MF
dtvcontrol/DTVControlApp.class

(from here http://www.coderanch.com/t/528312/java/java/standalone-application)

So should I get a structure where my class files are in a directory that reflects the name of the package… eg

META-INF/MANIFEST.MF
MyPackage/MyMainFile.class

and if so, why am I getting the incorrect structure using ANT, or why are there 2 different ‘correct’ internal structures? (how to specifify main-class and classpath for each / control what I get)

Also in case you are interested, in the MANIFEST file states (build using ANT)
[attribute name=”Main-Class” value=”MyPackage.MyMainFile”/]

Also the directory structure of the package under development is as follows…

/JavaDev/MyTestPackage/src (contains the source files)
//JavaDev/MyTestPackage/bin (contains the class files from eclipse, or from the ANT JAVAC task, have I named it incorrectly? should I have called it build ? )

Further to this, when I create the jar I am not naming it ‘MyTestPackage.jar’ but simply ‘test.jar’ could this be causing a problem? I assume not as if I have well understood that is what the [main-class] definition stuff is all about.

Further to all this…

‘MyTestPackage’ is actualy a small visual error messaging library that I use elsewhere, and I have a second file that has a main class to use for testing. As such it points to various libraries (do I need to copy all the SWT libraries to a specified directory?)

I have read somewhere that if I load libraries into my main class (which I obviously do to open the window) then trying to run the program will fail on a ‘main class not found’ if I use them, same is also true for adding in any ‘static final’ members (which I use for the loggin of errors).

‘Static Final’ problem…
I tried to adjust the classpath in ANT, and I get a load of other errors for the connection to Log4J and my ‘wrapper’ that I use (to do with it being a bad import), but the libraries exist where they should as set in the classpath).

I feel like I am almost there…. but not quite…

I’m doing this for the small ‘library projects’ that I am creating with the intention of using MAVAN for the main outer package that will connect them all together… for now however I just want to get this going so as it works.

I can supply the full source, or any other info as required.

Thanks in advance…

David

  • 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-06-01T11:00:00+00:00Added an answer on June 1, 2026 at 11:00 am

    It’s simple when you know where to look. Say your META-INF/MANIFEST.MF contains the line:

    Main-Class: mypackage.MyMainFile
    

    then the structure of the jar needs to be

    META-INF/MANIFEST.MF
    mypackage/MyMainFile.class
    

    where MyMainFile has to be in the proper package:

    package mypackage;
    public class MyMainFile {
      public static void main(String[] args) {
    ...
    

    Your error message is caused by MyMainFile being in the wrong place.

    Edit: it’s been a while since the last time i did that with ant, but i think you need something like this: a source file structure that reflects the package struture, say

    src/main/java/mypackage/MyMainFile.java
    

    and a directory to put the compiled class file into, say

    target
    

    (I’m using maven conventions here, ant doesn’t care and you can use the (rightclick)->properties->Java Build path->Sources tab in eclipse to set the source dir to src/main/java and the target to target/classes). Then in ant, have a compile target that compiles from source to target:

    <target name="compile">
        <mkdir dir="target/classes"/>
        <javac srcdir="src/main/java" destdir="target/classes"/>
    </target> 
    

    so that after ant compile you should see the class file in the target

    target/classes/mypackage/MyMainFile.class
    

    Then have a ant jar task that packages this:

    <target name="jar" depends="compile">
        <jar destfile="target/MyJarFile.jar" basedir="target/classes">
            <manifest>
                <attribute name="Main-Class" value="mypackage.MyMainFile"/>
            </manifest>
        </jar>
    </target>
    

    After saying ant compile jar you should have a file MyJarFile.jar inside target and

    java -jar MyJarFile.jar
    

    should run the main method.

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

Sidebar

Related Questions

This is probably a really silly question bu tI can't seem to find an
This is probably a really silly question, but I can't seem to find an
Hey Everyone, This question seems really silly to me, but I can't for the
This maybe a really silly question but I just could not find the answer
This seems like a silly question but I would really like your comments and
Ok, so this seems like a really silly problem but I can't get my
This really, really urks me, so I hope that someone can give me a
Hopefully this is a silly question and there's really a simple solution somewhere out
My question seems really silly. But I really headache with this question. For example
Alright, this is probably a really silly question but I am new to Python/Django

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.