load-on-startup problem tomcat
I want to load a class on tomcat startup which will actually initialize variables in other classes.
i have edited the appName/WEB-INF/web.xml as follows
<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes
how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null
java tomcat
add a comment |
I want to load a class on tomcat startup which will actually initialize variables in other classes.
i have edited the appName/WEB-INF/web.xml as follows
<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes
how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null
java tomcat
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29
add a comment |
I want to load a class on tomcat startup which will actually initialize variables in other classes.
i have edited the appName/WEB-INF/web.xml as follows
<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes
how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null
java tomcat
I want to load a class on tomcat startup which will actually initialize variables in other classes.
i have edited the appName/WEB-INF/web.xml as follows
<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes
how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null
java tomcat
java tomcat
asked Sep 16 '11 at 21:19
user949550user949550
12
12
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29
add a comment |
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29
add a comment |
4 Answers
4
active
oldest
votes
There are two problems:
The compiled class needs to go into a folder structure base on the package name. In your case a folder called
Loader
In order to call the servlet, you need to add a
<ServletMapping>
to yourweb.xml
file
add a comment |
The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.
add a comment |
This is the solution for Tomcat 7.0
Step 1:
Create war file for your webapp/servlets.
If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.
Step 2:
Find out the home folder for your tomcat.
For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
This will print out couple of global variable names.
Note down the one for CATALINA_HOME.
Step 3:
Copy the war file from Step 1 in CATALINA_HOME/webapps
Step 4:
Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
<Manager pathname=""/>
</Context>
Change docBase to point to location where you copied the war file in Step 3.
Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
Your servlets will be automatically started.
Hope this helps.
add a comment |
This is how I fix it on tomcat 9:
Edit the
conf/context.xml
file and addreloadable="false"
to the<Context>
tag.
<Context reloadable="false">
Edit the
conf/server.xml
file and adddeployOnStartup="false"
to the<Host>
tag.
<Host appBase="webapps" deployOnStartup="false" …>
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7450497%2fload-on-startup-problem-tomcat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two problems:
The compiled class needs to go into a folder structure base on the package name. In your case a folder called
Loader
In order to call the servlet, you need to add a
<ServletMapping>
to yourweb.xml
file
add a comment |
There are two problems:
The compiled class needs to go into a folder structure base on the package name. In your case a folder called
Loader
In order to call the servlet, you need to add a
<ServletMapping>
to yourweb.xml
file
add a comment |
There are two problems:
The compiled class needs to go into a folder structure base on the package name. In your case a folder called
Loader
In order to call the servlet, you need to add a
<ServletMapping>
to yourweb.xml
file
There are two problems:
The compiled class needs to go into a folder structure base on the package name. In your case a folder called
Loader
In order to call the servlet, you need to add a
<ServletMapping>
to yourweb.xml
file
answered Sep 16 '11 at 21:25
nfechnernfechner
15.1k53960
15.1k53960
add a comment |
add a comment |
The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.
add a comment |
The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.
add a comment |
The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.
The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.
answered Sep 16 '11 at 21:26
Juha PalomäkiJuha Palomäki
22.5k22938
22.5k22938
add a comment |
add a comment |
This is the solution for Tomcat 7.0
Step 1:
Create war file for your webapp/servlets.
If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.
Step 2:
Find out the home folder for your tomcat.
For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
This will print out couple of global variable names.
Note down the one for CATALINA_HOME.
Step 3:
Copy the war file from Step 1 in CATALINA_HOME/webapps
Step 4:
Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
<Manager pathname=""/>
</Context>
Change docBase to point to location where you copied the war file in Step 3.
Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
Your servlets will be automatically started.
Hope this helps.
add a comment |
This is the solution for Tomcat 7.0
Step 1:
Create war file for your webapp/servlets.
If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.
Step 2:
Find out the home folder for your tomcat.
For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
This will print out couple of global variable names.
Note down the one for CATALINA_HOME.
Step 3:
Copy the war file from Step 1 in CATALINA_HOME/webapps
Step 4:
Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
<Manager pathname=""/>
</Context>
Change docBase to point to location where you copied the war file in Step 3.
Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
Your servlets will be automatically started.
Hope this helps.
add a comment |
This is the solution for Tomcat 7.0
Step 1:
Create war file for your webapp/servlets.
If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.
Step 2:
Find out the home folder for your tomcat.
For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
This will print out couple of global variable names.
Note down the one for CATALINA_HOME.
Step 3:
Copy the war file from Step 1 in CATALINA_HOME/webapps
Step 4:
Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
<Manager pathname=""/>
</Context>
Change docBase to point to location where you copied the war file in Step 3.
Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
Your servlets will be automatically started.
Hope this helps.
This is the solution for Tomcat 7.0
Step 1:
Create war file for your webapp/servlets.
If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.
Step 2:
Find out the home folder for your tomcat.
For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
This will print out couple of global variable names.
Note down the one for CATALINA_HOME.
Step 3:
Copy the war file from Step 1 in CATALINA_HOME/webapps
Step 4:
Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
<Manager pathname=""/>
</Context>
Change docBase to point to location where you copied the war file in Step 3.
Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
Your servlets will be automatically started.
Hope this helps.
answered Jul 29 '13 at 6:22
Priyank DesaiPriyank Desai
2,1341914
2,1341914
add a comment |
add a comment |
This is how I fix it on tomcat 9:
Edit the
conf/context.xml
file and addreloadable="false"
to the<Context>
tag.
<Context reloadable="false">
Edit the
conf/server.xml
file and adddeployOnStartup="false"
to the<Host>
tag.
<Host appBase="webapps" deployOnStartup="false" …>
add a comment |
This is how I fix it on tomcat 9:
Edit the
conf/context.xml
file and addreloadable="false"
to the<Context>
tag.
<Context reloadable="false">
Edit the
conf/server.xml
file and adddeployOnStartup="false"
to the<Host>
tag.
<Host appBase="webapps" deployOnStartup="false" …>
add a comment |
This is how I fix it on tomcat 9:
Edit the
conf/context.xml
file and addreloadable="false"
to the<Context>
tag.
<Context reloadable="false">
Edit the
conf/server.xml
file and adddeployOnStartup="false"
to the<Host>
tag.
<Host appBase="webapps" deployOnStartup="false" …>
This is how I fix it on tomcat 9:
Edit the
conf/context.xml
file and addreloadable="false"
to the<Context>
tag.
<Context reloadable="false">
Edit the
conf/server.xml
file and adddeployOnStartup="false"
to the<Host>
tag.
<Host appBase="webapps" deployOnStartup="false" …>
edited Nov 16 '18 at 11:35
answered Nov 16 '18 at 10:29
Unai ViviUnai Vivi
2,37232044
2,37232044
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7450497%2fload-on-startup-problem-tomcat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.
– Jayesh
Jul 29 '13 at 6:29