默认的JavaFX maven项目:slf4j无法正常工作

时间:2017-12-03 12:44:12

标签: maven javafx netbeans slf4j

几个月前我用Netbeans创建了一个JavaFX Maven项目。直到昨天,我使用log4j作为记录器(完美地工作)。由于我的项目将与使用slf4j的其他项目一起使用,我决定更改我的记录器。

不幸的是,创建的.jar不包含我的log4j.properties文件,而是一个通用文件。如果我手动将其替换为我自己的版本,则日志记录可以正常工作。

如何告诉maven包含我的log4j.properties文件?根据网上发现的一些解释,应该src/main/resources/,但这并不能解决问题。

pom.xml的{​​{1}}和build部分:

构建

dependencies

依赖关系

<build>
  <plugins>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.6</version>
      <executions>
        <execution>
          <id>unpack-dependencies</id>
          <phase>package</phase>
          <goals>
            <goal>unpack-dependencies</goal>
          </goals>
          <configuration>
            <excludeScope>system</excludeScope>
            <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
            <outputDirectory>${project.build.directory}/classes</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.2.1</version>
      <executions>
        <execution>
          <id>unpack-dependencies</id>

          <phase>package</phase>
          <goals>
            <goal>exec</goal>
          </goals>
          <configuration>
            <executable>${java.home}/../bin/javafxpackager</executable>
            <arguments>
              <argument>-createjar</argument>
              <argument>-nocss2bin</argument>
              <argument>-appclass</argument>
              <argument>${mainClass}</argument>
              <argument>-srcdir</argument>
              <argument>${project.build.directory}/classes</argument>
              <argument>-outdir</argument>
              <argument>${project.build.directory}</argument>
              <argument>-outfile</argument>
              <argument>${project.build.finalName}.jar</argument>
            </arguments>
          </configuration>
        </execution>
        <execution>
          <id>default-cli</id>
          <goals>
            <goal>exec</goal>
          </goals>
          <configuration>
            <executable>${java.home}/bin/java</executable>
            <commandlineArgs>${runfx.args}</commandlineArgs>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <compilerArguments>
          <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
        </compilerArguments>
      </configuration>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.16</version>
      <configuration>
        <additionalClasspathElements>
          <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
        </additionalClasspathElements>
      </configuration>
    </plugin>

  </plugins>
</build>

1 个答案:

答案 0 :(得分:0)

我只需将以下内容添加到我的主要课程中:

public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference instanceof MultiSelectListPreference) {
        List<String> newValues = new ArrayList<>((HashSet<String>) newValue);

        pref.setSummary(TextUtils.join(", ", getSummaryListFromValueList(newValues)));
    }

    return true;
}

private List<String> getSummaryListFromValueList(List<String> valueList) {
        String[] allSummaries = getResources().getStringArray(R.array.pref_notif);
        String[] allValues = getResources().getStringArray(R.array.pref_notif_values);

        List<String> summaryList = new ArrayList<>();
        for (int i = 0; i < allValues.length; i++) {
            for (String value : valueList) {
                if (allValues[i].equals(value)) {
                    summaryList.add(allSummaries[i]);
                }
            }
        }
        return summaryList;
    }