• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

running java class as standalone

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a java class, which I want to run as standalone,
which means that wherever it will be located, doubleclick on it will
run it.(it also interacts with the user - it asks 3 questions and the
answers are simple int...)
Thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classes aren't double-clickable. You'll have to wrap it in a jar file.
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf, thanks for your reply.
I understand that jar files are double-clickale.
I executed a jar file out of my project.
I saved my jar in my desktop. I double-clicked on
it and it did nothing.
Do I miss something ? (I use Eclipse)
Thanks a lot.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe there are problems with the manifest or the classpath. To see those, run it from the command line via "java -jar my.jar".
 
Marshal
Posts: 80639
472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And there is more about jars and manifests in the Java™ Tutorials.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

moshi cochem wrote: I double-clicked on
it and it did nothing.


Since it did nothing, my guess is, it works fine.
else it would either show a prompt asking you to select the program to open jar files with,
or it will show a message box stating that the main method/class was not found.


Do one thing,
open command prompt, type the following command:

java -jar myFile.jar

and paste the exception/message here
[assuming your file name is myFile.jar and the path is set to java bin directory]
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I don't even have to include in this calling the jars that in the classpath, right ?
only java -jar myJar.jar ?
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I tried to run the jar independently.
I located it in c:/ and ran it from there:
java -jar myJar.jar
I got an exception that indicates that another jar from the classpath is missing.
Should I bring that jar into c: either and name it when I invoke the jar somehow ? (how...?)
If so, it says that the jar is never independent.
Am I write ?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to make the missing jar file available to the jar file you are running, either copying it in the same folder or using -classhpath option, something like java -jar myJar.jar -classpath C:\otherJars
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the jar file's manifest to put required jar files automatically into the classpath; this is easiest if those jar files are in the same directory as the main jar file.
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , first of all I want to thank you all to your help.
Well, unfortunately, I put the jar in c: and also the other jar that I use in the classpath.
I write:
C:\>java -jar myJar.jar classpath c:\h2.jar
and I get: Ljava.lang.StackTraceElement

Any idea ?
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

moshi cochem wrote:Hi , first of all I want to thank you all to your help.
Well, unfortunately, I put the jar in c: and also the other jar that I use in the classpath.
I write:
C:\>java -jar myJar.jar classpath c:\h2.jar
and I get: Ljava.lang.StackTraceElement

Any idea ?




need the complete stacktrace (or at least first 10 lines)
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry, here it is:
java.lang.ClassNotFoundException: org.h2.
at java.net.URLClassLoader$1.run(
at java.security.AccessController
at java.net.URLClassLoader.findCl
at java.lang.ClassLoader.loadClas
at sun.misc.Launcher$AppClassLoad
at java.lang.ClassLoader.loadClas
at java.lang.ClassLoader.loadClas
at java.lang.Class.forName0(Nativ
at java.lang.Class.forName(Unknow
at Utils.H2Admin.CreateDataBase(H
at Utils.H2Admin.main(H2Admin.jav
[Ljava.lang.StackTraceElement;@530daa

Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did the "-" in front of "classpath" get lost during posting? That's crucial.
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ulf,
I'm not sure that I understand what you mean.
I run it in command:
c:/>java -jar.....
I don't think that it is get lost when I run it...
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I solved it by addidng a manifest contains the classPath.
Thanks anyways !
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

moshi cochem wrote:Hi, sorry, here it is:
java.lang.ClassNotFoundException: org.h2.
at java.net.URLClassLoader$1.run(
at java.security.AccessController
at java.net.URLClassLoader.findCl
at java.lang.ClassLoader.loadClas
at sun.misc.Launcher$AppClassLoad
at java.lang.ClassLoader.loadClas
at java.lang.ClassLoader.loadClas
at java.lang.Class.forName0(Nativ
at java.lang.Class.forName(Unknow
at Utils.H2Admin.CreateDataBase(H
at Utils.H2Admin.main(H2Admin.jav
[Ljava.lang.StackTraceElement;@530daa

Thanks



looks like you used the mouse to select text in command prompt,
a full column was "eaten" away

 
reply
    Bookmark Topic Watch Topic
  • New Topic