*
The moose likes Java in General and the fly likes running java class as standalone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "running java class as standalone" Watch "running java class as standalone" New topic
Author

running java class as standalone

moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Classes aren't double-clickable. You'll have to wrap it in a jar file.


Ping & DNS - my free Android networking tools app
moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Maybe there are problems with the manifest or the classpath. To see those, run it from the command line via "java -jar my.jar".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39066
    
  23
And there is more about jars and manifests in the Java™ Tutorials.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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]


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
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

Joined: Nov 10, 2009
Posts: 91
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 ?
Efrain Morales
Greenhorn

Joined: Oct 14, 2009
Posts: 12
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
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

Joined: Nov 10, 2009
Posts: 91
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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

Joined: Nov 10, 2009
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Did the "-" in front of "classpath" get lost during posting? That's crucial.
moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
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

Joined: Nov 10, 2009
Posts: 91
Hi,
I solved it by addidng a manifest contains the classPath.
Thanks anyways !
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: running java class as standalone