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?
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.
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?
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.
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.
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.
90% ??? I doubt it. Unless you are talking about students.
Unable to access jarfile MessageBoxCreator.jar
Ahem... Excuuuse me Mr Norm?
Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code
Can you explain where you got that message and what you were doing.Unable to access jarfile MessageBoxCreator.jar
Does the laptop run Windows? Did you do the steps I described in post #3? If not, please do.
Yes 90% when i do i google search there are 10+ pages with no one able to answer the question.
Yes. That is where the code came from, From CMD
java -jar MessageBoxCreator.jar
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.no one able to answer the question.
PLEASE COPY THE EXACT CONTENTS OF THE COMMAND PROMPT WINDOW AND POST IT HERE.
I would expect to see something like this:
I got this message because there was no asdfasdf.jar file.
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>
You must be in the folder with the .jar file!!!
Last edited by Norm; January 7th, 2012 at 04:43 PM.
I got the program to work, but when i got it to work i download jdk then it worked?
No, you do NOT need the JDK to execute jar files.
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.
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.I got the program to work, but when i got it to work i download jdk then it worked?
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.
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.
Which variables and what values did you give them?
Others with this problem would probably like to know.
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?
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.)
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.have to change the environmental variables to run jars
No.Users need the path
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.
Only thing ive personal added was java api in my jdk.
So Confused: I have
JDK
Jre6
Jre7
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
im using jdk?
My first Path:
PATH
C:\Program Files\Java\jdk1.7.0_02\bin