Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing  RSS feed

 
Alec Porter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been wrapping my brain around this trying to understand how this works but I need some clarification. There is a couple of things I'd like to know. First say I have a file(package) with my class/java files in it, how would I use this file amongst other projects with out having to copy the folder for every project? I would like to do this because in case I have to update the files with out having to change multiple ones. How would I got about importing these files?

Also how come I can't put the class file and the java file together when making a package?or can I? This makes it unorganized for my java files in the top level of directories.

I've got books on this and I've read them over but this is the one thing at the moment that just doesn't make sense to me. I don't know how to get all my files to work together and be able to be accessed and still be organized.

Like say I have a folder and two folders inside a and b how can you access files in a from b? Unless your java files are in the main folder and classes are in the subdirectories then I don't know how, if I do this then I just makes the java files all piled up where as I would like them to be organized.

I'm sorry if I'm not being clear, its hard for me to explain so if something doesn't make sense or needs elaborating then I will. Thanks!
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the reuse of class files: usually you don't reuse a single class but a bunch of them at once. But in both cases it is as easy as adding them to the classpath.

Regarding java and class files together: Usually you want to separate the java files from the class files using the -d argument of javac. However the default is that the compiled class files will be created in the same directory in which the java file is.

Regarding importing: just add an import statement to your code. If the classpath has been set right then javac will get the file from the right location.
 
Alec Porter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote: However the default is that the compiled class files will be created in the same directory in which the java file is.

I'm using JCreator and by default it doesn't do that and I don't know how to change it.

Anyway, I've just decided to copy the file into each project, and now I'm getting this error

"class file contains wrong class: Shared
Please remove or make sure it appears in the correct subdirectory of the classpath." I'm not sure what this means.
But if I move the file up and compile it, it puts the class file in the lower directory where it should be anyway. So is this because the class files always go one directory lower and if so how do I change this?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IDE's will mostly add the -D parameter for you and I don't think it is possible to change that. Did you copy the java-file into a directory with only compiled classes?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!