I have an application JAR file I would like to obfuscate using ProGuard. It contains a number of PNG files that are referenced using path strings in the application, such as /my/path/image.png.
I tried using the -adaptresourcefilenames **.png resource obfuscation option but it didn't seem to have any effect.
Can ProGuard rename my PNG files somehow? I need it to rename the files and change the strings in class files that reference it.
The option -adaptresourcefilenames only works for resource files like mypackage/MyClass.properties that have a corresponding class file mypackage/MyClass.class. If the class name is obfuscated the resource file name is obfuscated along.
ProGuard doesn't obfuscate other file names, since the names are often not specified as a single literal string in the code, making it difficult or impossible to replace them.
Related
I have a situation where a external jar is loading a class which has a static block to initialise some configurations , i want to stop that happening . the only way i see is to extract that jar and remove that class file and write my own implementaion of that class. can this be done or is there any way i can stop that class from loading and load my own implementation
JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory.
See: https://docs.oracle.com/en/java/javase/11/docs/specs/jar/jar.html
So it is possible to replace a class file. But I would prefer the way vanje suggested in the comment of your question.
So I have a jar file (eclipselink-jpa-modelgen_2.1.1.v20100817-r8050.jar) which contains META-INF/services directory which just contains a file named javax.annotation.processing.Processor (that's it, nothing else) The funny thing is, its not an executable. It is a just text file which contains this data:
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
I also have eclipselink.jar which have above class file
My question is, is there any chance that eclipselink-jpa-modelgen_2.1.1.v20100817-r8050.jar is being used by application during runtime.
Or in simple words is it safe to delete that jar?
I'm trying to use a binary resource in my application. I need it for crypt/decript passwords. The file is located in the "classes" folder of my ear, just like properties files that the application access without problems.
Anyway, I am loading the files as follows.
ClassLoader.class.getResourceAsStrem(/file.xxxx);
But in the case of the binary file the resultant InputStream is null.
The question is, why it works with properties files and does not with a binary file? What can i do for load a binary resource?
Best regards.
Ensure that the file is available on the class path.
Use the context class loader instead - this will ensure that the code trying to look up the file can reside in a shared library as well.
Something on the lines of:
Thread.currentThread().getContextClassLoader().getResourceAsStream(..)
Hope that helps.
Instead of ClassLoader use the class name where you are currently in.
YourClass.class.getResourceAsStrem(/file.xxxx);
Problem statement:
I have a jar file with a set of configuration files in a package mycompany/configuration/file/.
I don't know the file names.
My intention is to load the file names at runtime from the jar file in which they are packaged and then use it in my application.
As far as I understood:
When I use the ClassLoader.getResources("mycompany/configuration/file/") I should be getting all the configuration files as URLs.
However, this is what is happening:
I get one URL object with URL like jar:file:/C:/myJarName.jar!mycompany/configuration/file/
Could you please let me know what I am doing wrong ?
For what you are trying to do I don't think it is possible.
getResource and getResources are about finding named resources within the classloader's classpath, not listing values beneath a directory or folder.
So for example ClassLoader.getResources("mycompany/configuration/file/Config.cfg") would return all the files named Config.cfg that existed in the mycompany/configuration/file path within the class loader's class path (I find this especially useful for loading version information personally).
In your case I think you might almost have half a solution. The URL you are getting back contains the source jar file (jar:file:/C:/myJarName.jar). You could use this information to crack open the jar file a read a listing of the entries, filtering those entries whose name starts with "mycompany/configuration/file/".
From there, you could then fall back on the getResource method to load a reference to each one (now that you have the name and path)
Currently i have placed the Displaytag.properties in 'src' directory, and it is working fine. Is it posssible to have this file on some different location like src/comp/bre/sub/config ?
From the docs for the DisplayTag library:
For the whole web application, create
a custom properties file named
"displaytag.properties" and place it
in the application classpath.
Displaytag will use the locale of the
request object to determine the locale
of the property file to use; if the
key required does not exist in the
specified file, the key will be loaded
from a more general property file.
So in your case make sure your build scripts (or IDE) copy your displaytag.properties file from src/comp/bre/sub/config the onto the classpath.
In an IDE this is normally as simple as specifying that a particular directory contains source code. In ANT just make sure the displaytag.properties file ends up in your /WEB-INF/classes.
Find the code which loads this properties file and add the new path. You can also place it in a folder yourProject/src/resources/ and add it to the classpath. Therefore, your properties file will be placed in the binary folder once the code will be compiled.