gpt4 book ai didi

maven-2 - 寻找 Webstart Maven 插件示例应用程序

转载 作者:行者123 更新时间:2023-12-01 23:09:31 25 4
gpt4 key购买 nike

我正在寻找使用 Webstart Maven 插件的完整应用程序的源代码。

有什么想法吗?

最佳答案

我在涉及嵌入式 tomcat 服务器的概念中尝试了 webstart 插件。该插件绑定(bind)到包阶段,需要很长时间才能执行,我建议从命令行手动调用它。它在目标目录中生成一个 zip 文件,其中包含 jnlp 文件和所有依赖项。然后可以提取该文件并将其放在网络服务器上。 pom 中的 url 应指向服务器上的此路径。启动时,该应用程序在本地主机端口 8080 上运行一个 tomcat 服务器,并使用一个简单的 servlet,该 servlet 仅以字符串形式返回请求的路径。

请告诉我这是否适合您。

这里是项目的pom,插件配置大部分是从文档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();
}
}

最后是一个servlet,位于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();
}
}

关于maven-2 - 寻找 Webstart Maven 插件示例应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5195545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com