2

I'm trying to use Microsoft Application Insights with my spring boot application.

It uses JAXB to load the xml config from ApplicationInsights.xml (stored in /java/main/resources) using the following code: https://github.com/Microsoft/ApplicationInsights-Java/blob/master/core/src/main/java/com/microsoft/applicationinsights/internal/config/JaxbAppInsightsConfigurationBuilder.java

This works fine when running the spring boot application via gradle (as the resource exists in the normal file system).

However if I create a jar file for this project and attempt to run it then I see the following error:

javax.xml.bind.UnmarshalException
 - with linked exception:
[java.io.FileNotFoundException: C:\Users\u\Code\ExperimentationService\file:\C:\Users\u\Code\ExperimentationService\build\libs\experimentationService-0.1.0.jar!\ApplicationInsights.xml (The filename, directory name or volume label syntax is incorrect)]

I see the same problem when running in a linux environment also.

Is there anything I can do to make the xml file available to the unmarshaller or is this something that needs to change in the sdk for Application Insights?

Xstian
  • 8,184
  • 10
  • 42
  • 72
Septih
  • 1,436
  • 17
  • 40

2 Answers2

4

This looks like a bug in the SDK. I stepped through the SDK code with a debugger, and it actually finds the file inside the jar, it just can't read it (as this question states, it doesn't exist on the filesystem, but in a jar).

One thing you could try in the meantime is putting the XML file in the same directory as the jar (the SDK will check it for a config file). I happen to know the AppInsights team - I'll follow up with them to see if we can publish a fix. Will edit the question when I find out more.

EDIT:

I spoke with the AppInsights Java SDK team. The bug has been fixed, and it should be out next week with the new version.

EDIT:

Here's the PR: https://github.com/Microsoft/ApplicationInsights-Java/pull/257

Community
  • 1
  • 1
aoetalks
  • 1,741
  • 1
  • 13
  • 26
0

You should use the class loader.

Windows:

c:\your-jar-file.jar/path/of/your/file/foo.xml

Linux:

/home/your-jar-file.jar/path/of/your/file/foo.xml

Code

InputStream is = this.getClass().getClassLoader().getResourceAsStream("path/of/your/file/foo.xml");
Xstian
  • 8,184
  • 10
  • 42
  • 72
  • This would need to change inside the sdk rather than my project - correct? I can't see a way to override how the sdk gets it's config. – Septih Aug 03 '15 at 14:05