Izpack Maven打包 第二篇

1.首先建立一个maven项目。

File - > New - > Other - > Maven Project 在打开的窗口直接next,选择maven-archetype-quickstart - > next,输入Group ID and Artifact ID - > Finished.

2.创建install.xml.

在src 下面创建izpack 文件夹(纯粹是一些原定俗称的东西),并在它的下面创建intall.xml。

内容可以从官网上找到,如下:

<?xml version="1.0" encoding="UTF-8"?>
<izpack:installation version="5.0"
                     xmlns:izpack="http://izpack.org/schema/installation"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://izpack.org/schema/installation http://izpack.org/schema/5.0/izpack-installation-5.0.xsd">
    <!-- 
        The info section.
        The meaning of the tags should be natural ...
    -->
    <info>
        <appname>Sample Installation</appname>
        <appversion>1.4 beta 666</appversion>
        <authors>
            <author name="JPz" email="[email protected]"/>
            <author name="Hidden Man" email="[email protected]"/>
        </authors>
        <url>http://www.anotherworld-inspace-website.net/</url>
    </info>

    <!-- 
        The gui preferences indication.
        Sets the installer window to 640x480. It will not be able to change the size.
    -->
    <guiprefs width="640" height="480" resizable="yes"/>

    <!-- 
        The locale section.
        Asks here to include the English and French langpacks.
    -->
    <locale>
        <langpack iso3="eng"/>
        <langpack iso3="fra"/>
    </locale>

    <!-- 
        The resources section.
        The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel.
    -->
    <resources>
        <res id="LicencePanel.licence" src="resource/Licence.txt"/>
        <res id="InfoPanel.info" src="resource/Readme.txt"/>
        <res id="userInputSpec.xml" src="userinput.xml" parse="yes" type="xml"/>
    </resources>

    <!-- 
        The panels section.
        We indicate here which panels we want to use. The order will be respected.
    -->
    <panels>
        <panel classname="HelloPanel"/>
        <panel classname="InfoPanel"/>
        <panel classname="LicencePanel"/>
        <panel classname="TargetPanel"/>
        <panel classname="UserInputPanel" id="panel1"></panel>
        <panel classname="PacksPanel"/>
        <panel classname="InstallPanel"/>
        <panel classname="FinishPanel"/>
    </panels>

    <!-- 
        The packs section.
        We specify here our packs.
    -->
    <packs>
        <pack name="Base" required="yes">
            <description>The base files</description>
        </pack>
        <pack name="Docs" required="no">
            <description>The documentation</description>
        </pack>
        <pack name="Sources" required="no">
            <description>The sources</description>
        </pack>
    </packs>

</izpack:installation>

 在izpack下面创建resource文件夹,把Licence.txt 和Reamde.txt 放入。(可以随便生成连个txt文件)

3.创建自己的userinput.xml文件并放在izpack下面。

<izpack:userInput version="5.0"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:izpack="http://izpack.org/schema/userinput"
                  xsi:schemaLocation="http://izpack.org/schema/userinput http://izpack.org/schema/5.0/izpack-userinput-5.0.xsd">
		 <panel id="panel1">
		    <field type="staticText" align="left" txt="My comment is here." id="input.comment"/>
		    <field type="text" variable="proxyaddress">
		      <spec txt="Proxy Host:" id="input.proxy" size="25" set=""/>
		    </field>
		    <field type="text" variable="proxyPort">
		      <spec txt="Proxy Port:" id="input.port" size="6" set=""/>
		    </field>
		  </panel>
</izpack:userInput>

 4.修改pom文件夹。

<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.lombardrisk</groupId>
  <artifactId>izpack</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>izpack-maven-demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <izpack.staging>${project.build.directory}/staging</izpack.staging>
    <izpack.version>5.0.0-beta11</izpack.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
  <build>
  	<plugins>
	    <plugin>
	    	<groupId>org.apache.maven.plugins</groupId>
	    	<artifactId>maven-antrun-plugin</artifactId>
	    	<version>1.7</version>
		    <executions>
		       <execution>
		          <id>generate-installer</id>
                  <phase>install</phase>
		          <goals>
		             <goal>run</goal>
		          </goals>
		          <configuration>
		             <tasks>
		                <copy todir="${izpack.staging}">
		                   <fileset dir="${basedir}/src/izpack"/>
		                </copy>
		             </tasks>
		          </configuration>
		       </execution>
		    </executions>
	 	</plugin>
  		<plugin>
            <groupId>org.codehaus.izpack</groupId>
            <artifactId>izpack-maven-plugin</artifactId>
            <version>${izpack.version}</version>
            <executions>
                <execution>
				 <id>1</id>
                    <phase>install</phase>
                    <goals><goal>izpack</goal></goals>
                    <configuration>
                         <baseDir>${izpack.staging}</baseDir>
                        <installFile>${basedir}/src/izpack/install.xml</installFile>
                        <jarName>installreport</jarName>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
			       <dependency>
			         <groupId>org.codehaus.izpack</groupId>
			         <artifactId>izpack-panel</artifactId>
			         <version>${izpack.version}</version>
			       </dependency>
			  </dependencies>
        </plugin>
  	</plugins>
  </build>
</project>

 5.至此完成准备工作。现在可以run maven命令了。

在cmd命令窗口中进入项目路径,然后输入命令 mvn clean install -U

运行成功后,就可以在target文件下看到installreport.jar,这就是生成出来的打包文件了。只是一个简单的demo,希望能帮助想学的人快速搭建起来这个环境。

 

 

 

你可能感兴趣的:(maven,demo,izpack)