jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Serializing/ Importing Packages/Classpath issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Serializing/ Importing Packages/Classpath issues" Watch "Serializing/ Importing Packages/Classpath issues" New topic
Author

Serializing/ Importing Packages/Classpath issues

Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
I'm not exactly sure how to ask this question (which is probably why I can't figure out the answer), so here goes nothing. I have the following architecture in my application:

So basically, the user side is able to write data, update data, manipulate data, etc. The administrator side can view the data, but otherwise can't touch it. In the user side, I have a class that serializes the data objects on the user side, and I need to be able to deserialize them from the administrator side so that I can view them. And this is where my design breaks down. On the admin side, I am trying to add a classpath to the class which deserializes my data. It's relatively easy to do so by right clicking on the project name, and then adding the folder, but then no combination of imports seems to wrok properly. I can import the package fine, but when I go to use one of the classes within the package, the app will throw "class not found" errors.

I can also move a copy of the package into the same directory as the admin package, but then the class used to deserialize is not the same one (in the same place structurally as the one that serialized the class). I know how to import between packages within the same directory, but I am having issues when the packages are in deiiferent directories.

Can anyone clarify what question I am trying to ask? Or is my design flawed in some way that I am not seeing? Or is it just time for me to step back for a day or two until I can see the problem.
[ January 23, 2006: Message edited by: Chad Clites ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

It sounds like you are simply having problems with your classpath. Can you sketch out your package structure and names for us? Since this has nothing to do with IO in particular, I'm going to move it to Java In General - Beginnner.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Are you getting compiler errors or run-time errors? Either way, you should post the full error message along with the code where the error occurs. Also post any additional information that may help us understand what your code is doing.

Layne


Java API Documentation
The Java Tutorial
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Thanks for moving this to the proper place. I did finally come to the realization that it was a classpath issue, so at least that was confirmed. Here is how my directory structure is situated:


The ClientSide package has the serialize/deserialize application that I need to get to (plus a couple of others, but if I can get to one, I can get to the others).

What I initially did was in my AdminSide project, try to set the ClientSide as a source package folder. It throws "Package Folder already used in project. One package folder can only be used in one project, etc. etc." I poked around in the java docs and could not find exactly why the issue is the way it is, but ok.

So I then decided that I should take my serialization file and simply create a Library class accessible to both packages. So now my new structure looks like this:

In the ClientSide project, and AdminSide project, I have added utility.jar as a library. Now I am going back and altering the couple places where I need to declare the import. So if I do import Utility.*; I get "Package Utility does not exist". So I am either adding the library in the wrong place, or I created the library incorrectly, or I totally am off the mark.
[ January 24, 2006: Message edited by: Chad Clites ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Originally posted by Chad Clites:
It throws "Package Folder already used in project. One package folder can only be used in one project, etc. etc." I poked around in the java docs and could not find exactly why the issue is the way it is, but ok.


That sounds like a problem with your IDE, not Java. I recommend that beginners use a programmer's editor like JEdit because it is MUCH easier to write Java code in a text editor and compile it on the command line than to figure the nuances of an IDE. If you don't know how to use it properly, an IDE just helps you get in to trouble quicker.

Originally posted by Chad Clites:

So if I do import Utility.*; I get "Package Utility does not exist". So I am either adding the library in the wrong place, or I created the library incorrectly, or I totally am off the mark.


My guess here is that you are either putting things into the Utility.jar file that do not have the package name Utility (the JAR file name doesn't matter, it's what's declared in the class that matters) or, if your classes are declared as "package Utility", you are not setting up your IDE to find the Utility.jar file.
Clear your head and spend a few minutes with the Java tutorial page on packages.
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
It may very well be an IDE issue. I've been using NetBeans for a few years now, and I just hopped up to the Beta 5 version, so perhaps there is some subtlety that I am missing. I am more inclined to believe that I am building my jar file incorrectly though. The more I think about this though, the more I am convinced that my current approach to the program structure is not correct anyway.
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
PArdon the double post, but just for the sake of possibly helping someone else out...

When I created my library, I didn't put the .java files into a package. So when I was tying to import them, I was trying to import them using the top level of the directory in which they were located. Once I put them in a package within the directory and built my .jar file, it worked perfectly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializing/ Importing Packages/Classpath issues
 
Similar Threads
More stinkin' package questions...
compiling interdependent classes and packages
Help on the Head First book
compiling interdependent classes and pachages
.jar file error opening zip file: Can anyone pinpoint my problem?