2017-01-12 3 views
0

Ich bin neu zu Maven und ich vor kurzem ein Swing-Projekt entwickelt, während Maven verwenden, um Abhängigkeiten zu verwalten.Ausführbare Jar von Maven Swing-Projekt

Was ich jetzt tun möchte, ist Paket mein Projekt für den Vertrieb und in der Lage, die Datei auf einen anderen Computer/Laptop für eine Person zu öffnen und zu verwenden.

Aus meiner Forschung habe ich verstanden, dass ich das Projekt mit Assembly oder Shade Maven Plugin verpacken muss.

Ich habe beide versucht und in der Lage, eine ausführbare Jar zu haben, aber ich versuche es auszuführen, passiert nichts.

Hier ist meine Projektstruktur HERE

Hier mein pom.xml ist, wenn Schatten-Plugin:

<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>1</groupId> 
    <artifactId>Fin</artifactId> 
    <version>0.0.6-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>AinsfieldFin</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.14</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-ooxml</artifactId> 
     <version>3.14</version> 
    </dependency> 

    <dependency> 
    <groupId>org.docx4j</groupId> 
    <artifactId>docx4j</artifactId> 
    <version>2.8.0</version> 
    </dependency> 

    <dependency> 
    <groupId>org.apache.xmlgraphics</groupId> 
    <artifactId>batik-bridge</artifactId> 
    <version>1.7</version> 
    </dependency> 
    </dependencies> 



    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.4.3</version> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
       <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
        <mainClass>com.Fin.index</mainClass> 
       </transformer> 
       </transformers> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19.1</version> 
       <configuration> 
        <argLine>-Dfile.encoding=UTF-8</argLine> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <encoding>UTF-8</encoding> 
        <Version>3.1</Version> 
       </configuration> 
      </plugin> 

    </plugins> 
    </build> 
</project> 

Hier wird die Datei index.java

package com.Fin; 

//swing imports 

import com.Fin.process.ManipulationExcel; 
import com.Fin.process.ManipulationWord; 


public class index { 

    //declarations 


    /** 
    * Launch the application. 
    */ 
    public static void main(String[] args) { 
     EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       try { 
        index window = new index(); 
        window.frame.setVisible(true); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
    } 

    /** 
    * Create the application. 
    */ 
    public index() { 
     initialize(); 
    } 

    /** 
    * Initialize the contents of the frame. 
    */ 
    private void initialize() { 
      // present layout and app functions 
    } 
} 

und ich bin mit Eclipse als meine IDE

Vielen Dank im Voraus für jede Hilfe zur Verfügung gestellt

BESCHLOSSEN: My pom.xml sieht wie folgt nun:

<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>1</groupId> 
    <artifactId>Fin</artifactId> 
    <version>0.1.1</version> 
    <packaging>jar</packaging> 

    <name>AinsfieldFin</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.14</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-ooxml</artifactId> 
     <version>3.14</version> 
    </dependency> 

    <dependency> 
    <groupId>org.docx4j</groupId> 
    <artifactId>docx4j</artifactId> 
    <version>2.8.0</version> 
    </dependency> 

    <dependency> 
    <groupId>org.apache.xmlgraphics</groupId> 
    <artifactId>batik-bridge</artifactId> 
    <version>1.7</version> 
    </dependency> 
    </dependencies> 



    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.4.3</version> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
       <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
        <mainClass>com.Fin.index</mainClass> 
       </transformer> 
       </transformers> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
       <!-- Build an executable JAR --> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>com.Fin.index</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19.1</version> 
       <configuration> 
        <argLine>-Dfile.encoding=UTF-8</argLine> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <encoding>UTF-8</encoding> 
        <Version>3.1</Version> 
       </configuration> 
      </plugin> 

    </plugins> 
    </build> 
</project> 
+0

Vielleicht etwas wie [dies] (http://stackoverflow.com/questions/24899985/this-project-cannot-be-added-because-it-does-not-produce-a-jar-file-using-an-ant/24900260 # 24900260) könnte helfen – MadProgrammer

Antwort

1

Sie diese in Ihrem pom.xml mithilfe dieser Teil tun können (Ihre Hauptklasse Standort ändern:

<build> 
     <plugins> 
      <plugin> 
       <!-- Build an executable JAR --> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>com.your.mainClass</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
+0

Hallo. Danke für deine Hilfe, aber ich verstehe nicht, was du meinst, wenn ich meinen Hauptklassenstandort ändere, sollte es funktionieren? Ich habe den Teil ersetzt, den du mir gesagt hast, und ich habe ein anderes Glas, was passiert, wenn ich renne. Nur für den Fall, dass ich etwas falsch mache, mache ich "Run as"> "Maven Build ..."> und dann als Ziel "Paket" –

+0

Hallo, dort setzen Sie Ihre Hauptklasse.Location wie com.example.Class zum Tag. Du solltest eine mvn clean-Installation machen und dann zum Ziel gehen und versuchen, java -jar nameOfJar.jar –

+0

Das half Lasten. Habe das und konnte meine App einen Nullzeigerfehler ausgeben lassen! Ich habe den Fehler korrigiert und es funktioniert jetzt! LEBENSRETTER! –

Verwandte Themen