2013-08-06 14 views
7

Ho creato una semplice applicazione Hello World Swing che compila ed esegue perfettamente in Eclipse. Ora sto provando a trasferire questa applicazione su una struttura di pacchetto Maven ed eseguirla come un'applicazione Java Web-Start, che mi sta causando un grande dolore. Dopo aver eseguito "mvn clean install", javaws sembra caricare per diversi secondi e quindi uscire.JNLP, Webstart e Maven

Qui ci sono alcune cose per riferimento. La mia (molto semplice) progetto dovrebbe essere pienamente riproducibili:

struttura del pacchetto (da albero):

├── pom.xml 
├── readme.txt 
├── SwingWebstartMaven-Client 
│   ├── pom.xml 
│   ├── src 
│   │   ├── main 
│   │   │   ├── java 
│   │   │   │   └── com 
│   │   │   │    └── shaunabram 
│   │   │   │     └── swingwebstartmaven 
│   │   │   │      ├── HelloWorldSwing.class 
│   │   │   │      └── HelloWorldSwing.java 
│   │   │   ├── jnlp 
│   │   │   │   └── template.vm 
│   │   │   └── resources 
│   │   └── test 
│   └── target 
│    ├── classes 
│    │   └── com 
│    │    └── shaunabram 
│    │     └── swingwebstartmaven 
│    │      └── HelloWorldSwing.class 
│    ├── jnlp 
│    │   ├── launch.jnlp 
│    │   ├── lib 
│    │   │   └── SwingWebstartMaven-Client-1.0.jar 
│    │   └── SwingWebstartMavenExample-KeyStore 
│    ├── maven-archiver 
│    │   └── pom.properties 
│    ├── surefire 
│    ├── SwingWebstartMaven-Client-1.0.jar 
│    └── SwingWebstartMaven-Client-1.0.zip 
└── SwingWebstartMaven-Web 
    ├── pom.xml 
    ├── src 
    │   ├── main 
    │   │   ├── java 
    │   │   ├── resources 
    │   │   └── webapp 
    │   │    ├── index.html 
    │   │    └── WEB-INF 
    │   │     └── web.xml 
    │   └── test 
    └── target 
     ├── classes 
     ├── maven-archiver 
     │   └── pom.properties 
     ├── surefire 
     ├── SwingWebstartMaven-Web-1.0 
     │   ├── index.html 
     │   ├── META-INF 
     │   └── WEB-INF 
     │    ├── classes 
     │    └── web.xml 
     └── SwingWebstartMaven-Web-1.0.war 

pom.xml primaria:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.shaunabram.swingwebstartmaven</groupId> 
    <artifactId>SwingWebstartMaven</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0</version> 
    <name>SwingWebstartMaven Project</name> 

    <modules> 
     <module>SwingWebstartMaven-Client</module> 
     <module>SwingWebstartMaven-Web</module> 
    </modules> 

    <build> 
     <pluginManagement> 
      <plugins> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <configuration> 
         <source>1.5</source> 
         <target>1.5</target> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>tomcat-maven-plugin</artifactId> 
        <configuration> 
         <url>http://localhost:8080/manager</url> 
         <username>tomcat</username> 
         <password>tomcat</password> 
        </configuration> 
       </plugin> 

      </plugins> 
     </pluginManagement> 
    </build> 

</project> 

pom.xml SwingWebstart-client

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.shaunabram.swingwebstartmaven</groupId> 
     <artifactId>SwingWebstartMaven</artifactId> 
     <version>1.0</version> 
    </parent> 
    <artifactId>SwingWebstartMaven-Client</artifactId> 
    <packaging>jar</packaging> 
    <name>SwingWebstartMaven Client</name> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo.webstart</groupId> 
       <artifactId>webstart-maven-plugin</artifactId> 
       <version>1.0-beta-2</version> 

       <executions> 
        <execution> 
         <id>package</id> 
         <phase>package</phase> 
         <goals> 
          <goal>jnlp-inline</goal> 
         </goals> 
        </execution> 
       </executions> 

       <configuration> 
        <jnlp> 
         <outputFile>launch.jnlp</outputFile> 
         <mainClass>com.shaunabram.swingwebstartmaven.HelloWorldSwing</mainClass> 
        </jnlp> 

        <libPath>lib</libPath> 

        <sign> 
         <keystore>SwingWebstartMavenExample-KeyStore</keystore> 
         <keypass>YourPassword</keypass> 
         <storepass>YourPassword</storepass> 
         <alias>SwingWebstartMavenExample</alias> 
         <validity>3650</validity> 

         <dnameCn>Your Name</dnameCn> 
         <dnameOu>Organizational Unit</dnameOu> 
         <dnameO>Organization</dnameO> 
         <dnameL>City or Locality</dnameL> 
         <dnameSt>State or Province</dnameSt> 
         <dnameC>US</dnameC> 

         <verify>true</verify> 
         <keystoreConfig> 
          <delete>true</delete> 
          <gen>true</gen> 
         </keystoreConfig> 
        </sign> 

        <pack200>false</pack200> 
        <gzip>true</gzip> 
        <outputJarVersions>false</outputJarVersions> 
        <verbose>true</verbose> 

       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

SwingWebstartMaven-Web pom.xml

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.shaunabram.swingwebstartmaven</groupId> 
     <artifactId>SwingWebstartMaven</artifactId> 
     <version>1.0</version> 
    </parent> 

    <artifactId>SwingWebstartMaven-Web</artifactId> 
    <packaging>war</packaging> 
    <name>SwingWebstartMaven Web</name> 

    <dependencies> 

    </dependencies> 

</project> 

HelloWorldSwing.java:

package com.shaunabram.swingwebstartmaven; 

import javax.swing.JFrame; 
import javax.swing.JLabel; 

public class HelloWorldSwing { 
    public static void main(String[] args) { 
    JFrame frame = new JFrame("HelloWorldSwing"); 
    final JLabel label = new JLabel("Hello World"); 
    frame.getContentPane().add(label); 

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.pack(); 
    frame.setVisible(true); 
    } 
} 

template.vm:

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="http://localhost:8080/SwingWebstartMaven-Web/webstart" href="$outputFile"> 
<information> 
    <title>Swing Webstart Maven Project</title> 
    <vendor>ShaunAbram</vendor> 
</information> 
<security> 
<all-permissions/> 
</security> 
<resources> 
    <j2se version="1.5+" initial-heap-size="32m" max-heap-size="128m" /> 
    <property name="jnlp.versionEnabled" value="false"/> 
    $dependencies 
</resources> 
<application-desc main-class="$mainClass"> 
</application-desc> 
</jnlp> 

Grazie.

PS: Il progetto che sto utilizzando proviene da un esempio sul sito web di Shaun Abram, qui: http://www.shaunabram.com/swing-webstart-maven-example/. È stato progettato per interfacciarsi con tomcat ed essere eseguito su un server, ma credo che dovrei essere in grado di farlo funzionare localmente. Sto solo usando il ramo SwingWebstartMaven-Client e ignorando il ramo SwingWebstartMaven-Web.

PPS: Mi sento come se dovessi essere in grado di rinominare la struttura del pacchetto, ma per qualche motivo non posso. Ogni volta che provo sostituzione shaunabram con il mio cognome nella struttura di directory, la dichiarazione del pacchetto nel mio file java, e nel file pom.xml, si lamenta con:

[ERROR] The project com.kothur.swingwebstartmaven:SwingWebstartMaven-Client:1.0 (/media/reivei/New Volume/Project Files/SwingWebstartMaven/SwingWebstartMaven-Client/pom.xml) has 1 error 
[ERROR]  Non-resolvable parent POM: Failure to find com.kothur.swingwebstartmaven:SwingWebstartMaven:pom:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2] 

EDIT: Il problema è identica a questa : I am not able launch JNLP applications using "Java Web Start"? tranne su una macchina Ubuntu. Ho difficoltà a capire come la soluzione dell'autore si sarebbe tradotta in Ubuntu (ho provato a impostare JAVAWS_HOME nel mio jre bin e rieseguire javaws ma mi ha dato lo stesso problema (ad esempio, lo splash screen Java 6 si avvia e quindi si interrompe senza alcun programma da trovato)). Facendo doppio clic launch.jnlp lo gestisce in Java 7 (non quello che voglio) e sputa fuori

"Error: Unable to load resource: http://localhost:8080/SwingWebstartMaven-Web/webstart/launch.jnlp." 

Dopo questo punto, ho provato un paio di altre cose. Il principale pom.xml aveva il plugin per il tomcat, che non stavo usando, quindi ho provato a eliminarlo, cosa che non ha fatto nulla. Ho quindi provato a creare un server tomcat e a mettere la cartella del progetto in/var/lib/tomcat7/webapps /. Ciò non ha modificato anche l'errore.

+0

"Errore"? Hai anche sostituito shaunabram nel nome del pacchetto della classe? – chrylis

+1

Sì, sì. Il mio male per non averlo menzionato; OP aggiornato. – rkoth

+2

Se mi sottovaluti, puoi spiegare perché? Sono i frammenti di codice gratuiti o il fatto che si tratta di una domanda davvero noisana? Quale sarebbe un modo migliore per formulare la domanda? – rkoth

risposta

3

Leggere cosa fa effettivamente Web Start; è un meccanismo per leggere un descrittore (ad es., riempito con template.vm) e scaricare e avviare una normale applicazione Java da esso (al contrario di un'applet). Se stai correndo dalla riga di comando e hai già il barattolo, è ridondante. Se vuoi davvero giocare con esso, devi modificare template.vm in a valid JNLP descriptor file che punta alla base di codice locale e quindi usare javaws heet.jnlp. Vedere la pagina man per javaws e i collegamenti che contiene.

Per quanto riguarda il problema di Maven, sembra che non sia stata installata la POM padre di riferimento, quindi Maven non sa da cosa ereditare. È necessario eseguire le stesse modifiche sul POM padre, installare e quindi lavorare sul POM figlio.

+0

Sì, ho capito cosa c'era di sbagliato nel file POM circa mezz'ora fa. Importante momento di derp. Per quanto riguarda javaws ... dopo aver aggiunto tutti i vecchi file parent e aver eseguito javaws launch.jnlp, mi imbatto nel vecchio problema di colpire l'animazione splash Java 6, che viene eseguita per circa 18 secondi prima di uscire. Aggiornerò l'OP con informazioni più rilevanti al mattino. – rkoth

Problemi correlati