Resources are not being loaded for shade plugin

225 views Asked by At

The below code is able to scan all the dependencies and load the resources when I am executing it from IntelliJ as IntelliJ resolves dependencies from the .m2 repo, but it's not able to load anything when running from the fat jar created by shade. any help?
The below code is not producing any output when executed from shade plugin, while from eclipse it is printing all the relevant properties.

ClassLoader str = ClassLoader.getSystemClassLoader();

try {
  Enumeration<URL> resURLs = str.getResources("properties/sample/i18n-resources.properties");
  while (resURLs.hasMoreElements()) {
    URL resURL = (URL) resURLs.nextElement();
    System.out.println("file path : " + resURL.getFile());
  }
}
catch (Exception e){
    System.out.println("resource exception");
}

pom file :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.2</version>
  <configuration>
    <filters>
    <filter>
      <artifact>*:*</artifact>
      <excludes>
      <exclude>META-INF/*.SF</exclude>
      <exclude>META-INF/*.DSA</exclude>
      <exclude>META-INF/*.RSA</exclude>
      </excludes>
    </filter>
      </filters>
        <transformers>
            <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.sample.extract.samples.SampleClient</mainClass>
            </transformer>
        </transformers>
          <shadedArtifactAttached>true</shadedArtifactAttached>
          <shadedArtifactId>application</shadedArtifactId>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
</plugin>
1

There are 1 answers

0
Klapsa2503 On

Analyze it as follows:

  • remove configs such as shadedArtifactAttached, shadedArtifactId, filters - basically just keep transformers only. There is simple example here
  • before try {} catch add some directory logging - print what is in current . directory, print what is in ./properties etc.

My suspisions:

  • properties files are not included
  • path to file is invalid (the invocation directory differs between InteliJ and running via shade)

Also if possible please attach the full code sample so anyone can download and run it