• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing an existing Java Package/Class into another Project. NetBeans 8.1 IDE  RSS feed

 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, folks, I finally got my MyClone.java file working.  Now, I have to incorporate it into a new Project called "Virtual World".  For some reason, NetBeans is telling me "package myclone does not exist".  I have compiled MyClone.java and there are no errors.  Am I not asking to import properly?

Thanks in advance!

Here is the code for the virtual world project:



The code from MyClone:
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyClone exists on my machine only, not on the internet.  I know how to import utilities, such as Scanner as well as other libraries.  I thought I knew how to import my own packages into new projects.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What format is MyClone? Is it a .jar file, or simple packages?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably in NetBeans there is a way to set the classpath for a project. Chances are that you didn't do that yet. It may be called something different than "classpath" but you should find it in the project's properties somewhere.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What format is MyClone? Is it a .jar file, or simple packages?


The extension is MyClone.java.  I'm really sorry if I'm not providing enough info.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I'm assuming that your package statement looks like this:

...and not this:

If that's not the problem, then maybe you have the two Java files in different Netbeans projects.  "Projects" are an IDE construct; they don't have anything to do with the Java language.  A "package" is part of the Java language.  In both Netbeans and Eclipse you can have packages in the same project.  If so, the IDE will create a classpath that includes the two packages.

If you have the Java files in different projects, then you need to tell the IDE that one project is included in the other.  In Netbeans you do this in the Project Properties (see attached image).  In Eclipse there is a similar capacity in the Build Path of the project.
AddProjectInNetbeans.png
[Thumbnail for AddProjectInNetbeans.png]
Add a Project in Netbeans
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Presumably in NetBeans there is a way to set the classpath for a project. Chances are that you didn't do that yet. It may be called something different than "classpath" but you should find it in the project's properties somewhere.


The Runtime Classpath is located on my C:\ drive.

My only other option is to copy the MyClone stuff into my virtual world project but I shouldn't have to do that-I should be able to import that.  Everything I've read says I can-Oracle docs, Horstmann, Big Java Late Objects, 1e (my textbook), several Java forums and YouTube videos.

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:The Runtime Classpath is located on my C:\ drive.

This doesn't make sense to me.  Either you have an environment variable called CLASSPATH (hopefully with nothing in it) or you have a classpath that is setup by the IDE.  (Or one can run Java with the -cp switch.)

My only other option is to copy the MyClone stuff into my virtual world project but I shouldn't have to do that-I should be able to import that.  Everything I've read says I can-Oracle docs, Horstmann, Big Java Late Objects, 1e (my textbook), several Java forums and YouTube videos.


There's nothing wrong with having two Java files in different packages in the same IDE project.  My previous post tells you how to link projects but if there is only two Java files, this is unusual.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:First, I'm assuming that your package statement looks like this:

...and not this:


Yes, I fat-fingered that.

Knute Snortum wrote:If that's not the problem, then maybe you have the two Java files in different Netbeans projects.  "Projects" are an IDE construct; they don't have anything to do with the Java language.  A "package" is part of the Java language.  In both Netbeans and Eclipse you can have packages in the same project.  If so, the IDE will create a classpath that includes the two packages.

If you have the Java files in different projects, then you need to tell the IDE that one project is included in the other.  In Netbeans you do this in the Project Properties (see attached image).  In Eclipse there is a similar capacity in the Build Path of the project.


So, I need to add MyClone to my Virtual World through the steps above.  And then I can import.

Thank you!
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:
Knute Snortum wrote:First, I'm assuming that your package statement looks like this:

...and not this:


Yes, I fat-fingered that.

Knute Snortum wrote:If that's not the problem, then maybe you have the two Java files in different Netbeans projects.  "Projects" are an IDE construct; they don't have anything to do with the Java language.  A "package" is part of the Java language.  In both Netbeans and Eclipse you can have packages in the same project.  If so, the IDE will create a classpath that includes the two packages.

If you have the Java files in different projects, then you need to tell the IDE that one project is included in the other.  In Netbeans you do this in the Project Properties (see attached image).  In Eclipse there is a similar capacity in the Build Path of the project.


So, I need to add MyClone to my Virtual World through the steps above.  And then I can import.

Thank you!


That worked! 
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!  Glad I could help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!