aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes could not find the main class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "could not find the main class" Watch "could not find the main class" New topic
Author

could not find the main class

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm trying to make a workable jar with ant:

here's my (relevant) dir structure:
here's my manifest from inside my jar:

what am i doing wrong?

TiA
[ April 01, 2006: Message edited by: miguel lisboa ]

java amateur
Pratik Lohia
Ranch Hand

Joined: May 05, 2005
Posts: 88
Try putting the main-class path in your Manifest as
projc.bin.giu.GuiLogin
[ April 03, 2006: Message edited by: Pratik Lohia ]
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
To Pratik Lohia

I don't think your answer is correct unless those top packages are defined in the package statement.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
To miguel lisboa

I think you might not packaged your class files in your jar, see this line


Try to open your jar to see what are inside.

Thanks!
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Roseanne: i checked and they are all there
using the same ant script i can perfectly run my app:

as you can see i invoque my main class twice (for running and for jar) the same way

i tried several combinations, with and without explicit manifest file, and with manifest at several locations...
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
If you double click your jar in windows, does it run?

If it does not, then hand change to make it run, then you will probably find out your problem.

From my experiences, if you can make something work by your hand, then you know how to make it work by ant.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
hi again Roseanne: thanks for helping

i'm not sure if i understood you right
my jar doesnt open, instead says cant find main class - and that's the reason i'm posting here
If it does not, then hand change to make it run


do you mean creating a jar from command line? and then compare paths and manifest?
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Originally posted by miguel lisboa:

do you mean creating a jar from command line? and then compare paths and manifest?[/QB]


That is one way to do it for sure.

Another way is creating a simple enough project with one HelloWorld.java, make your build file work on that one. You eliminate all the complexity and distractions. Focus on one thing and one thing only.

I always believe, you can do it by hand, then you can do it by using ant.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks again

my swing app is a standalone java app that interacts with database using hibernate, so i need several jars to have my app working

i developed all this using eclipse; here i added the packages (org, com, javax, etc) into my project and this way i can create an executable jar using eclipse wizard.

i also manually created an executable jar adding those jars to manifest classpath, but i had to have all those jars allways next to my jar, in order to have it working (didnt like this solution)

next, i tried to (re)create my proj, in another location, using jars instead of packages (inside lib folder):
<property name = "librarydir" value = "${basedir}/lib" />

<path id = "libraries">

<fileset dir ="${librarydir}">

<include name = "*.jar" />

</fileset>

</path>

and building and running it with ant: success!
the problem appeared when i tried to generate the dreaded jar

now, i tried using command line and coud not get the jar, because of the same error msg; so i added the several needed packages (instead of jars), and got it working, using:
C:\javas\projc\bin>jar -cmf MANIFEST.MF CDC.jar bd creditacao dominio excepcoes gui hbm io negocio org test util hibernate.cfg.xml log4j.properties img net com javax

now i guess that is impossible to create an executable jar from a project that itself includes jar files...

at this moment i'm looking at something called "one-jar", suposedly created for situations such as mine

as an aside, you might have noticed i'm no pro, just a java amateur who uses java for fun (in my spare time)
 
jQuery in Action, 2nd edition
 
subject: could not find the main class