在项目中使用多个模块时,Java Twitter4j 无法找到属性文件

问题描述

我正在尝试使用 Intellij 使用 twitter4j 和 openjfx 编写一个简单的 Java 应用程序。 在 Intellij 中,我创建了一个新的 Empty 项目并在该项目中定义了一些新的 Maven 模块来构建一个工作区,我可以在其中一次开发多个应用程序。我用 Maven 和 openjfx Archetype 创建了一个名为“tweetalot”的模块来测试 twitter4j 库,但程序总是失败,因为 twitter4j 没有找到 twitter4j.properties 文件。 它只找到属性文件,当我把它放在主项目目录“JavafxbuchÜbungen”(.idea 文件夹也在其中)中时,即使我把它放在 tweetalot 模块的根或资源文件夹中,twitter4j.properties可以找到文件。

如何将 twitter4j.properties 文件放在模块文件夹而不是主项目文件夹中? 这是我的文件夹结构: Folder Structure 这是 github 上的整个项目上传(主项目文件夹从 JavafxbuchÜbungen 重命名为 JavafxbuchUebungen,因为我无法在 github 上使用 Ü。 Link for Project on Github 应用程序源代码如下。

package de.javafxbuch;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import twitter4j.*;

/**
 * JavaFX App
 */
public class App extends Application {

    @Override
    public void start(Stage stage) {
        StackPane root = new StackPane();
        Label label = new Label();
        root.getChildren().add(label);
        try{
            Twitter twitter = TwitterFactory.getSingleton();
            ResponseList<Status> homeTimeline = twitter.getHomeTimeline();
            label.setText(homeTimeline.get(0).getText());
        }
        catch (TwitterException ex){
            //
        }
        stage.setScene(new Scene(root));
        stage.setTitle("Tweetalot");
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

}

解决方法

这就是 mvn / gradle - 基于约定的构建系统期望资源的方式。

属性文件 twitter4j.properties 应位于目录 tweetalot3/src/main/resourrces 下。从截图中看不清楚在提到的目录中是否存在属性文件

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...