Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6675283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:08+00:00 2026-05-26T03:50:08+00:00

I am trying to make a Daemon class in java so I have implemented

  • 0

I am trying to make a Daemon class in java so I have implemented a class which implements Daemon but when I run it, I always get errors.

The class that I use for that is ;

public class RemoteAgentDaemon implements Daemon {
    private Logger logger;
    public LocalAgent frame;

    public void destroy() {
        logger.info("Server was destroyed ....");
    }

    public void init(DaemonContext arg0) throws Exception {
        frame = new LocalAgent();
        logger = Logger.getLogger("daemon");
        logger.addAppender(new ConsoleAppender(new PatternLayout("%d{DATE} [%t] %5p - %m%n")));
        logger.setLevel(Level.ALL);
    }

    public void start() throws Exception {
        logger.info("Server was started ....");
        frame.listenSocket();
    }

    public void stop() throws Exception {
        logger.info("Server was stoped ....");
    }
}

And the script that I use for running the daemon is ;

#!/bin/sh

# Setup variables
EXEC=/usr/bin/jsvc
JAVA_HOME=/usr/lib/jvm/java-6-sun
CLASS_PATH="/usr/share/java/commons-daemon.jar":"/home/mehmet/Desktop/remoteAgent.jar"
CLASS=example.Main
USER=foo
PID=/tmp/example.pid
LOG_OUT=/tmp/example.out
LOG_ERR=/tmp/example.err

do_exec()
{
    $EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
}

case "$1" in
    start)
        do_exec
            ;;
    stop)
        do_exec "-stop"
            ;;
    restart)
        if [ -f "$PID" ]; then
            do_exec "-stop"
            do_exec
        else
            echo "service not running, will do nothing"
            exit 1
        fi
            ;;
    *)
            echo "usage: daemon {start|stop|restart}" >&2
            exit 3
            ;;
esac

When I run the script I got this error;

java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2444)
at java.lang.Class.getMethod0(Class.java:2687)
at java.lang.Class.getMethod(Class.java:1620)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:129)
    Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 5 more
    Cannot load daemon
    Service exit with a return value of 3

Can you please help me to solve this ?

Thank you all

EDIT :

now I have changed my class path to ;

CLASS_PATH=”/home/mehmet/Desktop/apache-log4j-1.2.16″:”/home/mehmet/Desktop/remoteAgent.jar”

but now I got an error ;

Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader Service exit with a return value of 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:50:09+00:00Added an answer on May 26, 2026 at 3:50 am
    java.lang.NoClassDefFoundError: org/apache/log4j/Layout
    

    The above indicates that you should add log4j to your classpath (edit CLASS_PATH in the script with the location of your log4j jar)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to make an init script using start-stop-daemon. I am stuck
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
trying to make a page which will recursively call a function until a limit
I am trying to make a socket server that spews mouse move events, in
im trying make one replace in string from a array but this dont work
I am trying to write a class that will calculate checksums using multiple processes,
I'm trying make one treeView with infinite subgroups. I can add my groups but
I'm trying to make a change to an old appengine application, but now after
Trying to make a Grid Like this using java and I'm assuming a 2d

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.