2011-03-04 11 views

답변

30

웹 스타트 플러그인을 임베디드 톰캣 서버와 관련된 개념으로 시험해 보았습니다. 플러그인은 패키지 단계에 바인딩되어 있으며 오랜 시간이 걸립니다. 명령 줄에서 수동으로 호출하는 것이 좋습니다. jnlp 파일과 모든 종속성을 포함하는 대상 디렉토리에 zip 파일을 생성합니다. 그런 다음이 파일을 추가하여 웹 서버에 저장할 수 있습니다. pom의 url은 서버의이 경로를 가리켜 야합니다. 시작되면, 응용 프로그램은 localhost 포트 8080에서 요청 된 경로를 문자열로 반환하는 간단한 서블릿으로 tomcat 서버를 실행합니다.

이 기능이 작동하는지 알려주세요. 내가 필요한 이유는 다음과 같습니다

프로젝트의 치어이며, 플러그인 구성이 대부분 here

다음
<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>net.jhorstmann</groupId> 
    <artifactId>EmbeddedTomcatWebstart</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>EmbeddedTomcatWebstart</name> 
    <url>http://localhost/jnlp/</url> 
    <organization> 
     <name>Organisation</name> 
    </organization> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <tomcat.version>7.0.6</tomcat.version> 
    </properties> 
    <repositories> 
     <repository> 
      <id>jboss</id> 
      <url>http://repository.jboss.org/nexus/content/groups/public/</url> 
     </repository> 
     <repository> 
      <id>sonatype</id> 
      <url>http://oss.sonatype.org/content/repositories/releases/</url> 
     </repository> 
    </repositories> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.5</source> 
        <target>1.5</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.3.1</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <mainClass>net.jhorstmann.embeddedtomcat7.App</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo.webstart</groupId> 
       <artifactId>webstart-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <!-- bind to phase, I prefer to call it manualls --> 
         <phase>package</phase> 
         <goals> 
          <goal>jnlp-inline</goal> <!-- use jnlp, jnlp-inline or jnlp-single as appropriate --> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <!--outputDirectory></outputDirectory--> <!-- not required?? --> 

        <!-- Set to true to exclude all transitive dependencies. Default is false. --> 
        <excludeTransitive>false</excludeTransitive> 

        <!-- The path where the libraries are stored within the jnlp structure. not required. by default the libraries are within the working directory --> 
        <libPath>lib</libPath> 
        <outputJarVersions>true</outputJarVersions> 
        <!-- [optional] transitive dependencies filter - if omitted, all transitive dependencies are included --> 
        <dependencies> 
         <!-- Note that only groupId and artifactId must be specified here. because of a limitation of the Include/ExcludesArtifactFilter --> 
         <!-- 
         <includes> 
          <include>commons-logging:commons-logging</include> 
          <include>commons-cli:commons-cli</include> 
         </includes> 
         --> 
         <!-- 
         <excludes> 
          <exclude></exclude> 
         <excludes> 
         --> 
        </dependencies> 

        <!-- 
        <resourcesDirectory>${project.basedir}/src/main/jnlp/resources</resourcesDirectory> 
        --> 
        <!-- default value --> 

        <!-- JNLP generation --> 
        <jnlp> 
         <!-- default values --> 
         <!--inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath--> 
         <!--inputTemplate>src/main/jnlp/template.vm</inputTemplate--> <!-- relative to inputTemplateResourcePath --> 
         <outputFile>app.jnlp</outputFile> <!-- defaults to launch.jnlp --> 

         <!-- used to automatically identify the jar containing the main class. --> 
         <!-- this is perhaps going to change --> 
         <mainClass>net.jhorstmann.embeddedtomcat7.App</mainClass> 
        </jnlp> 


        <!-- SIGNING --> 
        <!-- defining this will automatically sign the jar and its dependencies, if necessary --> 
        <sign> 
         <keystore>${basedir}/keystore</keystore> 
         <keypass>password</keypass> <!-- we need to override passwords easily from the command line. ${keypass} --> 
         <storepass>password</storepass> <!-- ${storepass} --> 
         <!--storetype>fillme</storetype--> 
         <alias>EmbeddedTomcatWebstart</alias> 

         <!--validity>fillme</validity--> 

         <!-- only required for generating the keystore --> 
         <dnameCn>EmbeddedTomcatWebstart</dnameCn> 
         <dnameOu>Organisation Unit</dnameOu> 
         <dnameO>Organisation</dnameO> 
         <dnameL>Location</dnameL> 
         <dnameSt>State</dnameSt> 
         <dnameC>Country</dnameC> 

         <verify>true</verify> <!-- verify that the signing operation succeeded --> 

         <!-- KEYSTORE MANAGEMENT --> 
         <keystoreConfig> 
          <delete>true</delete> <!-- delete the keystore --> 
          <gen>true</gen>  <!-- optional shortcut to generate the store. --> 
         </keystoreConfig> 
        </sign> 

        <!-- BUILDING PROCESS --> 

        <pack200>true</pack200> 
        <gzip>true</gzip> <!-- default force when pack200 false, true when pack200 selected ?? --> 

        <!-- causes a version attribute to be output in each jar resource element, optional, default is false --> 
        <outputJarVersions>false</outputJarVersions> 

        <!--install>false</install--> <!-- not yet supported --> 
        <verbose>true</verbose> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.tomcat</groupId> 
      <artifactId>tomcat-catalina</artifactId> 
      <version>${tomcat.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tomcat</groupId> 
      <artifactId>tomcat-coyote</artifactId> 
      <version>${tomcat.version}</version> 
     </dependency> 
    </dependencies> 
</project> 

src/main/jnlp/template.vm에 배치 된 jnlp 파일에 대한 사용자 지정 템플릿입니다 문서에서 복사, 기억이 없다 정확히 :

<?xml version="1.0" encoding="utf-8"?> 
<jnlp 
    spec="$jnlpspec" 
    codebase="$project.Url" 
    href="$outputFile"> 
    <information> 
    <title>$project.Name</title> 
    <vendor>$project.Organization.Name</vendor> 
    <homepage href="$project.Url"/> 
    <description>$project.Description</description> 
#if($offlineAllowed) 
    <offline-allowed/> 
#end 
    </information> 
#if($allPermissions) 
    <security> 
    <all-permissions/> 
    </security> 
#end 
    <resources> 
    <j2se version="$j2seVersion"/> 
    $dependencies 
    </resources> 
    <application-desc main-class="$mainClass"/> 
</jnlp> 

src/main/java/net/jhorstmann/embeddedtomcat7/App.java

package net.jhorstmann.embeddedtomcat7; 

import java.io.File; 
import java.io.IOException; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.servlet.ServletException; 
import org.apache.catalina.Context; 
import org.apache.catalina.LifecycleException; 
import org.apache.catalina.Wrapper; 
import org.apache.catalina.startup.Tomcat; 

public class App { 

    public static void main(String[] args) throws LifecycleException, ServletException, IOException { 
     File tmpDir = new File(System.getProperty("java.io.tmpdir")); 
     File webappDir = new File(tmpDir, "embeddedtomcat7"); 
     webappDir.mkdir(); 

     final Tomcat tomcat = new Tomcat(); 
     tomcat.setPort(8080); 
     tomcat.setBaseDir(tmpDir.getAbsolutePath()); 
     tomcat.getConnector().setURIEncoding("UTF-8"); 

     String contextPath = "/"; 

     Context context = tomcat.addContext(contextPath, webappDir.getAbsolutePath()); 
     Wrapper wrapper = tomcat.addServlet(contextPath, "Test", new TestServlet()); 
     //Wrapper wrapper = tomcat.addServlet(contextPath, "Async", new AsyncServlet()); 
     //wrapper.setAsyncSupported(true); 

     wrapper.addMapping("/*"); 

     tomcat.start(); 

     tomcat.getServer().await(); 
    } 
} 
의 기본 클래스입니다

그리고 마지막으로이 플러그인에 src/main/java/net/jhorstmann/embeddedtomcat7/TestServlet.java

package net.jhorstmann.embeddedtomcat7; 

import java.io.IOException; 
import java.io.PrintWriter; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class TestServlet extends HttpServlet { 

    @Override 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
     resp.setContentType("text/html; charset=utf-8"); 
     PrintWriter writer = resp.getWriter(); 
     writer.println("<h1>" + req.getPathInfo() + "</h1>"); 
     writer.close(); 
    } 
} 
+0

감사합니다! 코드를 살펴 보겠습니다 – Ralph

+0

실행할 명령은 무엇입니까? – jcalfee314

+0

위의 pom.xml 파일에서 두 가지 사항을 알아 두는 것이 중요합니다. 첫 번째는 ' 패키지'이고 두 번째 것은 ' jnlp-inline'이 플러그인으로 mainClass를 찾는데 문제가 있었는데'jnlp'에서'jnlp-inline'으로 변경하려고 시도했지만 아무것도하지 않았습니다. 이것은'jnlp'가 단계를 필요로하지 않기 때문입니다 'jnlp-inline'은 –

1

몇 가지 참고 사항에서 서블릿 (그것의 문서는 끔찍) : 당신이 그것을 지정하지 않는

그것은

처럼 template.vm 파일을 사용하지 않습니다

요하는 경우 : 전쟁을 만들기위한

<templateFilename>roll-gen-template.vm</templateFilename>

JnlpDownloadServlet (표준 자바가 제공하는)을 사용하여 위의 코드 대신 파일을 제공하고 (플러그인에서 사용할 수있는 작업 version.xml 파일을 생성해야 함), 기본적으로 새로운 유형의 전쟁 프로젝트와 jnlp-download-servlet goal을 대상으로합니다 (현재 pom 프로젝트의 클래스와 전쟁을 만드는 것을 지원하지 않는 것 같습니다). <jnlp> 섹션 하나가 아닌 <jnlpFiles> 섹션이 대신 표시 될 수 있습니다. 항아리 의존성. web.xml 파일을 수정해야 할 수도 있습니다. http://www.mojohaus.org/webstart/webstart-maven-plugin/jnlp-mojos-overview.html의 예시는

입니다. 추가 의견이 있으시면 언제든지 커뮤니티 위키입니다.

+0

https://web.archive.org/web/20150118052707/http://mojo.codehaus.org/webstart/webstart-maven-plugin/jnlp-mojos-overview.html – andrej