Results 1 to 10 of 10
- 02-26-2013, 05:07 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Executing the JAR File - ANT HelloWorld Tutorial
I'm going thru the HelloWorld tutorial in ANT. I've executed the echo command to create a manifest and created the HelloWorld.jar file using the manifest. When I try to execute the jar file (C:\ANT>java -jar Build\jar\HelloWorld.jar), I get " Cannot find or load main class oata.HelloWorld". If this class is in the jar file that is being executed, why is it not found?
Directory structure is as follows:
C:\Ant
C:\ANT\build
C:\ANT\build\classes
C:\ANT\build\classes\oata
C:\ANT\build\classes\oata\HelloWorld.class
C:\ANT\build\jar
C:\ANT\build\jar\HelloWorld.jar
Thanks
- 02-26-2013, 05:37 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Executing the JAR File - ANT HelloWorld Tutorial
Yes, but what is in the jar file?
Have you retained the package structure such that there is an 'oata' "folder" in the top level of the jar file, containing your class?Please do not ask for code as refusal often offends.
- 02-26-2013, 07:31 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Executing the JAR File - ANT HelloWorld Tutorial
Yes. The jar file has a META-INF folder which contains MANIFEST.MF. The jar file also contains "build/classes/oata/HelloWorld.class"
- 02-26-2013, 07:35 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Executing the JAR File - ANT HelloWorld Tutorial
Wait a minute. The "oata" folder is not the top level folder. Is that my problem?
Thanks
- 02-26-2013, 08:35 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Executing the JAR File - ANT HelloWorld Tutorial
Thanks for the help. The piece of data I was missing was that the "oata" folder needed to be the top level folder in the jar file
I figured this out how to make that happen.
Key points: 1. before executing the jar command one must change the directory to the the path of the class file . in my case "C:>ANT\build\classes".
2. if one wants the new jar file to be in a folder other than the "classes" folder, one must enter the full path. In my case "C:\build\jar\HelloWorld.jar".
One other note . If I used the -C parameter before the class file folder name, a jar file was not created. I had to leave out the "-C" to make it work. I don't know what is going on there.
.
- 02-27-2013, 09:23 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Executing the JAR File - ANT HelloWorld Tutorial
What is the full command you are using when using the -C option, and where are you located when you do that?
Please do not ask for code as refusal often offends.
- 02-27-2013, 03:22 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Executing the JAR File - ANT HelloWorld Tutorial
The following will not produce a jar file:
"C:\ANT\build\classes>jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest -C oata/"
The following DOES produce a jar file:
"C:\ANT\build\classes>jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest oata/"
- 02-27-2013, 04:57 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Executing the JAR File - ANT HelloWorld Tutorial
The -C just tells it to change directory to the given directory (oata in your case).
So in that first command you have only told the jar command to change directory...but you haven't given it anything to jar up.
jar -cfm C:\ANT\build\jar\HelloWorld.jar myManifest -C oata .
That '.' there tells it you want to jar up the contents of the current directory, in this case the contents of 'oata' since that is current as of the '-C'.Please do not ask for code as refusal often offends.
- 02-28-2013, 01:21 AM #9
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Executing the JAR File - ANT HelloWorld Tutorial
That works. I didn't know you needed the period.
Thanks again!!
- 02-28-2013, 10:08 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Executing a executable .jar file
By angrylolrus in forum New To JavaReplies: 3Last Post: 11-26-2012, 06:00 AM -
Trouble executing a file!
By javabeginner29 in forum New To JavaReplies: 1Last Post: 02-26-2012, 09:29 AM -
Problem executing jar file
By gio123bg in forum New To JavaReplies: 4Last Post: 06-30-2009, 11:37 AM -
executing the java file
By TheBayWatchMan in forum New To JavaReplies: 4Last Post: 01-12-2008, 09:31 AM -
Executing a jar file
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2007, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks