Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default eclipse and user made library

    Helllo all I hope sommeone can help me.

    I am learning Java on my own from the book Thinking in java vol4,, The author has a set of of Files with the .java extention so they are source code. Here is an example of one of them.

    Java Code:
    //: net/mindview/util/Print.java 
    // Print methods that can be used without 
    // qualifiers, using Java SE5 static imports: 
    package net.mindview.util; 
    import java.io.*; 
    
    public class Print { 
    // Print with a newline: 
    public static void print(Object obj) { 
    System.out.println(obj); 
    } 
    // Print a newline by itself: 
    public static void print() { 
    System.out.println(); 
    } 
    // Print with no line break: 
    public static void printnb(Object obj) { 
    System.out.print(obj); 
    } 
    // The new Java SE5 printf() (from C): 
    public static PrintStream 
    printf(String format, Object... args) { 
    return System.out.printf(format, args); 
    } 
    } ///:~

    There are 33 of these files all for different purposes, used in different chapters in the book.

    I have been able to add one to a project and make it work but then the next time I try the exact some thing it does not work.
    At the beginning of his code he calls it a package, so using his terminology, how do I add all of these packages to eclipse so that they will all be there when I need them and I dont have to go through a ton of steps that may not work every time I write a project that may only have 10 lines of code.
    it would also be nice for them to be loaded into eclipse at start up.

    I am running windows Vista and my version of eclipse is
    Version: 3.7.1
    Build id: M20110909-1335

    Any help would be greatly appreciated.

    Walkswithzombies

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: eclipse and user made library

    So, if you want to write down and use later those 33 files, why don't you use packages? If you organize your files in this way, you can use them later with import statement directly from your code and not only within eclipse... Google a little about packages. For example: Java Package Tutorial (English version)

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: eclipse and user made library

    Moving to the Eclipse section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: eclipse and user made library

    Thank you for the Java package tutorial link, even though it has nothing to do with ECLIPSE.

    I have been dealing with this problem for four days, I did not just run in to it and then run here for help. I have tried the classpath and I have tried imports and several other things to get these packages to work, but they do not work properly.

    I get one imported into a package in the current project and it will work, then I try the exact same thing in a new project and it does not work, or I get one of the packages to work and then try to add another and it wont work.

    I need to know how to get them into ECLIPSE so they will consistently work for me, the book I am using is 1400 pages and I dont want to fight this for the next 1300 pages, unfortunately the author did not use eclipse so there is no help from the book. I have done many Google searches on libraries and thinking in java and packages and imports and static import and everything else I could think of.

    Please help I am becoming very frustrated.

    Walkswithzommmbies

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: eclipse and user made library

    Stick the code from the book into its own project.
    Use Eclipse to create a jar file.
    Include that jar file in your second application (usually in a lib folder).
    Add that folder into your project.

  6. #6
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: eclipse and user made library

    Quote Originally Posted by Tolls View Post
    Stick the code from the book into its own project.
    Use Eclipse to create a jar file.
    Include that jar file in your second application (usually in a lib folder).
    Add that folder into your project.
    I have tried that I was able to make a Jar file out of all of the the different package files and then I tried to add them into the project as a Lib but It still does not work.

    I also tried to add the .jar to the build path and that did not work.
    Always when I type the print() command eclipse IDE say that:::The method print() is undefined for the type I have also removed the static from the the Import static ney.mindview.util.* The Eclipse IDE still says:::::the import net cannot be resolvedI like eclipse and want to keep using it but maybe I am too dumb for it, I think there must be an easy way to make this happen but I cant figure it out..

    any other Idea or instructions???

    Thanks
    Walkswithzombies

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: eclipse and user made library

    SHow us the code where you are getting the error, and the full error text.
    If you have added the jar file with the compiled classes then I suspect yuour code has a mistake in it.

  8. #8
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: eclipse and user made library

    Quote Originally Posted by Tolls View Post
    SHow us the code where you are getting the error, and the full error text.
    If you have added the jar file with the compiled classes then I suspect yuour code has a mistake in it.
    ok here you go hope this helps.

    Java Code:
    import java.util.*;
    //
    import net.mindview.util.*;// The Error on this line is:  "The import net cannot be resolved"
    public class Testing {
    
    	
    	public static void main(String[] args) {
    		System.out.println("this is the line the next one is supposed to replace");
    		print(" does not work");// the error on this line is:     "The method print(String) is undefined for the type Testing"
    	}
    
    }
    When I run this program in the Eclipse IDE it gives this error:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method print(String) is undefined for the type Testing

    at Testing.main(Testing.java:10)


    This is has been killing me I have tried everything to make this work, If you dont see anything wrong here maybe you could tell me how to get these .java files loaded into eclippse or my project I donnt know now.

    Thanks for your time.

    Walkswithzombies
    Last edited by walkswithzombies; 02-10-2012 at 12:27 AM. Reason: code tags did not work

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: eclipse and user made library

    Does the jar file contain .class files, or .java files?
    It should be the class files (or both).

    That first error shows that the jar file (assuming the jar is correct) is not visible to the compiler (ie the project).
    What does your "configure build path" show for the project?
    Your jar should appear in the Libraries tab.
    If it's not there then it needs adding.
    If it is there then the jar file is incorrect.

    As for the second problem, even if you had the jar in place properly that would still give an error.
    A static import looks like:
    Java Code:
    import static net.mindview.util.Print.print;

  10. #10
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: eclipse and user made library

    Quote Originally Posted by Tolls View Post
    Does the jar file contain .class files, or .java files?
    It should be the class files (or both).

    That first error shows that the jar file (assuming the jar is correct) is not visible to the compiler (ie the project).
    What does your "configure build path" show for the project?
    Your jar should appear in the Libraries tab.
    If it's not there then it needs adding.
    If it is there then the jar file is incorrect.

    As for the second problem, even if you had the jar in place properly that would still give an error.
    A static import looks like:
    Java Code:
    import static net.mindview.util.Print.print;
    I added the .jar to the build path and I changed the import statement and I am still getting the same errors in the same places. so I would guess that you are correct about the .jar file being bad. I made it just by guessing my way through it so I prolly screwed it all up.

    I dont want to be a huge bother or a help vampire, but couldd you point me to instructions on how to make the jar file with the .class files in it.

    Thank you very much.
    Walkswithzombies

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: eclipse and user made library

    I'd look up the Eclipse documentation.
    There should be something in the help drop down.

Similar Threads

  1. Reading a user made text file?
    By nhmllr in forum New To Java
    Replies: 6
    Last Post: 01-13-2012, 08:23 AM
  2. setting java.library.path through eclipse and maven
    By shivamfet in forum New To Java
    Replies: 0
    Last Post: 12-19-2011, 07:24 AM
  3. Arrays made from user input
    By sonofJack3 in forum New To Java
    Replies: 15
    Last Post: 12-01-2011, 06:18 AM
  4. Replies: 1
    Last Post: 08-07-2011, 02:35 AM
  5. Which Eclipse should I use (mac user)?
    By kracer in forum Eclipse
    Replies: 1
    Last Post: 05-21-2010, 01:46 AM

Tags for this Thread

Posting Permissions

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