7

Using ProGuard on my jar files has broken my calls to class.getResource(""). I have seen that in the ProGuard manual you need to specify the -keepdirectories mypackage (manual link). However, I have specified the -keepdirectories option and it doesn't seem to be working. I think there is something wrong with my ProGuard configuration. I have also looked at this related question, but I am having trouble getting the -keeppackagenames working as well.

In my code I have something similar to the following.

package com.example.mypackage;
public class MyClass{
    public static void main(String [] args){
        //url is always returned as null
        URL url = MyClass.class.getResource("");
        //do additional stuff including retrieving manifest file
    }
}

ProGuard Configuration

-injars ...
-outjars ...
-libraryjars ...

-dontoptimize
-keepattributes SourceFile,LineNumber,Table,LocalVariable*Table,*Annotation*
-renamesourcefileattribute SourceFile

-repackageclasses
-overloadaggressively

-keep public class com.example.mypackage.MyClass{
    public static void main(java.lang.String[]);
}
-keepdirectories com.example.mypackage,com.example.mypackage.MyClass
-keeppackagenames com.example.mypackage,com.example.mypackage.MyClass
Community
  • 1
  • 1
Gregory Peck
  • 636
  • 7
  • 22

2 Answers2

7

ProGuard expects dots in packages names, and slashes in file names and directory names:

-keeppackagenames com.example.mypackage
-keepdirectories  com/example/mypackage
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
0

I found that I was able to get it working with the following modification to -keepdirectories

-keepdirectories **mypackage**

However, this feels sort of clunky, and while it works, I feel as if there is a better solution out there.

Gregory Peck
  • 636
  • 7
  • 22