• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Directory, File, Jar input problem

 
Ronnie Coh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've written a program that reads files from vaious locations on my drive to populate JComboboxes. It works file when I run the program through an IDE, but when I Jar the Classes it will not work.

Here is an example:

cboCrop = new JComboBox();
String line = null;
BufferedReader br =
new BufferedReader(
new BufferedReader(new FileReader("C:\\Test\\Data\\Jclimate.txt"));
while ((line = br.readLine()) != null)
{
cboCrop.addItem(line.substring(3, 3 +12));
}


Any suggestions will be appreciated. Thanks...Ronnie
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'will not work' isn't precise enough.

Is there a general 'catch (Exception e)' clause, which is silent as the grave of the dead programmer ({})?
 
Ronnie Cohen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that it will not find the file when I run the program in my JAR.

Thanks.
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are getting a ClassNotFound exception?
In order to find a class file within a jar, either the classpath has to contain the jar file:

Or you create an executable jar and run it with the -jar flag:
 
Ronnie Coh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, ClassNotFond Exceptions. The program just hungup. I managed to get it to work by putting the Data and Text files outside the Jar in the same foldre as the jar.

Not the Jar will not finded the two Jars that war included in the jar. I uded a Manifest file file:

Main-Class: folder.program
Class-Path: folder.jarone.jar folder.jartwo.jar

But it will not find the two jars. Any ideas? Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic