Solved

.jar File Can't Find Main Class - Newbie

Posted on 2009-06-29
5
632 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
  • 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 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now