简体   繁体   English

Eclipse-我想从相同的程序包访问一个类,但是在不同的项目下,该怎么办?

[英]Eclipse - I want to access a class from the same package but under a different project, how?

I use Eclipse IDE for my Java projects and all my projects( Project_1 , Project_2 and so on) related classes are inside a package package_name . 我将Eclipse IDE用于Java项目,并且所有与项目( Project_1Project_2等)相关的类都在package_name包中。

I am currently working on 2 classes. 我目前正在上2节课。

class_name.java ( Project_2 / package_name ) class_name.javaProject_2 / package_name

utility.java ( Project_1 / package_name ) utility.javaProject_1 / package_name

All methods are public . 所有方法都是public How can I use the methods within utility.java in class_name.java ? 如何使用class_name.javautility.java中的方法?

You can create a jar file from the source package and import it in the classpath of Project_2. 您可以从源包中创建一个jar文件,并将其导入Project_2的类路径中。

1- Right Click on desired package -> Export -> JAR File 1-右键单击所需的软件包->导出-> JAR文件

2- Right Click on goal project -> build path -> Add external jar(or copy the jat file in lib folder of the second project and select the Add Jars in the Libraries tab of Java Build Path) 2-右键单击目标项目->构建路径->添加外部jar(或将jat文件复制到第二个项目的lib文件夹中,然后在Java Build Path的Libraries选项卡中选择Add Jars)

如果只有一个需要另一个,则可以使用一个项目(项目2)的Java Build Path属性页来让它要求另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入的类文件显示在Eclipse中的默认软件包下,我如何访问它们? - Imported class files are shown under default package in Eclipse, how can i access them? 如何引用同一项目中不同包中的类 - How to reference a class in a different package in the same project 如何在同一包中但在不同jar中访问父类的包本地字段? - How can I access package-local fields of parent class in the same package but in different jar? 从同一个Java(Eclipse)项目运行不同的类 - Run different class from same java (eclipse) project 如何从不同的类和包访问对象? - How to access an object from a different class and package? 我想访问同一类不同函数中的函数变量 - I want to access variable of function in different function of same class 如何在Java中同一包中的不同文件上从一个类访问另一个类的变量 - How to access a variable from one class into another class on different files in same package in java 来自相同类但方法不同的访问变量-Android Eclipse-App - Access Variable from the same Class but different method - Android Eclipse - App 如何在Eclipse中同一包下的一组类的包声明中更正? - How do I correct the package declaration for a set of classes under the same package in Eclipse? 我希望登录类从其他类访问数据库连接 - I want for the login class to access the database connection from different class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM