Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trouble Understanding Basic Concepts

807601Mar 28 2008 — edited Mar 31 2008
Hi all, I am having trouble wrapping my head around a few basic concepts and I was hoping for some for some pointers. Not necessarily any 'howto' type advice, but really more help understanding a few of the basics.

The impetus of this post was the failure of my .jar file to run outside my IDE (Netbeans - but that doesn't matter here I think). The error I got was this:
Exception in thread "main" java.lang.NoClassDefFoundError: mainWindow
   at java.lang.Class.initializeClass(libgcj.so.8rh)
Caused by: java.lang.ClassNotFoundException: javax.swing.GroupLayout not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:Castle.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
   at java.net.URLClassLoader.findClass(libgcj.so.8rh)
   at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.8rh)
   at java.lang.ClassLoader.loadClass(libgcj.so.8rh)
   at java.lang.ClassLoader.loadClass(libgcj.so.8rh)
   at java.lang.Class.forName(libgcj.so.8rh)
   at java.lang.Class.initializeClass(libgcj.so.8rh)
My basic understanding of this error is that because I am trying to run the app outside the IDE I need to supply it will all of the libraries and whatnot that the IDE made available to it. In other words, there needs to be a 'library' folder with javax.swing.GroupLayout in it, and whatnot. According to the documentation that came with my IDE, the library folder should be provided automatically when I build and run the project, so I do not understand why it is not. But more than that, I do not understand why the necessary libraries are not "rolled into" (not a technical term) the jar file or executable file in the first place? This leads to other questions:

Should the library folder be alongside the jar archive (less elegant) or inside the jar archive (seems better since the client would only be seeing your jar file, which -HOPEFULLY is double-clickable)?

Does Java have the convenience of an .exe equivalent? My understanding is that other programming languages have an end product that is some executable file that end users can just double click to use the app you wrote for them. They do not have to worry about unpacking anything or making sure there are libraries to go along with the application. In the java way of doing things, as far as I can fathom, the equivalent of the .exe is the JAR file, which isn't really an executable at all but rather an archive file with all of your classes and libraries and meta-info inside it. Which if your file associations are not correct, you will not be able to run by double clicking on it. (I suppose this is also true of the .exe - the difference is that the .exe will just fail to launch and give an error, while a JAR file might open revealing more content archived inside).

Next, if you send your JAR off to a client, and they decided to look inside (regardless of their file association's) will they not have access to your class files? And thus your source code? If the required libraries are not compiled into the executable, and are custom libraries, would they not have access to those?

I guess that is all for now. I am going to continue figuring out why my IDE isn't providing the library folder so my apps can run outside the IDE. Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2008
Added on Mar 28 2008
4 comments
132 views