IntelliJ Idea + Gradle + class.getResource()返回null

时间:2017-12-22 13:36:54

标签: java intellij-idea resources getresource

我知道,这里有很多类似的问题,类似的问题,但在阅读了大量的帖子后,我不能简单地解决这个问题。在我的项目中,我已经将资源文件夹标记为资源根目录 尽管如此,我还是尝试使用以下简单命令链接的每个资源文件 null

System.out.println(MainClass.class.getResource("config.properties"));

任何提示? 谢谢!

在这里你可以看到我的项目结构:

Project Structure

这是我的MainClass.java类。

package dataParser;

import dataParser.Controller.PropertiesManagement;
import dataParser.Controller.RequestDataThread;
import dataParser.Model.WorkpieceData;

import java.net.Socket;
import java.util.Properties;
import java.util.Vector;

public class MainClass {

    // Connection socket.
    private static Socket socket;
    // Stores the workpieces data which have not already been saved in the DB.
    private static Vector<WorkpieceData> workpiecesDataObjectsArray;


    /**
     * Main Method
     */
    public static void main(String[] args) {
        System.out.println(MainClass.class.getResource("config.properties"));
        // First of all let's load the settings from the properties file.
        Properties properties = new Properties();
        PropertiesManagement propertiesManagement = new PropertiesManagement(properties);
        propertiesManagement.readPropertiesFile();

        workpiecesDataObjectsArray = new Vector<>();
        RequestDataThread reqDataThread = new RequestDataThread(socket);

        // New thread to initialize incoming data.
        Thread incomingDataThread = new Thread(reqDataThread);
        // Now let's start the thread.
        incomingDataThread.start();
    }

    /**
     * Getter for the array of workpiece objects.
     *
     * @return The array of workpiece objects to be filled with the data incoming from the control unit.
     */
    public static Vector<WorkpieceData> getWorkpiecesDataObjectsArray() {
        return workpiecesDataObjectsArray;
    }

}

0 个答案:

没有答案