The system cannot find the file specified while starting a windows service from a Java App using Apache Commons Daemon

SpartaSixZero

I have the following file structure from Eclipse for my Java app which I turned into a windows service using Apache Commons Daemon.

SubscriberACD
    /Maven Dependencies
    /src/main/java
        /org.SubscriberACD
            /Subscriber.java
    /src/test/java
    /JRE System Librar
    /src
    /target
    config.xml
    pom.xml

In Subscriber.java, here is where the string is defined:

    private static final String CONFIG_FILE = "config.xml";

Here is the code snippet to read from the xml file (based off of this post: Java: How to read and write xml files?):

   Document document;
   DocumentBuilderFactory doc_builder_factory = DocumentBuilderFactory.newInstance();

   try {
       DocumentBuilder doc_builder = doc_builder_factory.newDocumentBuilder();
       document = doc_builder.parse(CONFIG_FILE);

My file directory for the service looks like this:

E:\SubscriberACD
     \bin
        \subscriberACD.exe
        \subscriberACDw.exe
     \classes
        \org
           \SubscriberACD
               \Subscriber.class
               \config.xml
        \3rdpartyjarfiles
        \SubscriberACD.jar
     \logs

Notice how I stuck config.xml under SubscriberACD under classes just to try it out. But it didn't work. Also worth noting that I also exported my project as a SubscriberACD.jar and put that under \classes folder. From eclipse, it does look like config.xml is also being packaged in that jar. I get the following error when I try to start my windows service:

2016-04-16 15:08:27 Commons Daemon procrun stderr initialized
Exception in thread "main" n\config.xml (The system cannot find the file specified)
java.lang.NumberFormatException: For input string: "null"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.parseInt(Integer.java:527)
    at zmq.TcpAddress.resolve(TcpAddress.java:105)
    at zmq.Address.resolve(Address.java:98)
    at zmq.SocketBase.connect(SocketBase.java:510)
    at org.zeromq.ZMQ$Socket.connect(ZMQ.java:1246)
    at org.SubscriberACD.Subscriber.start(Subscriber.java:114)
    at org.SubscriberACD.Subscriber.windowsService(Subscriber.java:61)

Was there some additional configuration that I missed?

David

Try this: Put the file config.xml directly into the classes folder:

E:\SubscriberACD\classes\config.xml

Then in Subscriber.java try to load the file like this:

Document document;
DocumentBuilderFactory doc_builder_factory = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder doc_builder = doc_builder_factory.newDocumentBuilder();
    try(InputStream instream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.xml")) {
        document = doc_builder.parse(instream);
    }
} catch(SAXException | ParserConfigurationException e) {
    throw new RuntimeException(e);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java - The system cannot find the file specified when using ProcessBuilder directory()

The system cannot find the file specified executable from java

Using Apache Commons CSV to read file starting from the second line

The system cannot find the file specified in java

The system cannot find the file specified java

Windows Process Activation Service Error 2:The system cannot find the file specified

Cannot run container in Docker for Windows: "System cannot find the file specified"

Windows 10 : cannot delete folder "The system cannot find the file specified"

FileNotFoundError: [WinError 2] The system cannot find the file specified while loading model from s3

svn head revision from a remote repository in windows batch file - the system cannot find the file specified

The System cannot find the file specified error while deleting folder

The system cannot find the file specified while programming C

System cannot find file specified

The system cannot find the file specified

The system cannot find the file specified windows error python

Golang beginner, on Windows: System cannot find file specified

subprocess.run not working in windows - The system cannot find the file specified

Windows 10 Command Prompt system cannot find the file specified

Error: "The system cannot find the file specified" when using -r flag

java.io.FileNotFoundException: the system cannot find the file specified

Java system cannot find file specified when trying to execute

Java Azure function : System cannot find file specified

The system cannot find the file specified but file exists

System Center Service Management Automation (SMA) PowerShell Runbook Invoke-NcSsh : The system cannot find the file specified

Cannot start Tomcat 7 as Apache Commons Daemon

AppStartError: CreateProcess: The system cannot find the file specified

Android Studio The system cannot find the file specified

Cassandra - "The system cannot find the file specified"

Batch file The system cannot find the path specified