我在努力學習更好地理解Maven的用法。 我對使用多個模塊的軟件包名稱的正確方法有疑問。具有多個模塊的Maven包名
我會用一個例子來解釋我的問題。
我們有以下項目。
project
project-api Interfaces (implemented by the modules)
project-core Logic
project-persistence Data (models, repository etc)
project-utils Utilities (hashing, calculating etc)
project-gui Graphical User Interface
project-cli Command Line Interface
project-dist Distribution (generate the JAR's together)
具有以下類。
project-api
Repository Interface
project-core
AbstractRepository Abstract class (implements Repository)
Core Class
project-persistence
SampleRepository Class (extends AbstractRepository)
Sample Class (model)
project-utils
Calculator Class
project-gui
Demo Class (main)
現在,當我們有這個東西,我們將創建以下Demo類。
public class Demo() {
public static void main(String[] args) {
Core core = new Core();
core.start();
Repository sampleRepository = new SampleRepository();
Sample sample = sampleRepository.get();
Calculator.calc(sample);
}
}
我們還需要導入包。 你應該在你的項目中使用哪個選項,或者如果選項不聽,什麼纔是正確的路?
選項1
名稱所有的模塊封裝相同的模塊-name:com.company.project.api
package com.company.project.gui
import com.company.project.api.persistence.repository.Repository;
import com.company.project.core.Core;
import com.company.project.persistence.repository.SampleRepository;
import com.company.project.persistence.models.Sample;
import com.company.project.utils.Calculator;
選項2
名稱API模塊包與項目的根名稱相同:com.company.project
package com.company.project.gui
import com.company.project.persistence.repository.Repository;
import com.company.project.core.Core;
import com.company.project.persistence.repository.SampleRepository;
import com.company.project.persistence.models.Sample;
import com.company.project.utils.Calculator;
選項3
名稱的所有模塊封裝一樣的項目根包名稱:com.company.project
package com.company.project
import com.company.project.repository.Repository;
import com.company.project.Core;
import com.company.project.repository.SampleRepository;
import com.company.project.models.Sample;
import com.company.project.Calculator;
所有反饋意見,建議等,歡迎選購。先謝謝你!
我通常堅持選項1,因爲我發現它更清晰 – Koby