Webstart Package Batch processing __web

Source: Internet
Author: User
Tags rar

Packaging for Web Start requires the digital signature of the package file, or the writing of the engineering files into a jar.
Packaging-testing--correcting--packaging--testing the process repeatedly, it's a good idea to have the computer replace the manual repeat process.

This text gives an example of how to use the command line and the redirection of the command-line input to override repetitive operations. The specific tool usage please the reader to find the explanation. The command line is not familiar, you can refer to help on the operating system, and the command line is not interpreted in this article.

In the process of digital signature, the input of key generation can be used to achieve automation with the input redirection of command line.

This article is divided into two scenarios to illustrate how to create a batch file to do this work:
1 package All the compiled code in the project into a jar (this jar contains the other jars as a development package)
2 signature on multiple jars

Working environment: Windows Advanced Server
WinRar 3.5
JSDK 1.5.0_12

A common batch file is introduced before the description. These stand-alone batch files are introduced separately because individual batch files can be easily invoked by other batch files, and from a programmatic standpoint these individual batch files are like functional "functions"


To set a batch file for a substitution variable: setenvparam.cmd

Set Jdk_bin=d:/jdk15/bin
Set Project_lib_path=e:/timingproj/aenv/lib
Set Original_lib_path=./originallib
Set Signed_lib_path=./signedlib
Set Aenv_pack=f:/aenvbuild/aenv.jar


Copy file Batch file: Copy.cmd

Call Setenvparam.cmd
copy/y%project_lib_path%/*.jar%original_lib_path%
copy/y%aenv_pack%%original_lib_path%

Case one: Packaged into a jar

In this case, the class file for the project and the class file in the development Kit (*.JAR) used as a development project are packaged into the same jar. The process is to unpack all the *.jar and then wrap the "bulk" class file together with the engineering class file to the final jar

Unzip.cmd

Set Lib_path=e:/timingproj/aenv/lib
Set Idea_packed_jar=f:/aenvbuild/aenv.jar
For%%n in (%lib_path%/*.jar) do%rar% x-o+%%n%classes_path%
%rar% x-o+%idea_packed_jar%%classes_path%

The for command is used here to decompress all jars under the path, and the extracted tools use the Winrar.exe command-line method.
The reason why I use Winrar is my personal preference, I think Winrar command line is more convenient and rich than Jar's command.


and assemble the "bulk" class into a jar.

Zip.cmd

%rar% a-r-ep1%deploy_jar%%classes_path%/

To this end, package the file into a jar way to complete the process, as for the digital signature, please continue reading this article


Case two: Keep multiple jars
Using the previous setenvparam.cmd and copy.cmd for file operations, do not repeat (call Xx.cmd calls to the specified batch work). Next, the project class file is packaged and then digitally signed along with the development package jar
The class package after the project has been compiled is not described. Go straight to the topic look at the use of digital signatures and for commands and redirect input


Sign.cmd

Call Setenvparam.cmd

REM Delete old keys
del/q%original_lib_path%/temp.keystore

REM Create key
%jdk_bin%/keytool-genkey-keystore%original_lib_path%/temp.keystore-alias Tempkeystore < KEY_INFO.lst
%jdk_bin%/keytool-export-keystore%original_lib_path%/temp.keystore-alias Tempkeystore-file%ORIGINAL_LIB_PATH%/ Aenv.cer < Key_export.lst
For%%n in (%original_lib_path%/*.jar) does call Selfsign.cmd%%n

The red Word is input redirection: read each line from a text file to "answer" the command line "question" (the command line waiting input actually comes from the file input stream), the reply is submitted as a newline carriage return. The "line" in the Key_info.lst file means: Carriage return and wrapping, each line corresponding to the command line requires the user's input

The orange%%n is the entry parameter for selfsign.cmd execution, which is the command line argument

Selfsign.cmd
%jdk_bin%/jarsigner-keystore%original_lib_path%/temp.keystore%1 Tempkeystore < key_export.lst

Using Ant to run a batch file with Windows

To run an external program within ant, use the <exec> task. It allows you to do the following:

l Specifies the program name and the parameters to be passed in.

L NAME the running directory.

L Use the FAILONERROR flag to control whether the build stops when the application fails.

L Specify a maximum program duration, over which the program aborts. A task is considered a failure at this time, but at least the build aborts, rather than hangs, which is essential for automatic construction.

L Save the output to a file or attribute.

l Specifies the environment variables that need to be preset when Java invokes the local program.



Here's an example:

Batch file:

Test.bat

@echo Offecho Hello > Test.txt


Build.xml

<?xml version= "1.0" ><project name= "batch" default= "extract" basedir= "."             > <target name= "extract" > <exec executable = "cmd" > <arg line= "/C A.bat"/> </exec> </target></project>

Use the executable element tag to specify the command to use, which can be entered at the command line with the Help cmd view. If you want to abort the build when you run a batch error, you need to set failonerror= "on". Join your external program to hang at some point, Maybe it's a conversation with a remote site, and you don't want the build to hang forever, Ant provides timeout this attribute, and he's a number in milliseconds. Let's see how you can use ant to run Tomcat.

Starting Tomcat requires two environment variables catalina_home, Java_home, if you are already set in the environment variable, you do not need to process in ant, if you do not need to use the <env> attribute to set, you can also use <env> property to overwrite your previous environment variables.


<?xml version= "1.0" ><project name= "batch" default= "Tomcat-start" basedir= "."    > <property name= "tomcat.dir" value= "C:/tomcat5" ></property> <target name= "Tomcat-start" >       <exec dir= "${tomcat.dir}/bin" executable= "cmd" > <env key= "catalina_home" path= "${tomcat.dir}"/> <arg value= "/C startup.bat"/> </exec> </target></project>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.