Automatically generate Jad files based on MIDlet Suite

Source: Internet
Author: User
Tags key string
We often encounter situations where there is a jar file but there is no Jad file, which is a bit of a hassle if you want to run the simulator. Of course, you can write your own jad files according to the MANIFEST.MF file in the jar file. Note that your handwriting must not ignore the following two parameters: Midlet-jar-size and Midlet-jar-url.

There are also tools on the Internet to automatically generate Jad files based on jar files. Here we use Java to implement a simple Jad file builder. The key to solving this problem is to parse the Jar package with the API provided by the Java.util.jar package, then write the contents of its manifest file into a new file, and then write Midlet-jar-size and Midlet-jar-url to the Jad file. The reference source is as follows:

Package Com.j2medev.parsejar;
Import Java.io.*;import Java.util.jar.*;import java.util.*;
public class Jarparser {
/** * @param args * *
public static void Main (string[] args) throws IOException {
TODO auto-generated Method Stub
File File = new file ("C:\\simple.jar");
if (!file.exists ()) {system.exit (0);}
Jarfile jar = new Jarfile (file);
Manifest MF = jar.getmanifest ();
Attributes att = mf.getmainattributes ();
PrintWriter jad = new PrintWriter (New FileOutputStream ("C:\\simple.jad"));
Set key = Att.keyset ();
Iterator iterator = Key.iterator ();
while (Iterator.hasnext ()) {
String k = Iterator.next (). toString ();
String v = (string) att.getvalue (k);
Jad.println (k + ":" + V);
}
Jad.println ("Midlet-jar-size:" +file.length ());
Jad.println ("Midlet-jar-url:simple.jar");
Jad.close ();
}
}
Program has been debugged through, if interested can be perfected, add a graphical user interface. This makes it easier to operate.

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.