user727272
user727272

Reputation: 475

how to add an xml file to the java application's classpath in eclipse?

I need an xml file to be accessed via the classpath in a java application i am creating . how to achieve it in eclipse

Upvotes: 17

Views: 39460

Answers (3)

Joseph Ottinger
Joseph Ottinger

Reputation: 4951

Put the directory containing the XML in the runtime classpath, then use className.Class.getResourceAsStream() to get an InputStream containing the XML.

Upvotes: 1

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298988

I'd generate a separate resources folder, right-click it and select Build Path > Use as Source Folder. That way it's on the class path, but you're not mixing it with your Java source files

Upvotes: 24

Imran
Imran

Reputation: 3024

Put it in java source folder, and use it as resource

Upvotes: 1

Related Questions