0

I created a java GUI application using java.awt. The basic idea off the app is to query a mongo database using the mongo-java driver.

When running the code from the command prompt, the GUI opens up and it can interact with the initialized mongod server just fine with no problem. However, when I create a jar executable with the same class, the GUI opens up fine, yet none of the server interactions seem to occur.

For instance, when running the non-jar version, the mongod server running in the background displays something along the lines of: Sat Dec 14 09:14:20.347 [initandlisten] connection accepted from 127.0.0.1:XXXX #5 (1 connection now open), yet when running the jar version (without making any changes to the source code at all, literally the same exact .java and .class files), I don't see any of the conection statuses on the server.


I doubt you need me to insert all my code into this post, but here are the details that I think are most relevant to my issue. Let me know if you need any other details.

when creating my jar I used the command:

jar cvfm MongoDBGUI.jar manifest.txt *.class

manifest.txt has the line:

Main-Class: MongoDBGUI

*MongoDBGUI being the class with the main function

Maxim
  • 725
  • 1
  • 8
  • 24
  • *"using java.awt"* Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Dec 14 '13 at 17:52
  • Oh, I understand VERY well why awt should be abandoned. I just started learning GUI's from scratch and I thought I would learn the very basics first. – Maxim Dec 14 '13 at 17:57
  • *" I just started learning GUI's from scratch and I thought I would learn the very basics first."* AWT is not 'the basics' so much as 'the obsolete'. It will ***not*** help in learning how to use Swing, and will be much harder, since the few people around these days who ever used AWT have largely forgotten the fine details. So to that I say: no, *no.* ***no!*** – Andrew Thompson Dec 14 '13 at 18:02

1 Answers1

2

My crystal ball says that you've been swallowing exceptions in your code, so when something goes wrong, you have no logging to tell you what the error was.

My tarot cards tell me that you don't have the driver packaged inside your jar, so the driver isn't found. But my ouija board claims that you do have the driver inside the jar, it's just not configured properly in the classpath in MANIFEST.MF.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • You might be right about the exception part, I didn't even consider giving that a try. But for the driver file part, wouldn't the GUI not even load because it would spit out some class not found error? – Maxim Dec 14 '13 at 18:03
  • *"it would spit out some class not found error?"* Not if it is being ignored by the code. – Andrew Thompson Dec 14 '13 at 18:15
  • What I meant was that if I tried running the program without the jar in my classpath, it wouldn't even run. In this case, the program is working...I'm just getting a run time error. Also, I have been tinkering with exceptions and I have noticed that the program just freezes at the connection stage, which doesn't happen in the "non-JAR" version. Does this help? – Maxim Dec 14 '13 at 18:28
  • Just read the Java tutorial for JAR and figured out how to define Class-Path in MANIFEST.MF – Maxim Dec 14 '13 at 18:49