Results 1 to 8 of 8
  1. #1
    Tavern_Walker is offline Member
    Join Date
    Jul 2014
    Posts
    4
    Rep Power
    0

    Default NetBeans package help please

    Hi all,
    My first post and I need help please. I've googled for hours and can't figure this out.
    If I have project1 inpackage my.project1, then I create project2 in package my.project2. I'd like to use a class from project1 in project2 so I thought I could say:
    import my.project1.*;
    in project2.
    But NB keeps saying my.project1 does not exist.
    I've been reading all over the place about a zillion ways to add libraries and jar files etc., but I'm new to this and everything I try doesn't work. Do I need to create a jar out of project1?
    When I try to add project1 to project2 via like right click Libraries in project2, and select project1 NB says "This project cannot be added because it does not produce a JAR file using an Ant script".
    Please, I'd love some advice. Thank you,
    TW

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: NetBeans package help please

    What are project1 and project2? Are they netbeans projects? Classes? Directories? Something else? Post a screenshot of your directory structure.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tavern_Walker is offline Member
    Join Date
    Jul 2014
    Posts
    4
    Rep Power
    0

    Default Re: NetBeans package help please

    Sorry, that info would help wouldn't it. I'm working on an example in my JHTP 9 textbook, "project1" is my Reservation project which is a web service. "project2" is my ReservationClient project that is supposed to consume the Reservation service.
    NetBeans package help please-1.png
    Project Reservation has package com.deitel.reservation and that is what NB is telling me doesn't exist.
    Thank you

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: NetBeans package help please

    In other words: you didn't tell Netbeans that your Reservation project needs to be on the classpath of your ReservationClient project. Just because both projects happen to be open in your project view, does not mean that they can magically see each other's classes. Either you missed that bit of configuration in your book, or your book is missing a page.

    https://blogs.oracle.com/roumen/entr...k_tip_16_using
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tavern_Walker is offline Member
    Join Date
    Jul 2014
    Posts
    4
    Rep Power
    0

    Default Re: NetBeans package help please

    gimbal2 that is exactly the approach I took when I get the error message I stated above.
    I right-click on ReservationClient, click Properties, select Libraries, click Add Project, select my Reservation project and click Add Project JAR File:

    NetBeans package help please-2.png

    and get:

    NetBeans package help please-3.png

    Is it because it's a web service and not a desktop application?

    *EDIT* I did some more experimenting. I can import packages from Java Applications but not from Java Web Services. Does anyone know how to do this?
    Last edited by Tavern_Walker; 07-30-2014 at 09:24 PM.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: NetBeans package help please

    Oh very sorry, there are so many clueless posts today that I'm starting to assume the worst everywhere; you do not deserve that.

    I see that Reservation has a 'web pages' entry, I guess it is a web project then? That will produce a war, not a jar so you cannot link that as a project jar. Whatever classes you want to share between the two projects, you will need to put in a third project which WILL build as a jar. Called it a 'model' project or something.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tavern_Walker is offline Member
    Join Date
    Jul 2014
    Posts
    4
    Rep Power
    0

    Default Re: NetBeans package help please

    Hmm, I've got to be missing something here. Why would the book provide such an example? It's got to work, I've got to be missing something.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: NetBeans package help please

    Possibly, perhaps you used the wrong project type. 'Web application' instead of 'web service' or something. Its an easy mistake to make.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. package does not exists - netbeans
    By emosms in forum New To Java
    Replies: 9
    Last Post: 08-22-2013, 06:37 PM
  2. Replies: 2
    Last Post: 03-26-2013, 06:07 PM
  3. Replies: 3
    Last Post: 03-27-2012, 09:27 AM
  4. Package Problems in NetBeans IDE
    By farmer in forum NetBeans
    Replies: 2
    Last Post: 08-24-2011, 06:35 PM
  5. NetBeans losing package information when crashing
    By Kethas in forum New To Java
    Replies: 4
    Last Post: 03-03-2010, 05:38 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
  •