Why my Tomcat could not load - java

First of all, I want to say that I know that this question is already has been asked but their solutions really did not help me. My problem occurs when I add Tomcat9.0 into my server part in console. When I click to add server and when I then click finish to configure Tomcat I got error:
Could not load the Tomcat server configuration at \Servers2\Tomcat
v9.0 Server at localhost-config. The configuration may be corrupt or
incomplete. The processing instruction target matching "[xX][mM][lL]"
is not allowed.
I tried everything(to copy files from tomcat instalation directory to folder Server2 in my workspace, to remove then to add server)... but nothing helps me. My tomcat instalation is on Desktop and that path is set into server-Run time enviroment in eclipse.
Could someone maybe helps me to fix this problem?

Try this:
Reinstall your Tomcat 9 (use the default location to start and see if it works).
Uninstall all the tomcat servers from your servers tab in Eclipse.
Restart Eclipse.
Then go to File -> New -> Other, select Server, select Apache -> Tomcat v9.0 Server and hit Next.
Select tomcat installation directory.
Hit Finish.
After it shows up in your servers tab, double click on it and select Use Tomcat installation and save the changes.
Make sure your service in windows services set to manual and not started.
Now you can start it inside the Eclipse.

The error includes 2 parts:
Could not load the Tomcat server configuration at \Servers2\Tomcat
v9.0 Server at localhost-config
You should check the server config file.
The processing instruction target matching "[xX][mM][lL]" is not
allowed.
This error usually occurs when a XML declaration (eg: <?xml version="1.0" encoding="...">) is NOT at the beginning of the file.
Try searching the file for stray <?xml. Also, remove everything before the first <?xml, even blanks or byte order mark.

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 do I change the Tomcat default working directory?

In my web application, when I do new File(".").getAbsolutePath(), the path returned is <tomcat_home>/bin. I want to change it to <tomcat_home>/webapps/<app_name>.
The default directory for HTML ./path works fine and is the path I want. But the Java path ./Path is different in the same project.
I have tried to add a parameter like workDir="Path" in the <Host> area of the server.xml file on my Tomcat server, but it doesn't work.
How do I change it?
The general question of how to change the working directory of a java process has been asked before. The simple answer is that the java language and the java virtual machine don't provide a way to change the working directory of the JVM process. You won't be able to change the working directory after tomcat has started.
Tomcat's startup scripts (bin/startup.sh and so on) don't set a working directory. The tomcat process will normally inherit whatever the current directory was for the startup script. See this question. To make tomcat start in a different working directory, you'll have to figure out what is launching tomcat, and change that process to change to the desired directory before it runs startup.sh.

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.

Can't figure out cause for NoClassDefFoundError: aspose/pdf/Paragraph

I can't get any pages of my webapp to load (locally on Tomcat 7.0.2.6), due to this NoClassDefFound error. I'm at my wits end trying to figure out what the cause is, here is what I know:
My coworker has this project successfully running locally (on Tomcat) and on our development server (WebLogic).
I have done a fresh pulldown from svn so my code is exactly the same as his. I've verified that I have a shared library reference to Aspose (and that the required .jars are in there), and that weblogic.xml has an entry for it.
We saw this same error when initially deploying on WebLogic because the Aspose library was named incorrectly, but it ran fine locally on his Tomcat server.
I've tried cleaning and rebuilding the project to no effect.
As best as I can figure, it has to be either a Tomcat issue, or maybe an Eclipse setting.
Has anyone encountered a similar situation? Any ideas on what to try to resolve this?
First thing you need to do is determine if you are colliding with another class with the same name and package. The easiest way to do this is with the cygwin/linux console, save this shell script to a file say, findjar
find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;
put it in your path and navigate to the root of the server instance and run the script like this
findjar . yourclass
Note the period, dont forget it. this will return if you have multiple classes with the same name in your project.
once your sure the project is clean and there is only one copy of the class, i would try actually adding your shared libraries folder to the websphere server instances JVM arguments. to do that:
Go into the admin, click on servers
Open server types, click on websphere application servers
You should see your server listed there, click on it
On the right hand side, you will see a section “server infrastructure” and below that is a subsection “Java and process Management”
Open that section and click on “Process Definition”
On the process definition screen is another right hand column. Click on “Java Virtual Machine”
Yes, finally we are on the correct screen, there is an end in sight here, I promise
On the virtual machine page, there is a large text field labeled “Classpath” What you need to do is enter the full path to the shared libraries folder
its odd and makes no sense to have to do it, but i have had to do that in the past to allow my code to see the properties files in a shared resource.
It is possible that your colleague has java librarys installed within his Tomcat instance itself.
Take a look in the Tomcat directory for some lib folders (I cant remember the exact location and I think it changes based on the version) but something like ${CATALINE_HOME}/common/lib
Verify that he doesnt have differen JAR files in his tomcat installation as yours.
From this question: Does Tomcat load the same library file into memory twice if they are in two web apps?
They are apparently stored here:
Tomcat 6 $CATALINA_HOME/lib
Tomcat 5 $CATALINA_HOME/common/lib

Latest changes are not reflected in servlet (tomcat)

I am working on my project of quiet sometime now I am using tomcat and eclipse both working correctly till now..
I deployed the war on 22-1-2012 ( with some print messages) it was working correctly then next day I made some changes removed some messages and redeployed the file...In my webapps folder it is showing the latest time for 'last modified' of my war file.. what wrong i am doing tell me..
P.S any changes to JSP pages of same project are reflected but servlet class is unchanged
This is what log file shows
_SEVERE: A web application appears to have started a TimerThread named [MySQL Statement Cancellation Timer] via the java.util.Timer API but has failed to stop it. To prevent a memory leak, the timer (and hence the associated thread) has been forcibly cancelled. _
Well this is the summary of my problem i hope i can explain you now the problem
i again performed the following steps
Deleted my webapp directory from webapps
Tried to access servlet (it shows 'Resource not available')
Make some changes in print statement to debug
Redeployed WAR from eclipse
Again when access that servlet it is not the latest version it is showing same old messages.
Now tell me if there is solution....
Thanks in advance
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
The JSP files are not updating because they were precompiled, and even though they may pull information from files that have changed, each JSP file that may be affected needs to have a minor change made to it, like add a space and then remove a space, and then save it.
Then build your WAR, and then the updates should show. I went through this same problem tonight and none of the other answers helped. The key is, to check the file dates in the Tomcat directory of where you deployed the WAR. I noticed that even though I was deploying an entirely new cleaned WAR, and deleting all folders, there were still older cached files in there, probably because Eclipse keeps them to save compile time, thinking they don't have any changes.
Hope this helps
Go to Servers View in Eclipse:
Double click on your server. In my case, it’s Tomcat.
A Tomcat Web Module should pop up. Click on Modules tab at the very bottom (see Pic1)
Select your project. Click “Remove” button.
Pic 1:
Now you should see a star next to the Tomcat Tab. That means you need to save your changes. So do a Control+S.
Pic 2:
Right-click on your project in Project Explorer. Go to Maven -> Update Project…
Pic 3:
Now this is the important part, make sure you have “Force Update of Snapshots/Releases” checked. Having that part checked is critical. Then click Ok.
Pic 4:
Now look at your Server View. It should look like this, with a “Restart” warning telling you that it’s out of sync.
Pic 5:
Right-click on it and choose Restart
Pic 6:
Let the server restart. Now if you go back to the Server View, you should see that it’s synchronized. That’s what you want. Like this:
Pic 7:
Now you should be able to right-click on your project and choose “Run As” -> Run on Server and you should see your changes.
Pic 8:
If things still didn’t update, go back and look at your Server View and make sure it doesn’t say the restart thing like in Pic 5 above. If it does, please restart your server again like in Pic 6. Then click refresh on the browser.
Go to browser settings and clear the cache.
Check the log files for Tomcat, I bet there is a startup problem with your web app and it's not getting deployed.
The reality is that Tomcat cannot be running code it doesn't have a copy of. Especially if you have restarted it. It sounds like there is a separate "copy" of your web app that is actually in use. Either made inadvertently by you (hey lets face it, we've all done this) OR made by Tomcat in a location you weren't aware of.
Pick a unique file that exists within your web app. Maybe an icon name, or a configuration file name. Search the entire hard drive for it to locate exploded copies of the WAR file. This will help find it in a temp directory or working folder. Make sure to clean those up.
Also, make sure you are running the Tomcat that you think you are. Most developers with multiple Tomcat installations has also made the mistake of deploying to a different location. Look at the process list to see the arguments given to the JVM at launch time. Be sure to also check environment variable for things like CATALINA_HOME.
EDIT: Your update that JSP pages change, but classes do not make me think you have multiple JAR files on the class path that have the same file in it (one older version loaded first) OR you have changed a class name in the code base, but not updated references to it.
any changes to JSP pages of same project are reflected but servlet class is unchanged
It is not clear what you are saying.
If you are saying that the updated JSPs are in the expanded webapp directory, but the generated / compiled JSP classes have not changed (in the work directory), then try deleting the classes from the work directory. You may need to restart the web container too.
If you are saying that the non-JSP servlet classes have been updated (in the webapp) but you are not running them, then try restarting the web container.
If you are saying that the non-JSP servlet classes have not been updated in the webapp directory, then something went wrong in the webapp deployment. Shutdown the web container, delete the webapp directory (and the compiled JSPs for good measure) and restart the webapp.
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
So the problem is nothing to do with deployment. The problem is that you are not building the WAR file correctly in the first place.
I can't help with this because I don't use Eclipse to build my WAR files. (I use Maven so that the build process is scripted and reproducible ... and doesn't depend on me clicking the right buttons in the right order every time.)
is your tomcat server.xml pointing to the right Workspace?
to make sure, you go to tomcat installed directory -- find server.xml in the confi folder
for every war file, tomcat creates a similar named folder. Delete the folder, try to redeploy war again, hope it will reflect.
In web.xml file add one letter at the end and delete it and then by pressing enter save the file. After that run the program and it works with updated data.
go to catalina home\conf\context.xml
change <Context> to <Context reloadable="true">
Make sure you restart tomcat.
Boom.
You might have to still press F5 or Ctrl+F5 two or three times though.
TL;DR: Make sure your eclipse project is set to build automatically: Project > Build Automatically
I apologize for answering without having complete knowledge of what the WAR files are, but I assume the WAR files are the compiled .class files in the "build" folder.
I noticed that when I saved my Servlet "HelloWorld.java" in my case, that the compiled "HelloWorld.class" did not update at all. I could force the project to build by right clicking the java project and selecting "Build Project". After Building the project, the "HelloWorld.class" file was successfully updated, but the updated code still did not show on the server.
To get the results to show on the server, I had to click on my server (mine was called "Tomcat v9.0 Server at localhost [Started, Synchronized]") and then I clicked "Publish to Server". If you do not see your Servers, do: Window > Show View > Servers
I didn't even have to restart the server, after a few seconds (and refreshing google chrome), the website updated itself!
Of course manually building and publishing (and possibly restarting) the server is kind of too much for my lazy fingers, so I found how to fix it. You can just go to Project > Build Automatically. and then the website will update anytime you save a modified java file.
This solution worked for me because I was only missing the automatic building. but you could also have a problem where the server doesn't automatically publish.
I personally didn't have this problem so I'm just speculating, but there are some settings for publishing. In your "Servers" view, double click on your server name (in my case, double click on "Tomcat v9.0 Server at localhost [Started, Synchronized]"). A tab should open up showing your server settings. Expand the section titled "Publishing", and set your publishing settings as you desire. Right now mine is set to "Automatically publish when resources change".
Unfortunately I have no clue how to make the server automatically restart upon the saving of a modified .java file.

Categories