开发者

Java -- how do I access (import) the class files in a folder that is in the same directory as the src folder?

开发者 https://www.devze.com 2023-03-02 11:30 出处:网络
In eclipse or netbeans or emacs pico or microsoft word or notepad or or or whatever. Thanks. In eclipse, I\'m trying to share a package in one project w/ another project. I do the whole buildpath->li

In eclipse or netbeans or emacs pico or microsoft word or notepad or or or whatever. Thanks.

In eclipse, I'm trying to share a package in one project w/ another project. I do the whole buildpath->link source -> add source ... and it creates a linked directory but n开发者_如何学运维ot as package within the src/ dir, instead as a separate dir sibling to the src/. so I'm left stranded, wondering, waiting for a solution.


If you mean classes without a package, you can only refer from them outward, you can't refer from a class that is in a package to a class with no package declaration (A very good thing).

Even if you wanted to reference a class in the default package it would be in your "src" folder, not in the same directory as your src folder, so perhaps you mean something different?

Generally your "src" directory would contain a "com" directory--the top of the package tree. So if you had a class in the default package you would place it at the same level as "com", but as I said you can't refer to it from other code--you can only execute the unpackaged class from the command line.

If you are saying that you want all your classes in the same directory or something--then I recommend packaging them all together as a .jar file.


Normally you would add the project (with classes you want to share) to the Build Path (right-click>Build Path>Configure Build Path) of the consuming project. That allows you to compile and run within eclipse.

If you want to create a link from one project to the place where the other project code lives, you have to create your linked folder in such a way that 1) it's already in the /src/ folder or 2) can be turned into a source folder and can see the full package structure necessary to compile your classes. But that is not how most java projects consume the output of another java project.

0

精彩评论

暂无评论...
验证码 换一张
取 消