How to set bootstrap entries of Tomcat without using Eclipse? - java

I am using Tomcat 7. JDK1.6.
I was trying to get the list of runtime JVM.
Code:
for (int i=0; i<VirtualMachine.list().size(); i++) {
VirtualMachineDescriptor vi = VirtualMachine.list().get(i);
System.out.println("**PID :"+vi.id()+" **DISPLAYNAME:"+vi.displayName());
}
It works fine when I compile it in Eclipse. But when I exported it in to a war package, and put the war file into webapps folders of Tomcat, it returns empty list.
And eclipse use the same tomcat too. I found that configuration files in eclipse are same with those files in tomcat. But there are bootstrap entries and user entries in eclipse. User entries are pointed to Tomcat 7. I want to try to set same configuration to Tomcat, but I don'
t know how to set bootstrap entries to Tomcat.

When I debugged the tools.jar code and found the root cause,
In short, what you need to do is just remove the all the following setting in catalina.bat or catalina.sh, before you start tomcat on windows or unix. Enjoy it! :-)
-Djava.io.tmpdir="%CATALINA_TMPDIR%"
Welcome discussion, maybe there are much earier way then mine.

Related

WebSwing to Tomcat deployment (Configuration)

I followed the steps given from the official source here.
To deploy Webswing to Tomcat, follow the following steps:
Create a new folder named webswing in Tomcat’s home folder and unzip
the Webswing distribution to this folder.
Move webswing-server.war from the distribution package to Tomcat’s
webapps folder.
In conf/catalina.properties file add the following properties.
webswing.warLocation=webapps/webswing-server.war
webswing.configFile=webswing/webswing.config
webswing.tempDirBase=webswing/tmp
I followed all the steps above. But the result seems it's ERROR.
Then i tried to access(but no luck):
localhost:8080/webswing
nor
localhost:8080/webswing-server
Please take note that I'm currently using Tomcat server normally.
My specs are:
Windows 7 with 64bit, 8gb ram
JDK 8 for 64bit
Tomcat8.5.31
I thought there's no tmp folder, but after i check it out, the folder still exists there. And i also check the catalina properties, it's exactly 3lines code written already. So, What should i do to resolve this case? Any other clues?
I just tried from scratch according to documentation and have the same result.
The issue is starting directly the startup.bat
When I start the tomcat from CATALINA_HOME everything works fine, I assume starting as a service would work.
This is how I started the tomcat:
c:\_DEV\apache-tomcat-8.5.31>.\bin\startup.bat
When you start the startup.bat directly, you will see this as root cause (notice the bin in the path):
Root Cause
org.webswing.server.model.exception.WsInitException: Invalid system property webswing.warLocation: File c:\_DEV\apache-tomcat-8.5.31\bin\webapps\webswing-server.war or c:\_DEV\apache-tomcat-8.5.31\bin\webapps\webswing-server.war not found.

How to configure log4j2 with Tomcat 8.5.15

I have log4j2 jars under $CATALINA_HOME/lib:
log4j-api-2.10.0.jar
log4j-core-2.10.0.jar
log4j-jul-2.10.0.jar
export JAVA_OPTS="${JAVA_OPTS} -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager"
In catalina.properties I've got common classloader and I tried to add log4j-jul-2.10.0.jar again even if it is already under the CATALINA_HOME/lib, but no success.
common.loader="${catalina.base}/lib","${catalina.base}/lib/.jar","${catalina.home}/lib","${catalina.home}/lib/.jar","/opt/tomcat/apache-tomcat-8.5.15/lib/log4j-jul-2.10.0.jar"
I have deleted logging.properties under Tomcat and add a new log4j2.xml to path
ERRORMESSAGE:
Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"
java.lang.ClassNotFoundException: org.apache.logging.log4j.jul.LogManager
Any idea why LogManager is still missing or should I use some other jars instead. In another messages they are speaking juli.jar and extras, but in their case they have older Tomcat version, 6 or 7.
You just need to add the log4j2-api, log4j2-core and log4j2-appserver libraries into the Tomcat classpath, provide the log4j2 configuration file and remove the $CATALINA_BASE/conf/logging.properties from your installation.
This is most easily done by:
Creating a set of directories in catalina home named log4j2/lib and
log4j2/conf.
Placing log4j2-api-2.x.x.jar, log4j2-core-2.x.x.jar, and
log4j2-appserver-2.x.x.jar in the log4j2/lib directory.
Creating a file named log4j2-tomcat.xml, log4j2-tomcat.json,
log4j2-tomcat.yaml, log4j2-tomcat.yml, or log4j2-tomcat.properties
in the log4j2/conf directory.
Create or modify setenv.sh in the tomcat bin directory to include
CLASSPATH=$CATALINA_HOME/log4j2/lib/*:$CATALINA_HOME/log4j2/conf
You can force the applications that use the JUL framework to use log4j2 format changing the environment variable LOGGING_MANAGER. You can do this by adding in the setenv.sh file: LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager"
Remember that org.apache.logging.log4j.jul.LogManager is included in the log4j-jul-2.x.x.jar bridge which must be added to your classpath.
refs:
https://db-blog.web.cern.ch/blog/luis-rodriguez-fernandez/2019-03-keeping-your-logs-clean-apache-tomcat-9-log4j2-and-spring-boot
https://logging.apache.org/log4j/2.x/log4j-appserver/index.html
I know that this is a little late to answer this question, but I'm sure it could help someone struggling like me trying to configure tomcat so that it uses lo4j.
I've been working on something similar for the past 3 days, and I found out that the extras folder provided by tomcat's website are not what I need. But, you can still grab them using maven. I was able to configure tomcat so that it uses the mentioned jar files ( tomcat-extras-juli.jar and tomcat-extras-juli-adapters.jar ). Just remember to include the VM argument -Dlog4j.debug to make your life easier and catch errors quicker.
Maven repo: https://mvnrepository.com/artifact/org.apache.tomcat.extras/tomcat-extras-juli-adapters
I came upon the same problem after I included the mentioned jars provided by tomcat's repository. After a quick analysis I found that the interface org.apache.juli.WebAppProperties was not included in the jar file tomcat-extras-juli.jar which is utilized by the file org.apache.catalina.loader.WebappClassLoaderBase. After researching a bit more, I realized that the tomcat jar files are included in the Maven Repo. I downloaded the mentioned jar files under the same version of tomcat ( currently 8.5 ), plugged those jars in my tomcat installation and everything worked as expected. Now my version of tomcat uses log4j instead of juli.
log4j2 jars must be loaded along with bootstrap.jar (tomcat startup) and tomcat-juli.jar (logging)
These jars are present in CATALINA_HOME/bin directory and are responsible for
initialization of tomcat including logging.
In CATALINA_HOME/cataline.bat in case of windows, you will find below code -
set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
Here, you should add log4j2 jars at the classpath so that when tomcat starts, these jars are there.
Create in tomcat\bin\ file setenv.bat and add to file:
set "CLASSPATH=%CLASSPATH%%CATALINA_BASE%\bin;%CATALINA_BASE%\bin\log4j-core-2.10.0.jar;%CATALINA_BASE%\bin\log4j-api-2.10.0.jar;%CATALINA_BASE%\bin\log4j-jul-2.10.0.jar"
copy jars files
log4j-api-2.10.0.jar
log4j-core-2.10.0.jar
log4j-jul-2.10.0.jar
to folder tomcat\bin\
create file log4j2.xml in tomcat\bin folder

Java Debug won't unfold the WAR file On windows with netbeans

I have a little complicated problem to explain;
I have a project that I write on Netbeans that will be used as intranet application. It was a dynamic web application. And it has some File.IO operations in it . My aim is create some files on the directory where index.html in. So I try to make the program find the directory by the code below :
Session.getServletContext().getRealPath("Index.jsp");
But because of java version it didn't work so I used:
Session.getServletContext().getContextPath();
Now it shows the right path on debug but not fullpath. After debug I can find my files under c:/ not under the directory where index.html in nor even nearby my projectfolder :)
So I looked at Apache folder under Programfiles under webapps and I saw that my applications folder is not there. It didn't unfold the war file actually it seems to virtualy opens it and creates a some numbered html file under temp folder . How can I make my Tomcat work like a Tomcat on a linux system and unfold the war file and find the right folder (the main web folder) and read write files, folders etc.
Additionally I want to add the server.xml unpack config below:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
Even if you can give me a clue I would be pleased.
Thanks,
Kaan
I solved the problem . But there is a bunch of work to do . So I write down here one by one ;
Session.getServletContext().getRealPath("Index.jsp"); is not true . But not the main problem . in the brackets we must write a folder not a file to find the parent folder. After correct this, it will return null again . because Java EE 7 does not support getRealPath() method. but at the end this will be already solved by changing the version.
On Netbeans IDE , at toolbar , tools >> Servers , I removed the
tomcat server. and also uninstall the Apache Tomcat8 that comes with
Netbeans8 because there may be a version problem as I read from the
forums.
And I download Apache Tomcat7 from the official site of apache and
installed service.
I configured tomcat-users.xml config file for admin priviledges.
And I add the Tomcat7 server at netbeans from the same toolbar
(tools >> Servers)
What I saw was in the project the server was not there. I went inside
project properties , from the menu > Run , and Server combo-box was
empty. Because I was using Java EE7 and Tomcat7 needs at least Java
EE6. So I needed to change the java ee version.
What to do :
Click the files tab near projects tab. Under nbproject folder , select j2ee.platform , for Tomcat7 change the platform to 1.6 (Tomcat6 > Jave EE 1.5). than make a "clean and build" on the project .
Now the server will come at Project > properties > Run > Servers
After that I came across with another problem : (And also you may :) )
Tomcat logs from NetBeans says :
-" '127.0.0.1*' is not recognized as an internal or external command "
to correct that : Error starting Tomcat from NetBeans - '127.0.0.1*' is not recognized as an internal or external command

Apache Tomcat 8 not working. Throws HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

I am using Apache Tomcat 8 and I've JDK 1.7.
Tomcat starts running after I run "startup.bat". But when I try to run "http://localhost:8080/", it shows an error: "HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp"
Please help me to fix this.
Click here to see the screenshot
IT'S WORKING!
What I did:
Opened command prompt using "Run as administrator"
Went to the "bin" directory of Tomcat folder.
cd C:\Program Files\apache-tomcat-8.0.3\bin'
Entered 'startup' to run 'startup.bat' and the server started
Opened a web browser entered http://localhost:8080/ and it worked like charm. This also started generating Tomcat log files too.
The only different thing I performed is "Run as administrator".
But I checked with Tomcat7 it did not require me to "Run as administrator" but it worked; not sure why
Check the lib folder of your tomcat installation. It must contain the JARs jasper-el.jar, jasper.jar, and jsp-api.jar. If they exist, maybe you should add Tomcat 8 in the Java Build Path for your project.
EDIT:
What you can do is to run shutdown.bat. Then look for a file called catalina.out in the logs folder of your tomcat installation. Open it in a text editor, delete all of its contents and save. Then try running startup.bat again. Next copy the contents of catalina.out and paste them here. This may help other people solve your problem.
I had the very same error attempting to reach the manager URL (actually, 404 then 500 after page refresh, each single time). I thought it was <SERVER_BASE_URL>/manager/. It turns out it was <SERVER_BASE_URL>/manager/html.
It’s worth mentioning it wouldn’t tell me I wasn’t using the right credentials either.
Simple, A ClassNotFoundException throws when some where a class that is used in the code is missing.
EG : If it is for servlet, then it means something servlet api that is regularly available to tomcat is now missing for some reason.
quite possibly the servlet-api.jar file in tomcat's lib folder (maybe other jar files in the tomcat lib folder) have become corrupted or removed.
Find it, you'll fix that.

Including external jar in Tomcat ClassPath

In Tomcat I want to use a jar inside a web application. The jar file will exist outside of the Tomcat directory.
To include the jar file in tomcat classpath, I modified the TomcatHome/conf/catalina.properties to include the absolute path of my jar file like,
shared.loader=D:\jaa\MyJarFile.jar
as per the suggestion given in link,
http://www.mulesoft.com/tomcat-classpath
But it throws the error,
java.lang.NoClassDefFoundError
I have also tried ,
shared.loader=D:\jaa\*.jar
shared.loader=file:\\D:\jaa\MyJarFile.jar
None of them seem to work :(
If I try placing the jar inside tomcat/lib it seem to work. But I am not allowed to do that.
Please help me out with this issue as I have implementation the next week..
I figured myself how to add the classpath for tomcat. Instead of editing catalina.properties, just create a "setenv.sh" in the Tomcat Bin directory with the classpath,
Example,
CLASSPATH=D:\jaa\MyJarFile.jar
I just checked the catalina.sh in Tomcat/bin and these classpath variable will be set while setting the bootstrap as the classpath.
I was using IntelliJ and I tried everything like:
Using CtrlAltShiftS (Project Settings) and adding a dependency of mysql-connector.jar. Didn't work. (The only thing that worked was that code completion inside IntelliJ was working fine.
Adding mysql-connector.jar to apache-home/lib/ folder. Didn't work.
Including mysql-connector.jar from Maven inside IntelliJ. Just didn't work.
The thing that worked for me:
Include the mysql-connector.jar file in the PROJECT/web/WEB-INF/lib folder.
No need to add it as a dependency anywhere. Just compile this and it will work fine.
I find myself copying extra JARs, which should be available for all contexts and should therefor go into the root loader, into the following directory:
C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib
But this only possible if you have access to this directory, which might not be the case for all ISPs. At least you can do it at home.
Bye

Categories