Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 43

Thread: Jar file only Works on my computer?

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Question Jar file only Works on my computer?

    i made a jar file using only notepad, a compiler and jdk to make it into a jar
    it runs on my computer but it dosent run on my laptop? says it cannot find main class?


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Jar file only Works on my computer?

    You may find that this tutorial is helpful.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    Are the java versions at the same version?
    on the laptop, open a command prompt window, change to the folder with the jar file and enter:
    java -jar <THEJARFILENAME>.jar

    Copy the command prompt window and paste here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  4. #4
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    That didnt help, im doing it correctly, ive looked it up and 90% of people that are making java applications into jar files get the same error when transfecting the application throughout other users.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    90% ??? I doubt it. Unless you are talking about students.

  6. #6
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Unable to access jarfile MessageBoxCreator.jar

  7. #7
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Jar file only Works on my computer?

    Ahem... Excuuuse me Mr Norm?
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    Unable to access jarfile MessageBoxCreator.jar
    Can you explain where you got that message and what you were doing.
    Does the laptop run Windows? Did you do the steps I described in post #3? If not, please do.

  9. #9
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Yes 90% when i do i google search there are 10+ pages with no one able to answer the question.

  10. #10
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Yes. That is where the code came from, From CMD
    java -jar MessageBoxCreator.jar

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    no one able to answer the question.
    There are thousands of ways any code including code in a jar file can fail. The main problem is having the OP do EXACTLY what you tell them and report back what happened. Somehow they get distracted or ??? and do something differently and don't tell you all the details about what they did or what they saw.

    PLEASE COPY THE EXACT CONTENTS OF THE COMMAND PROMPT WINDOW AND POST IT HERE.
    I would expect to see something like this:

    Microsoft Windows XP [Version 5.1.2600]

    D:\JavaDevelopment\Testing\ForumQuestions7>java -jar asdfasdf.jar
    Unable to access jarfile asdfasdf.jar

    D:\JavaDevelopment\Testing\ForumQuestions7>
    I got this message because there was no asdfasdf.jar file.
    You must be in the folder with the .jar file!!!
    Last edited by Norm; January 7th, 2012 at 04:43 PM.

  12. #12
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Quote Originally Posted by Norm View Post
    Can you explain where you got that message and what you were doing.
    Does the laptop run Windows? Did you do the steps I described in post #3? If not, please do.
    Do you need jdk to run jar files in general?

  13. #13
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    I got the program to work, but when i got it to work i download jdk then it worked?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    No, you do NOT need the JDK to execute jar files.

  15. #15
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Jar file only Works on my computer?

    Quote Originally Posted by Java Programmer View Post
    Do you need jdk to run jar files in general?
    No. The jar file is an archive (a sort of zip file, in fact) containing java classes and other resources (images etc) a program needs. Packaged up in this way the program can be run just using the java executable, or a browser's java plugin.

    I got the program to work, but when i got it to work i download jdk then it worked?
    Sounds weird. But note expressions like "it worked" are somewhat vague. As Norm points out we need to see the exact command and its output. Also the manifest and contents (from dir) of the directory where you run it.

    At any rate the intention of jar files is that they should run anywhere that there is a compatible runtime. I always check them periodically just to make sure I haven't screwed up and not put resources into the jar file, or am accessing them wrongly. If you cannot run the jar on a machine with an uptodate runtime that is definitely a problem and you should deal with it. If necessary by describing it (and its context) here, fully.

  16. #16
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    I changed the Environmental variables on my other computer and it worked.
    while downloading jdk i did the same on my laptop and then it worked.

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    Which variables and what values did you give them?
    Others with this problem would probably like to know.

  18. #18
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    User:
    PATH - C:\Program Files\Java\jdk1.7.0_02\bin

    System:
    CLASSPATH - C:\Program Files\Java\jdk1.7.0_02\bin

    I want to release programs but i dont think people will be to happy if they have to change the environmental variables to run jars?

  19. #19
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Jar file only Works on my computer?

    The user will need to configure the PATH variable if they want the Java runtime to be run simply from the command line. In this respect it is no different to any other software that they want to run this way. (which explains the other entries you will have already seen on the PATH). As far as I know this just happens when the user installs the Java runtime on Windows, ie it doesn't involve any special action on their part.

    Neither the user nor you need set CLASSPATH to anything in particular. It is not necessary for the correct functioning of java.exe or any of the JDK tools: javac.exe jar.exe etc. In fact it can get in the way and I would recommend removing any setting that it has, unless other software you have installed depends on a particular value. In any case the setting you showed here (the JDK bin directory) is wrong and should be removed.

    The JDK bin directory is no place for you to be putting files. It's a place for the JDK executable files. (The same goes, in general, for the whole "Program Files" directory. Windows users aren't used to the fact that they should treat this as "read only".) If your program does depend on classes etc that you have put in the JDK bin directory you should move them and correct the program. (There is a slight exception to that if your program actually uses JDK resources like the java compiler. In that case the user will have to have the JDK installed, obviously. But the CLASSPATH still need not be set and should not be set to include the JDK bin directory.)

  20. #20
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Quote Originally Posted by pbrockway2 View Post
    The user will need to configure the PATH variable if they want the Java runtime to be run simply from the command line. In this respect it is no different to any other software that they want to run this way. (which explains the other entries you will have already seen on the PATH). As far as I know this just happens when the user installs the Java runtime on Windows, ie it doesn't involve any special action on their part.

    Neither the user nor you need set CLASSPATH to anything in particular. It is not necessary for the correct functioning of java.exe or any of the JDK tools: javac.exe jar.exe etc. In fact it can get in the way and I would recommend removing any setting that it has, unless other software you have installed depends on a particular value. In any case the setting you showed here (the JDK bin directory) is wrong and should be removed.

    The JDK bin directory is no place for you to be putting files. It's a place for the JDK executable files. (The same goes, in general, for the whole "Program Files" directory. Windows users aren't used to the fact that they should treat this as "read only".) If your program does depend on classes etc that you have put in the JDK bin directory you should move them and correct the program. (There is a slight exception to that if your program actually uses JDK resources like the java compiler. In that case the user will have to have the JDK installed, obviously. But the CLASSPATH still need not be set and should not be set to include the JDK bin directory.)

    So Users need the path and not the classpath?

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    have to change the environmental variables to run jars
    They don't. Something about your jar file has not been resolved. You've made a bunch of what I'd call random changes without really tracking down what the problem is/was.

    Users need the path
    No.
    Has the jre install changed? It used to put a java.exe file into one of the Windows folders so that is was on the PATH. There was no need to change the PATH variable because the java.exe was on the PATH.
    The JDK installation required a change to the PATH to put the javac.exe and other tools on the PATH.

  22. #22
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    Only thing ive personal added was java api in my jdk.

  23. #23
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    So Confused: I have
    JDK
    Jre6
    Jre7

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jar file only Works on my computer?

    Yes, it is possible to have more that one version of java on one computer. I have 3 or 4 and use a command line with a full path to pick the one I want to use.
    Which one is the first one on the PATH on your computer?
    java -version

  25. #25
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jar file only Works on my computer?

    im using jdk?

    My first Path:
    PATH
    C:\Program Files\Java\jdk1.7.0_02\bin

Page 1 of 2 12 LastLast

Similar Threads

  1. I have no idea how this works.
    By GeneralPihota in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 29th, 2011, 09:55 PM
  2. It works!!! eureka!!! Java...Day 12.
    By Spidey1980 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: August 18th, 2011, 09:41 PM
  3. GUI Only Works Sometimes
    By bgd223 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 12th, 2011, 08:08 AM
  4. jar file works on XP but not on Linux
    By cl2606 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 10th, 2011, 09:19 AM
  5. Making computer independent file path
    By Javabeginner in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 2nd, 2010, 03:56 PM