簡體   English   中英

使用Maven將外觀依賴打包到可執行jar中

[英]Package look and feel dependency into executable jar with maven

我正在通過Netbeans和Maven在我的Swing GUI應用程序中使用Substance Look and Feel。

當我從Netbeans中運行項目時,將應用外觀,但是當我清理並構建項目並執行maven生成的jar時,GUI會恢復為默認外觀。

另外,在檢查生產的罐子時,我在任何地方都看不到物質文件。

我已經通過maven添加了實質依賴關系,甚至嘗試將其范圍更改為運行時,但沒有任何變化。 在編譯或執行程序時沒有遇到錯誤或異常。 問題是什么?

我在64位Windows 8計算機上使用JDK 7。

這是設置LaF的代碼:

try {
            UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel");
        }
        catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Texus.class.getName()).log(Level.SEVERE, null, ex);
        }

這是我的pom.xml:

<?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>com.pawandubey</groupId>
    <artifactId>Texus</artifactId>
    <version>0.1-ALPHA</version>
    <packaging>jar</packaging>
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.pawandubey.texus.Texus</mainClass>
            </manifest>
          </archive>
        </configuration>

      </plugin>
    </plugins>
  </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.insubstantial</groupId>
            <artifactId>substance</artifactId>
            <version>7.2.1</version>

        </dependency>
        <dependency>
            <groupId>com.seaglasslookandfeel</groupId>
            <artifactId>seaglasslookandfeel</artifactId>
            <version>0.2</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
</project>

請參閱QuickStartJavaMavenProject 它說明了您應該使用maven-assemply-plugin創建具有依賴項的jar。 就像是

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
       <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
       <archive>
          <manifest>
              <mainClass>com.areaofthoughts.grumpycat.GrumpyCat</mainClass>
          </manifest>
       </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>                        
                <goal>single</goal>
            </goals>
         </execution>
     </executions>
</plugin>

您的類路徑中很可能會丟失物質的外觀。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM