Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

public class ABC {
    public ABC() {
        File file = new File("xyz.xml");

but when I run my jar as follows:

java -jar filename.jar arguments....

then it is showing error:

java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:120)
at com.ensarm.niidle.web.proxy.ABC.<init>(ABC.java:47)

How can I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
123 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you need to read file content in JARs, you can not use File class directly. Using ClassLoader to load it:

// for example read the SeleniumConfiguration.xml in the default package

InputStream input = SeleniumConfiguration.class.getResourceAsStream("/SeleniumConfiguration.xml");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...