从jar共享库访问资源

时间:2015-04-02 15:54:59

标签: java jar resources

从test.java,我如何访问以读取contacts.jar库中的Contact.xml文件?

波纹管代码返回null。

package views;

import fr.hznteam.contacts.Contact;
import fr.hznteam.errors.ResourceException;

import java.io.InputStream;


    public class Test {

        private static final String TAG = "Test ";

        public static void main(String[] args) throws ResourceException {

            InputStream is = Contact.class.getResourceAsStream("/fr/hznteam/contacts/sql/Contact.xml");
            System.out.println(TAG + "resource from jar " + is);

        }

包结构:

enter image description here

1 个答案:

答案 0 :(得分:0)

这是有效的(参见上面的评论)。在对象实例中使用

getClass().getResourceAsStream("/absolute/class_path/to/resource.file"))
相关问题