How to use --hash-modules and JDK 9 JAR tool-path options -module-paths?

I would like to compute and write a hash of a module that matches a given pattern, which is directly dependent on the modular JAR file being updated. To do this, use the --hash-modules

and options --module-path

. There are my attempts:

jar --hash-modules com.me.util --module-path "dist\com.me.jar;dist\com.me.util.jar"  --update --file dist/com.me.jar --main-class=com.me.A --verbose --module-version 0.1 -C build/modules/com.me module-info.class build/modules/com.me/com/me/A.class build/modules/com.me/com/me/B.class

jar --hash-modules "com.me.util;com.me.util" --module-path "dist\com.me.jar;dist\com.me.util.jar"  --update --file dist/com.me.jar --main-class=com.me.A --verbose --module-version 0.1 -C build/modules/com.me module-info.class build/modules/com.me/com/me/A.class build/modules/com.me/com/me/B.class

      

When I try to do this, I get a warning message: "no module has been written to hash in com.me".

These commands will create * .jar files (modules) without any errors, but they will not add hash information. I would like to see this information and take advantage of this functionality ( --hash-modules

and --module-path

). Please tell me how to do it!


The complete project folder structure can be found here .

My experiments and working examples of using the jar tool options: here .

The following operations are described in the Java Platform, Standard Edition Tools Reference (jar) .

+3


source to share


2 answers


Gautam Uddhav , thank you for the link to additional documentation.

After reading the documentation carefully ( Packaging: Modular JAR files (JEP 261: Modular system) and --hash-modules=PATTERN

(Java Platform, standard edition of tools)
), I figured out what parameters should be given to solve this problem.

Here's a working example:

#Working command:
#Create module:
jar --hash-modules "com.me" --module-path "dist/com.me.jar" --verbose --create --file dist/com.me.util.jar -C build/modules/com.me.util module-info.class  build/modules/com.me.util/com/me/util/Util.class
jar --hash-modules "com.me" --module-path "dist/com.me.jar" -v -c -f dist/com.me.util.jar -C build/modules/com.me.util module-info.class  build/modules/com.me.util/com/me/util/Util.class

#Update module:
jar --hash-modules "com.me" --module-path "dist/com.me.jar" --verbose --update --file dist/com.me.util.jar -C build/modules/com.me.util module-info.class
jar --hash-modules "com.me" --module-path "dist/com.me.jar" -v -u -f dist/com.me.util.jar -C build/modules/com.me.util module-info.class

      



To see the result, use the following command:

#Describe module:
jar --file dist/com.me.util.jar --describe-module

      

The result should be like this:

com.me.util jar:file:///C:/my_ch1_9/dist/com.me.util.jar/!module-info.class
exports com.me.util
requires java.base mandated
hashes com.me SHA-256 85c0539e4ca9a01b00f4c29a1a8b01cd452d1d97f437166b8bb415046dac65cb

      

+4


source


--hash-modules <ProvidePatternHere>

/ * you are missing a picture * /

http://openjdk.java.net/jeps/261

Hashes are recorded only for modules whose names match the regular expression



--module-path <LinkToModule>

      

So a complete example would be something like this:

jar --hash-modules "*.jar" --module-path "dist" ... and your other stuffs here.

      

+2


source







All Articles