My professor has decided to provide an external jar with a main method for this assignment and we’re supposed to write code for the back end. I have no problem getting this jar into my project and having it run within Eclipse, but as soon as I try to export a runnable jar I get this error:
“could not find main method from given launch configuration”
This seems ridiculous as it can certainly find the main method whenever I run it in Eclipse, what am I missing? I’ve tried opening up the jar to get at the Manifest.mf file and providing it with the name of the class that is main inside of the external jar but it still can’t locate it.
I have the jar added to the project build path and class path as well but that doesn’t seem to make a difference.
The manifest file just says:
Manifest-Version: 1.0
Class-Path: .
I think this is wrong but how do I set it up correctly?
— EDIT —
Here is an ANT file generated by Eclipse when I build:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project Lab 1">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="C:/lab.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="edu.wmich.cs1120.la1.solution_gui.MainWindow"/>
<attribute name="Class-Path" value="."/>
</manifest>
<zipfileset excludes="META-INF/*.SF" src="C:/LA1_GUI.jar"/>
<fileset dir="C:/bin"/>
</jar>
</target>
Okay I see what the Main-Class attribute needs to be set to so when I edit the Manifest.mf to reflect that it works! But I’m still confused, especially by the lines:
filesetmanifest="mergewithoutmain"
zipfileset excludes
Why is it doing that if I’ve specified a main for my project?
With classpath as ‘.’ in your manifest, you will need to have the jar your professor supplied in the same directory you are trying to run your created jar from. Else there is probably a way to tell eclipse/ant to include all dependencies.
-UPDATE-
Since you are using a Main method from a dependency, you should specifiy the folloing in your ant build xml, and re-build.
This will merge in the main section of the other manifest into your new jar’s manifest.