Skip to content

larrybolt/example.java.helloworld

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

example.java.helloworld (with signing of the jar file using a make file)

This is "Hello World" Example for Java.

The structure HelloWorld package is like this:

example.java.helloworld/
|-- HelloWorld
|   `-- Main.java
|-- LICENSE
|-- Manifest.txt
`-- README.md

Compile class

For compile the main class for package, execute the follow command:

javac HelloWorld/Main.java

This generate the Main.class file into HelloWorld directory.

Run class

For run the main class for package, execute the follow command:

java -cp . HelloWorld.Main

This show the Hello world message.

Create a JAR file

For pack the main class for package as a JAR file, execute the follow command:

jar cfme Main.jar Manifest.txt HelloWorld.Main HelloWorld/Main.class

Run a JAR file

For run the JAR file packed, execute the follow command:

java -jar Main.jar

This show the Hello world message.

Signing of jar

To sign the jar you need to create a keystore, you acn do this with next command:

keytool -genkeypair \
  -alias signFiles \
  -validity 300 \
  -keystore keystore.jks

To export the public certificate use:

keytool -export -keystore keystore.jks -alias signFiles -file public.cer

For the actual signing of the jar file:

jarsigner -signedjar \
  signed-HelloWorld.jar HelloWorld.jar signFiles \
  -tsa http://sha256timestamp.ws.symantec.com/sha256/timestamp \
  -keystore keystore.jks

In order to verify the jar is correctly signed:

jarsigner -verify signed-HelloWorld.jar -keystore tmp-keystore.jks

If someone else wants to verify he should first import you public certificate:

keytool -importcert \
  -file public.cer \
  -storepass tmptmp \
  -noprompt \
 -keystore tmp-keystore.jks

Automation

All these steps have also been automated for you in a [Makefile](makefile) .

You can simply run make in the directory to:

  • compile the Main.java class
  • bundle it into a jar
  • create a keystore and prompt for password and info
  • sign the jar
  • export the public certificate

Other useful commands are clean to remove all generated files, and verify to create a new keystore, import the public certificate and verify the signed jar using that new keystore.

Reference

About

"Hello World" Example for Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 91.5%
  • Java 8.5%