aspose file tools*
The moose likes Java in General and the fly likes jar runs on desktop but not laptop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "jar runs on desktop but not laptop" Watch "jar runs on desktop but not laptop" New topic
Author

jar runs on desktop but not laptop

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

i have clean & build my project in netbeans which run fines in my desktop , the executable jar was in my project folders dest folder and the executable jar has java's icons ,
but the problem is when i run the same folder in my laptop which has java and jdk class path is set in environment variable in other words its also my development machine
but there i cant run that same project or jar files , when i run that it says no class or jar found at that location but i can see the jar file in the path , c/desktop/jtext/dist/jtextpane.jar
but jvm launcher says that jar file does not exit in the same location
what can i do now ?


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Exactly how are you trying to "run the same folder"?

Bill
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

William Brogden wrote:Exactly how are you trying to "run the same folder"?

Bill


i m launching the classname.jar by double clicking on the jar but it throws an error saying noclassdeffound etc
but i m able to launch the same app from cmd
then what is the problem with double clicking the app's jar file ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

javaw has a nasty habit of displaying the same error message for any throwable that's thrown from the main method.

How are you launching the JVM from the command line?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Rob Spoor wrote:javaw has a nasty habit of displaying the same error message for any throwable that's thrown from the main method.

How are you launching the JVM from the command line?

hi rob , problem is when i m launching from command line my app.jar runs fine
  • but when i double click the jar it says noclassDeffound when i try to open with java se binary (jar association is java)
  • and when i double click the jar it says no class found in the directory and shows me the path of my deirectory but this it is launched by javaw se binary (jar association is javaw)


  • i have also try to set the classpath like .; and the directory which contains the jar file like for eg classpath = .;c//desktop/jtextpane/dest/myapp.jar but nothing seems to be working

    note : this jar is build on my desktop & works fine in my desktop , problem arises when i try to make a zip and distribute it to my users so for eg : in this case consider user is my laptop
    now can you help me ?
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19670
        
      18

    You did not answer my question. What do you enter on the command line when it runs fine?
    Randall Twede
    Ranch Hand

    Joined: Oct 21, 2000
    Posts: 4340
        
        2

    rob is probably your best hope for a good answer, but i will just mention this in case it applies. maybe the laptop has an older version of the JRE. i have had a problem with this when compiling an Applet in java7 and my browser only finds java6 runtime.


    SCJP
    Visit my download page
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    Rob Spoor wrote:You did not answer my question. What do you enter on the command line when it runs fine?
    hi rob
    i started my app.jar like
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19670
        
      18

    To be honest, I doubt it. Windows doesn't use forward slashes as path separators but backslashes. Perhaps you meant that that is the current path; then it would work. It would also mean that double clicking the JAR file (which does little more than call javaw.exe -jar Myapp.jar) should work as well. If it doesn't it's probably a class path issue. Did you set the class path inside that command line window? Or did you set it up as an environment variable? Either way, the preferred way of setting class paths for JAR files is to put it in the JAR's MANIFEST.MF file, as the value of the Class-Path attribute. See this for more information.
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    Rob Spoor wrote:To be honest, I doubt it. Windows doesn't use forward slashes as path separators but backslashes. Perhaps you meant that that is the current path; then it would work. It would also mean that double clicking the JAR file (which does little more than call javaw.exe -jar Myapp.jar) should work as well. If it doesn't it's probably a class path issue. Did you set the class path inside that command line window? Or did you set it up as an environment variable? Either way, the preferred way of setting class paths for JAR files is to put it in the JAR's MANIFEST.MF file, as the value of the Class-Path attribute. See this for more information.


    i got this mf file from inside my jar file
    strange thing was the class path is not set ...and i have tried setting it manually but this too doesn't solve my problem
    note : the main class is correct package is jtextpanedemo and class is JTextPaneDemo
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19670
        
      18

    That java -jar Myapp.jar command is working on your desktop. Is it also working on your laptop? I still think there is a class path issue. Maybe it's not in the CLASSPATH environment variable, but some library you put in the /lib/ext sub folder of the JRE installation.
    On the other hand, the cause could be something completely different. Perhaps you're trying to read from a file that doesn't exist on the laptop, or you have no rights to read that file. Likewise for writing a file or creating a directory.
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    That java -jar Myapp.jar command is working on your desktop
    .

    yes , it works any way in my desktop from cmd or just by double click ..no problem in my desktop

    Is it also working on your laptop?


    from command line or cmd it works fine let me give you the complete command i use

    I still think there is a class path issue
    .
    i think that too ..
    the measure i have taken to solve class path issue was
    i have included classpath = .;c;C:\Users\Admin\Desktop\JTextPaneDemo\dest\java -jar JTextPaneDemo.jar
    but didnt got success

    Maybe it's not in the CLASSPATH environment variable,

    i m setting the classpath (stated above)in the environment variable only
    under user variables for admin

    but some library you put in the /lib/ext sub folder of the JRE installation.

    i have not putted any lib in this project nor in at the installation time of JRE

    On the other hand, the cause could be something completely different. Perhaps you're trying to read from a file that doesn't exist on the laptop, or you have no rights to read that file. Likewise for writing a file or creating a directory


    i m admin so this should not be the case .
    i have full writes rwx
    or 777 in unix words
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    Nobody seems to have mentioned yet that "java -jar something.jar" ignores any classpath settings, except for those specified as "Class-Path" entries in the jar's manifest.
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    Paul Clapham wrote:Nobody seems to have mentioned yet that "java -jar something.jar" ignores any classpath settings, except for those specified as "Class-Path" entries in the jar's manifest.

    so you mean i need to set the classpath in the menifiest file inside the "something.jar"
    which is empty for now
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    Paul Clapham wrote:Nobody seems to have mentioned yet that "java -jar something.jar" ignores any classpath settings, except for those specified as "Class-Path" entries in the jar's manifest.

    so no answers i guess , now i m thinking making jars for distributing the code is a hell ,
    it could run or not depends on the destiny of the end user ...lol
    i guess exe is much better options for windows platform
    Henry Wong
    author
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18714
        
      40

    naved momin wrote:
    Paul Clapham wrote:Nobody seems to have mentioned yet that "java -jar something.jar" ignores any classpath settings, except for those specified as "Class-Path" entries in the jar's manifest.

    so you mean i need to set the classpath in the menifiest file inside the "something.jar"
    which is empty for now


    That depends. Does your jar files depend on external jar files (or any external classes)? If it does, then yes, you need to have those jar files also copied over to the other machine, and your jar files needs to reference it.

    If it doesn't, then empty "Class-Path" should be fine.

    Henry


    Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 692

    Henry Wong wrote:
    naved momin wrote:
    Paul Clapham wrote:Nobody seems to have mentioned yet that "java -jar something.jar" ignores any classpath settings, except for those specified as "Class-Path" entries in the jar's manifest.

    so you mean i need to set the classpath in the menifiest file inside the "something.jar"
    which is empty for now


    That depends. Does your jar files depend on external jar files (or any external classes)? If it does, then yes, you need to have those jar files also copied over to the other machine, and your jar files needs to reference it.

    If it doesn't, then empty "Class-Path" should be fine.

    Henry

    k , but any way the jar is not running from double click and runs fine through cmd with the fully qualified path to the jar files (absolute path)
    Henry Wong
    author
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18714
        
      40

    naved momin wrote:
    so no answers i guess , now i m thinking making jars for distributing the code is a hell ,
    it could run or not depends on the destiny of the end user ...lol
    i guess exe is much better options for windows platform


    Just because the distribute is different, doesn't mean that one is easier than the other.

    You have this same exact issue, if you try to distribute a DLL, and it depends on an external DLL. You still need to copy dependent DLLs over, and have them in your library paths.

    Henry
    Henry Wong
    author
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18714
        
      40

    naved momin wrote:
    k , but any way the jar is not running from double click and runs fine through cmd with the fully qualified path to the jar files (absolute path)


    On the same machine? Easily. If the command line environment and the windows environment are configured differently -- and depending on what you application is doing, it could be anything.... I recommend writing a quick and dirty script that dumps all the environment variables and see what is different. That should give you a place to start to look.

    On a different machine? Easily times ten. Different software packages installed. Different versions installed. Different OS version. Different hardware configurations. Different hardware. etc.

    Henry
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: jar runs on desktop but not laptop