Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.jar File Can't Find Main Class - Newbie

Posted on 2009-06-29
5
Medium Priority
?
672 Views
Last Modified: 2013-11-23
Hello All,
I will warn you up front that I do not know java and am learning it only to support some interfaces that were written by a previous co-worker, so I apologize in advance for my lack of knowledge.

To my knowledge, my co-worker used Eclipse when building these interfaces.  I do need to make some changes to them, but overall they have been running fine.  However, we recently received new workstations and now the .jar files won't run and produce an error saying that they can't find the Main Class.

I have ensured that the path on the new computers contains the path to the java folder but am not sure what else to look for.  After more investigation, it looks like the interface files only ever did run successfully on a handful of pc's, but I have no idea what my co-worker may have done to these to get them to work.  For the most part, my new pc has the same software as my previous one (which was able to run the interfaces).

I know that this is really open-ended, but what could the jar file be needing that is external to itself?  From my (albeit limited) understanding, the .jar file should 'stand alone'.  We can still run the .jar files on the 'old' computers and they work fine.  We are running them from a shared network drive, so the interfaces themselves have not changed, just the pc's.

Thanks.
Carmen
0
Comment
Question by:SysApps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 24736977
Java finds things using the classpath (not the PATH). There are various ways of making the JVM aware of what classpath you want it to use. Arguably the most simple and straightforward one is to specify it in the command line (usually "-classpath"). A jar file can also be specified as part of the class path as if it was a directory to search.
0
 

Author Comment

by:SysApps
ID: 24737429
How do I know what classpath I want/need it to use?  There is a ClassPath.class file within the .jar file.
Interface-zipfile.doc
0
 
LVL 16

Accepted Solution

by:
imladris earned 750 total points
ID: 24741351
The classpath normally specifies the directory in which the class files are found or, in the case of a jar, specifies the .jar file itself.

So, for instance, if the jar file is c:\system\time\punch.jar then you would add:

-classpath c:\system\time\punch.jar

as an argument to the java command that starts the program.
0
 
LVL 1

Expert Comment

by:sukalp
ID: 24744149
Either you could add that command to the command line or you could add it to the system wide Environment by ->
  For Vista,

1) Right Click on Computer in the Start Menu and then choose Properties.
2) Choose Advanced system settings from the list on the left.
3) Under the advanced tab, choose Environment variables.
4) Either add the CLASSPATH environment variable to the user variables or the system-wide variables as be your choice or if it already exists modify it to point to your files.
Click one the following options, for either a user or a system variable:
Click New to add a new variable name and value.

Click an existing variable, and then click Edit to change its name or value.
Click an existing variable, and then click Delete to remove it.

For XP,
Right-click My Computer, and then click Properties.
Click the Advanced tab.
Click Environment variables.

Click one the following options, for either a user or a system variable:
Click New to add a new variable name and value.

Click an existing variable, and then click Edit to change its name or value.
Click an existing variable, and then click Delete to remove it.

If this does not work, check your java command,
it should be java -jar <whatever> and also (if you are using one) if your jar manifest file is correct.


0
 

Author Closing Comment

by:SysApps
ID: 31597955
I tried all of the suggestions and it turned out to be something that we missed - there was an odbc missing, which others had supposedly checked for, but I guess you need to always double check yourself.

Thanks to all.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question