• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

running a class in a jar ......

 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using ant to jar up an application and it is going ok.
However I have two minor problems which I think are class path related.
First how do I run a class from the jar I create, I want to run java from inside the directory that contains the jar.
Secondly how can I have a build.xml for ant in each projects src dir and run ant from inside the src dir.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First how do I run a class from the jar I create
You'll need the JAR file included in your CLASSPATH setting, or you can create an executable JAR file.
 
Steven Broadbent
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still have problem running the single class jar:-
C:\j2sdk1.4.2_01\bin>java -jar C:\javaprojects\ant_test\dist\project.jar wibble
Failed to load Main-Class manifest attribute from
C:\javaprojects\ant_test\dist\project.jar
the jar was created with ant, has I class wibble with a main method
 
Steven Broadbent
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
followed the example on creating a jar given by Dirk, but double clicking the jar gives error message "exception in main thread" (I think, the console window flashes by )

Any answers anyone? I can create jars it seems, but can't run them via double click of the command prompt.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you run them from a command prompt? If so, then it's likely a case of the JAR file type not being properly registered with your OS in order to be able to run them by double-clicking on them.
If you can run them from a command prompt, and you'd like some help with adjusting your OS settings to work with double-clicks, just post a note.
Note that the syntax to run execute a JAR from a command prompt is java -jar MyJar.jar
 
Steven Broadbent
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my jar is under C:
C:\>C:\j2sdk1.4.2_01\bin\java -jar MyFoo.jar
Exception in thread "main" java.util.zip.ZipException: The system cannot f
e file specified
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:112)
at java.util.jar.JarFile.<init>(JarFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:65)
seems I have had every error message imaginable. I have look into the
jar and it seems to be ok - a single class with no package dec.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it helps, here is my jar target that I use to create an executable jar. Maybe you can modify it to jar up your code.

Brian
 
Steven Broadbent
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still can't get this working.
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Still can't get this working.
>
That doesn't tell us much. What did you try? What errors do you get (if any)? Give us some code, some command lines, some build scripts, etc., etc. We're not mind readers
brian
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic