google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
10.85k stars 2.09k forks source link

Add Automatic-Module-Name manifest entry to Java jar files #2451

Open dkkopp opened 3 years ago

dkkopp commented 3 years ago

What language and solver does this apply to? Java

Describe the problem you are trying to solve. The current Linux jar file cannot be used with the Java module system because it’s file name cannot be converted into an automatic module name. Adding this additional manifest entry will fix this.

Describe the solution you'd like Add Automatic-Module-Name: com.google.ortools to the ortools-java-xxx.jar file

Add Automatic-Module-Name: com.google.ortools.linux to the ortools-linux-xxx-xxxx.jar file.

Similar automatic module names should be added to the other os specific jar files (i.e .windows, .mac)

Mizux commented 2 years ago

Do you have sample and maven documentation related to this field ? since the jar is generated by our pom.xml ....

dkkopp commented 2 years ago

You can add it via the maven jar plugin:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Automatic-Module-Name>com.google.ortools</Automatic-Module-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
Mizux commented 2 years ago

http://branchandbound.net/blog/java/2017/12/automatic-module-name/

Mizux commented 2 years ago

Will postpone it after release since I need to change our pom.xml runtime template to add a new variable then adapt cmake and makefile to change it.

DevNote add

  1. to all pom.xml in https://github.com/google/or-tools/tree/stable/ortools/java add

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Automatic-Module-Name>@JAVA_PACKAGE@</Automatic-Module-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
  2. For pom-native.xml.in need to use:

              <Automatic-Module-Name>@JAVA_PACKAGE@.@JAVA_PLATFORM_OS@</Automatic-Module-Name>

    rework: https://github.com/google/or-tools/blob/86d4c543f717fa8716a9d66c25143660668bf825/cmake/java.cmake#L44-L52 to introduce JAVA_PLATFORM_OS and JAVA_PLATFORM_ARCH so NATIVE_IDENTIFIER become

    set(NATIVE_IDENTIFIER "${JAVA_PLATFORM_OS}-${JAVA_PLATFORM_ARCH}")

    todo(mizux): Add JAVA_ prefix to NATIVE_IDENTIFIER todo(mizux): Rename NATIVE_IDENTIFIER to PLATFORM_IDENTIFIER ?

  3. also fix Makefile.java https://github.com/google/or-tools/blob/86d4c543f717fa8716a9d66c25143660668bf825/makefiles/Makefile.java.mk#L67-L80 and https://github.com/google/or-tools/blob/8d692f30f37547a4701b436ea02d9376f5625cf6/makefiles/Makefile.java.mk#L424-L435 need to add

    $(SED) -i -e 's;@JAVA_PLATFORM_OS@;$(JAVA_PLATFORM_OS);' \
    $(TEMP_JAVA_DIR)$S$(JAVA_ORTOOLS_NATIVE_PROJECT)$Spom.xml

see: https://github.com/google/or-tools/blob/8d692f30f37547a4701b436ea02d9376f5625cf6/ortools/java/com/google/ortools/Loader.java#L34 ref: http://java-native-access.github.io/jna/5.10.0/javadoc/com/sun/jna/Platform.html#RESOURCE_PREFIX