Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
*
*/
package de.tutorials;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
/**
* @author Tom
*
*/
public class JarFileCreationExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.put(new Attributes.Name("main-class"), HelloWorld.class
.getName());
JarOutputStream jarOutputStream = new JarOutputStream(
new FileOutputStream("c:/tutorials.jar"), manifest);
ZipEntry zipEntry = new ZipEntry(HelloWorld.class.getName().replace(
".", "/")
+ ".class");
jarOutputStream.putNextEntry(zipEntry);
InputStream inputStream = JarFileCreationExample.class
.getResourceAsStream("HelloWorld.class");
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) > 0) {
jarOutputStream.write(buffer, 0, bytesRead);
}
inputStream.close();
jarOutputStream.closeEntry();
jarOutputStream.flush();
jarOutputStream.close();
}
}
/**
*
*/
package de.tutorials;
/**
* @author Tom
*
*/
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
C:\>java -cp .\tutorials.jar de.tutorials.HelloWorld
Hello World!