使用maven将包外观依赖到可执行jar中

时间:2014-07-04 20:03:52

标签: java swing maven netbeans look-and-feel

我在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>

2 个答案:

答案 0 :(得分:1)

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>

答案 1 :(得分:0)

您的类路径中很可能缺少Substance外观。