• Post Reply Bookmark Topic Watch Topic
  • New Topic

Distributing my first Java program  RSS feed

 
Ian Taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so I've written my first real Java program. It is a JPanel application and it runs just fine from Netbeans, which is where I wrote it. The problem is that when I build the program into a .jar file, I then can't get it to run. If I double click on the file nothing happens (although an instance of the javaw process starts as it appears in task manager). If I open a command prompt and try to run it from there (with the javaw command), it just returns to the command prompt with no error message. If I use the java command it runs the program and gives me an I/O error (which I assume is because a JPanel can't run inside a command prompt).

Any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set up the manifest correctly?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that you aren't getting any error messages because you wrote code which ignores error messages?


 
Ian Taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Did you set up the manifest correctly?


I'm sorry I don't really know what that means, I'm a bit of a newbie

I set the main class of the program in the properties if that's what you mean. What else would I need to do?
 
Ian Taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Is it possible that you aren't getting any error messages because you wrote code which ignores error messages?




I wrote code to handle I/O errors and Input Mismatch errors, both of which should display in the output area. I didn't attempt to catch any other errors.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InputMismatchException??

When I looked in the API docs they told me it was thrown by a Scanner. What's a Scanner doing in your Swing application?
 
Ian Taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:InputMismatchException??

When I looked in the API docs they told me it was thrown by a Scanner. What's a Scanner doing in your Swing application?


Um... good point. I originally wrote the program as text only and then converted it to a Swing app as I learned more. The method processing IME errors is still in there, but you've just made me realise it no longer actually does anything, thanks!

Baer - Cheers, I'll check out that link tomorrow when I have some time.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you aren't getting any error messages when you run the jar from the command line (um, you did mean "javaw -jar yourJar.jar", right?) then that means your application starts and then terminates normally without doing anything.
 
Ian Taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, my head is now spinning with manifest files and classpaths and entry points and stuff like that. Nothing really worked, so I created a much more basic JFrame app as a test and that seems to run fine.

After more investigation, I think the problem is with the text files I am using in my app. When the program starts it reads values from various text files and adds them to arrays as a rudimentary form of saving data. But with a jolt of 'duh' I just realised that now the program is compiled into a jar file the file paths contained within the program will all be wrong, causing an I/O error. I have checked the contents of the jar file and the text files are still there, in the same folder as in the file system, but it is no longer finding them when they are accessed within the program.

How do relative file paths work when you are running an app from a jar file? What path do I need to use to access them?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!