图像未导出到可执行jar文件

时间:2017-08-16 04:08:47

标签: java image maven jar weka

我正在修改Weka,一个开源的Maven项目,我的修改在eclipse上完美运行。但是,当我导出到可执行jar文件时,我得到一个空指针异常,因为它无法找到我创建的图像并在getImage()调用时添加到项目中。

似乎这是jar文件的一个相当常见的问题,所以我尝试使用URL方法加载,但经过进一步调查,当我用SecureZIP查看jar文件时,我添加的图像(.png)到项目甚至没有在jar中(但是,原始开源分发中的图像(.png)是,尽管所有图像都在同一文件夹中并且指定了相同类型(.png)通过源代码中的构建路径)。有什么我忘记做的事吗?为什么我的图像没有导出到jar,但文件夹中的其他图像是?

库处理是:"将所需的库提取到生成的JAR"中。 图像位于src / main / java / weka / gui。



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>nz.ac.waikato.cms.weka</groupId>
  <artifactId>weka-stable</artifactId>
  <version>3.8.1-SNAPSHOT</version>
  <!-- weka-version -->
  <packaging>jar</packaging>

  <name>weka-stable</name>
  <description>The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This is the stable version. Apart from bugfixes, this version does not receive any other updates.
  </description>
  <url>http://www.cms.waikato.ac.nz/ml/weka/</url>
  <organization>
    <name>University of Waikato, Hamilton, NZ</name>
    <url>http://www.waikato.ac.nz/</url>
  </organization>
  <licenses>
    <license>
      <name>GNU General Public License 3</name>
      <url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <developers>
    <developer>
      <id>wekateam</id>
      <name>The WEKA Team</name>
      <email>wekalist@list.waikato.ac.nz</email>
    </developer>
  </developers>

  <mailingLists>
    <mailingList>
      <name>wekalist</name>
      <subscribe>https://list.waikato.ac.nz/mailman/listinfo/wekalist</subscribe>
      <unsubscribe>https://list.waikato.ac.nz/mailman/listinfo/wekalist</unsubscribe>
      <archive>https://list.waikato.ac.nz/mailman/htdig/wekalist/</archive>
    </mailingList>
  </mailingLists>

  <parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>7</version>
  </parent>

  <scm>
    <connection>scm:svn:https://svn.cms.waikato.ac.nz/svn/weka/branches/stable-3-8/weka</connection>
    <developerConnection>scm:svn:https://svn.cms.waikato.ac.nz/svn/weka/branches/stable-3-8/weka</developerConnection>
    <url>https://svn.cms.waikato.ac.nz/svn/weka/branches/stable-3-8/weka</url>
  </scm>

  <profiles>
    <profile>
      <id>release-sign-artifacts</id>
      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.1</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!-- used for skipping tests -->
      <id>no-tests</id>
      <properties>
        <skipTests>true</skipTests>
      </properties>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.2</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
      <artifactId>java-cup-11b</artifactId>
      <version>2015.03.26</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
      <artifactId>java-cup-11b-runtime</artifactId>
      <version>2015.03.26</version>
    </dependency>

    <dependency>
      <groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
      <artifactId>bounce</artifactId>
      <version>0.18</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-compress</artifactId>
      <version>1.10</version>
      <optional>true</optional>
    </dependency>

    <dependency>
      <groupId>com.googlecode.matrix-toolkits-java</groupId>
      <artifactId>mtj</artifactId>
      <version>1.0.4</version>
    </dependency>

    <dependency>
      <groupId>net.sourceforge.f2j</groupId>
      <artifactId>arpack_combined_all</artifactId>
      <version>0.1</version>
    </dependency>

    <dependency>
      <groupId>com.googlecode.netlib-java</groupId>
      <artifactId>netlib-java</artifactId>
      <version>1.1</version>
    </dependency>
  </dependencies>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <weka.main.class>weka.gui.GUIChooser</weka.main.class>
  </properties>

  <build>
    <directory>dist</directory>
    <outputDirectory>build/classes</outputDirectory>
    <testOutputDirectory>build/testcases</testOutputDirectory>

    <resources>
      <resource>
        <targetPath>${project.build.outputDirectory}</targetPath>
        <directory>${project.build.sourceDirectory}</directory>
        <includes>
          <include>**/*.arff</include>
          <include>**/*.cost</include>
          <include>**/*.cup</include>
          <include>**/*.default</include>
          <include>**/*.excludes</include>
          <include>**/*.flex</include>
          <include>**/*.gif</include>
          <include>**/*.icns</include>
          <include>**/*.ico</include>
          <include>**/*.jflex</include>
          <include>**/*.jpeg</include>
          <include>**/*.jpg</include>
          <include>**/*.kfml</include>
          <include>**/*.matrix</include>
          <include>**/*.png</include>
          <include>**/*.properties</include>
          <include>**/*.props</include>
          <include>**/*.txt</include>
          <include>**/*.xml</include>
          <include>**/DatabaseUtils.props.*</include>
          <include>weka/gui/beans/README</include>
        </includes>
      </resource>
      <resource>
        <targetPath>${project.build.testOutputDirectory}</targetPath>
        <directory>${project.build.testSourceDirectory}</directory>
        <includes>
          <include>**/*.arff</include>
          <include>**/*.cost</include>
          <include>**/*.cup</include>
          <include>**/*.default</include>
          <include>**/*.excludes</include>
          <include>**/*.flex</include>
          <include>**/*.gif</include>
          <include>**/*.icns</include>
          <include>**/*.ico</include>
          <include>**/*.jflex</include>
          <include>**/*.jpeg</include>
          <include>**/*.jpg</include>
          <include>**/*.kfml</include>
          <include>**/*.matrix</include>
          <include>**/*.png</include>
          <include>**/*.properties</include>
          <include>**/*.props</include>
          <include>**/*.txt</include>
          <include>**/*.xml</include>
          <include>**/DatabaseUtils.props.*</include>
          <include>weka/gui/beans/README</include>
        </includes>
      </resource>
    </resources>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.7.2</version>
          <configuration>
            <includes>
              <include>**/*Test.java</include>
            </includes>
            <disableXmlReport>true</disableXmlReport>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
            <systemPropertyVariables>
              <weka.test.Regression.root>src/test/resources/wekarefs</weka.test.Regression.root>
              <weka.test.maventest>true</weka.test.maventest>
              <user.timezone>Pacific/Auckland</user.timezone>
            </systemPropertyVariables>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.1</version>
          <configuration>
            <tagBase>https://svn.cms.waikato.ac.nz/svn/weka/tags</tagBase>
            <useReleaseProfile>false</useReleaseProfile>
            <!-- tests are performed with the ant build file, hence skipped here. -->
            <preparationGoals>clean verify -P no-tests</preparationGoals>
            <goals>deploy -P no-tests</goals>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
          <filesets>
            <fileset>
              <directory>.</directory>
              <includes>
                <include>**/*~</include>
                <include>**/.attach_pid*</include>
                <include>**/hs_err_pid*</include>
              </includes>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>${weka.main.class}</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.1.2</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <excludeResources>true</excludeResources>
            </configuration>
          </execution>
          <execution>
            <id>attach-test-sources</id>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
          <maxmemory>1000m</maxmemory>
          <subpackages>weka:org</subpackages>
          <show>public</show>
          <outputDirectory>${project.basedir}/doc</outputDirectory>
          <!-- when using Java 8, use this setting to avoid overly strict javadoclet -->
          <!--additionalparam>-Xdoclint:none</additionalparam-->
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
&#13;
&#13;
&#13;

0 个答案:

没有答案