Closed nandhusriram closed 9 years ago
@nandhusriram can you show your java code?
My Servlet Listener
public void contextInitialized(ServletContextEvent event)
{
try
{
LOG.debug("contextInitialized called {} ",event);
ServletContext sc = event.getServletContext();
Manifests.DEFAULT.append((new ServletMfs(sc)));
LOG.debug("adding servlet {} ",sc);
}catch (Exception ex) {}
My Manifest reader
if(Manifests.exists("Class-Path")) versionTextBuilder.append( String.format("Class-Path is %s %n",Manifests.read("Class-Path")));
Both of the java files are in a jar file that gets deployed with war , I could paste the Manifest if you need one.
Do you have this file in your WAR: WEB-INF/classes/META-INF/MANIFEST.MF
?
not under classes warname/META-INF/MANIFEST.MF
In this case, you should also add this:
Manifests.DEFAULT.append(new ClasspathMfs());
let me try that real quick
still same issue
is there any order for appending the Mfs , I added ServletMfs and then ClassPath
Nope, the order doesn't matter. If none of them can find anything, it means that you don't have MANIFEST.MF
available in your JAR/WAR. Are you sure you have the file available?
Yes I am looking at the exploded war and its there , its finding other variables and even for the variable I am interested in , its finding that not the correct one, looks to me its finding the variable "class-path" from some other manifest.mf
Ah, sure, there could be many duplicates of the same attribute in multiple files. jcabi-manifests gets the first one available.
how could I force to load mine first , if thats even a possibility ?
How about this:
for (InputStream stream : new ClasspathMfs().fetch()) {
Manifest manifest = new Manifest(stream);
Attributes attrs = manifest.getMainAttributes();
for (final Object key : attrs.keySet()) {
String value = attrs.getValue(Attributes.Name.class.cast(key));
System.out.println("key: " + key + ", value: " + value);
}
}
this snippet will load all available key/value pairs from all available MANIFEST.MF in classpath. I don't know how to find "yours" there though :)
Thanks , I am looking at maven archiver plugin of how to change the name of variable class-path when this is invoked, if I cannot figure that out , I might add a prefix to my values , so I can parse it
configuration>
</configuration>
I am trying to read the variable "Class-Path" added by the maven archiver to the manifest and it looks like Manifests.read("Class-Path") showing me entirely unexpected results , any ideas would be greatly appreciated?