Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's simple when you know where to look. Say your META-INF/MANIFEST.MF contains the line:</p> <pre><code>Main-Class: mypackage.MyMainFile </code></pre> <p>then the structure of the jar needs to be</p> <pre><code>META-INF/MANIFEST.MF mypackage/MyMainFile.class </code></pre> <p>where MyMainFile has to be in the proper package:</p> <pre><code>package mypackage; public class MyMainFile { public static void main(String[] args) { ... </code></pre> <p>Your error message is caused by MyMainFile being in the wrong place.</p> <p><strong>Edit:</strong> 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 </p> <pre><code>src/main/java/mypackage/MyMainFile.java </code></pre> <p>and a directory to put the compiled class file into, say</p> <pre><code>target </code></pre> <p>(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:</p> <pre><code>&lt;target name="compile"&gt; &lt;mkdir dir="target/classes"/&gt; &lt;javac srcdir="src/main/java" destdir="target/classes"/&gt; &lt;/target&gt; </code></pre> <p>so that after <code>ant compile</code> you should see the class file in the target</p> <pre><code>target/classes/mypackage/MyMainFile.class </code></pre> <p>Then have a ant jar task that packages this:</p> <pre><code>&lt;target name="jar" depends="compile"&gt; &lt;jar destfile="target/MyJarFile.jar" basedir="target/classes"&gt; &lt;manifest&gt; &lt;attribute name="Main-Class" value="mypackage.MyMainFile"/&gt; &lt;/manifest&gt; &lt;/jar&gt; &lt;/target&gt; </code></pre> <p>After saying <code>ant compile jar</code> you should have a file MyJarFile.jar inside target and </p> <pre><code>java -jar MyJarFile.jar </code></pre> <p>should run the main method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload