Results 1 to 11 of 11
  1. #1
    gradStudent is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default Help Needed to import package

    Hi, I am developing a JAVA project following Graphical Editing Framework in Eclipse.
    I have 3 packages ( in order of build) - ProcessModel, Process Editor and Application.
    I am trying to import application package and use its class in Process Model.

    package cheme.ProcessModel.Interpreter;
    import cheme.Application.*; // I have tried importing one class also

    But I am getting compile time error " the import cheme.application can not be resolved" .
    I assume this error is coming because Application package and its classes are not compiled and hence it is not allowing me to import and use them.

    I have added the CLASSPATH variable with the folder address of Application package but no success.

    Please help me and let me know how can I use the class of Application package in Process Model.

    Thanks a Bunch in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Your question has me a bit confused, sorry. Have you tried compiling the classes that the current classes depend on yet, and if not what prevents this? If this class is not yet complete, you could either create a skeleton class of unimplemented methods or (and I like this best) create an interface for the class needing to be imported and import that. Best of luck.

  3. #3
    gradStudent is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default

    thanks for your reply.
    All the methods in both the packages are complete.
    I tried importing the whole package itself without using any of the classes to test if problem is with a particular class or whole package.

    Build order is ProcessModel -> Application.

    On import it gives compile time error. I am also confused that what should I do. I have tried playing with project properties also. But of not much help.

    Can you suggest something on what should i try to make it work.

    Thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that you should try to create two HelloWorld.java type classes in two different packages and try to import one into the other. Get this working on the most basic level possible. If this doesn't work, then please post your code here and tell us exactly how you're trying to compile them. Best of luck.

    Here are my program examples:
    Java Code:
    package package1;
    
    public class HelloWorld1 {
      public static void helloWorld() {
        System.out.println("Hello World from package1");
      }
    }
    Java Code:
    package package2;
    
    import package1.HelloWorld1;
    
    public class HelloWorld2 {
      public static void main(String[] args) {
        HelloWorld1.helloWorld();
      }
    }
    Last edited by Fubarable; 08-11-2009 at 01:34 AM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You know that even if the first package's java files are not yet compiled, the compiler should compile them as it compiles the Java file that depends on the first file.

    In other words, if neither of my HelloWorldX.java files have been compiled, if I compile HelloWorld2 in package2 with:
    C:\........ (etc)....>javac -cp . package2\HelloWorld2.java
    then both HelloWorld2.java and HelloWorld1.java get compiled since 2 depends on 1.
    Last edited by Fubarable; 08-11-2009 at 01:44 AM.

  6. #6
    gradStudent is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default

    Hi.. Thanks a bunch for detailed explanation....

    Actually my packages are in different projects as well. I ma sorry I should have mentioned this in first place.

    So I have two different projects in my workspace and I am trying to import package from one project to another.
    I have also included the package's folder path in the build path of the target project.

    but it is not working.

    Regarding your snippet...it will definitely work... as in Java there is no need of forward declaration like in C++ :)

  7. #7
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    I'm guessing that you haven't set the path correctly. If you are using Eclipse, right click the project that you are importing to, find build options/build path (sorry, don't have Eclipse running right now), and click link source. Find the source folder that contains the package you want, and link it. You could also link a folder (Right click, New->Folder and under advanced check link folder to folder on filesystem) in the project to the package you need.

    Hopefully this helps,
    Singing Boyo
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  8. #8
    gradStudent is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default

    Hi Singing Boyo

    I have tried this..but it is not working with me...

    Thanks for your comment.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by gradStudent View Post
    Actually my packages are in different projects as well. I ma sorry I should have mentioned this in first place.

    So I have two different projects in my workspace and I am trying to import package from one project to another.
    I have also included the package's folder path in the build path of the target project.
    This still should work, but I think that you'll need a more detailed bit of information in the javac line after -cp. here you'll likely need the full path to the project that is not currently on the class path. You'll also need the lone period "." but separating all classpaths with semicolons.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Fark! I didn't see the part about using Eclipse. Have you gone to the Properties setting of your project, the one importing the classpath? If not, right click on the project, click on properties, click on "Java Build Path", then click on Projects and add the one project into your other project.

  11. #11
    gradStudent is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default

    When I try to add a project thru build path I get an error " Cycle detected'.
    This is becoz a is trying to use b and b is using A.

    I tried other things like adding the project in library and in order and export tab.
    But nothing is working in this case.
    It is getting more challenging than I thought :(

    Thanks for your input

Similar Threads

  1. Gwt how to import external gar?
    By trust in forum Web Frameworks
    Replies: 2
    Last Post: 07-14-2009, 05:31 AM
  2. can any one help?? how to import library
    By libish in forum New To Java
    Replies: 5
    Last Post: 02-12-2009, 07:51 AM
  3. How to import a package in Eclipse?
    By naipulb in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 12:04 PM
  4. Replies: 2
    Last Post: 03-31-2008, 06:11 AM
  5. import statement.
    By diRisig in forum New To Java
    Replies: 2
    Last Post: 02-08-2008, 01:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •