File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Steven Broadbent
Ranch Hand
Posts: 400
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Brian Pipa
Ranch Hand
Posts: 299
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still can't get this working.
 
Brian Pipa
Ranch Hand
Posts: 299
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic