Installing Solr onto a hosted tomcat server - java

I have installed and configured tomcat+solr on my personal linux machine and windows as well. I was able to get them working fine. I'm very new to Java and how the file structure works. (i.e. knowing where to put war files and what WEB-INF is) So now that I am ready to install solr and configure it on my clients shared hosting plan, the directions are different from what I did before. I dont want to mess this up and apparently the webserver reboots daily and I dont think I can do it manually which means I have one shot at this every day.
Here is the directions for installing a tomcat servlet on his hosting provider:
http://www.apluskb.com/scripts/Where_do_I_put_my_answer1186.html
As you can see I need to install solr under the html/WEB-INF directory, but read what it says.. its very confusing:
"All Servlets should be uploaded in the /html/WEB-INF/classes directory. Any unpacked custom classes and resources should be uploaded in the /html/WEB-INF/classes directory, while classes and resources packed in Jar files should be uploaded to /html/WEB-INF/lib."
uhh... so which is it? /classes? or /lib? I dont think they explain that very well and I'm a little confused by this statement. Also what exactly do I install? With a normal solr install, solr is put somewhere else, the war file is copied into tomcat and the rest of solr is referenced using some kind of XML configuration file.
Also, since I'm a little new to Java and servlets, can someone explain the tomcat file structure to me (in great detail will definitely get you a +1 from me) and where things should go and why?
Thanks in advance!

Web application structure is defined by J2EE spec, it's not limited (or specific) to Tomcat per se. Here is a detailed tutorial covering its layout. Briefly, however, it's as follows:
There a base (root, home, whatever you want to call it) folder which serves as root of web application, everything else goes under it.
All public stuff (html, images, CSS, javascript, JSP, what have you) goes under that folder (directly or via subfolders).
There's one special folder, also located directly under root, called WEB-INF. It contains non-public stuff, like application descriptor (web.xml), classes (which go into WEB-INF/classes folder), libraries (WEB-INF/lib) and possibly configuration files.
Application can be deployed either using expanded structure above or as WAR (web archive) which is basically an archive containing everything above starting at root folder level (but not including root).
The distinction between classes and lib folders is simple: all packaged libraries (JAR files) need to go into lib; all unpackaged classes (and resource files that need to be in classpath) have to go into classes preserving their directory structure (e.g. com.mypackage.Blah class should go into classes/com/mypackage/)
In your case, it looks like you can only have one web application deployed and it has to be deployed to /html folder. If you're deploying a war file, you need to extract it to that directory (e.g. from within that /html folder run jar xvf solr.war or whatever it's called).

Related

tomcat and extracted files

I am using ubuntu with packaged tomcate7 .
I used .war file to upload the website.
the web is working fine.
This is not my website but its there:
:/var/lib/tomcat7/webapps/ROOT$ ls
index.html META-INF
I find my site files (those in .war) at
/var/cache/tomcat7/Catalina/localhost/_/org/apache/jsp/
/var/cache/tomcat7/Catalina/localhost/_/WEB-INF/classes/
I do not find any of my .css or .js files with a system wide search
like find / -name '*.css' -ls
where are they?!
Is there an easy way to just give tomcat the .class files or delete the .jsp .java files
(for example if I don't want to give the real source but only .class)
JSP precompilation. During build-time some tool (jspc) is difficult.
any easy walk through?
The WAR file is likely "somewhere" on the server, but tomcat may have been configured to not "explode" the WAR files on deploy, and simply serve the resources directly out of the WAR. That may be why your web site "works" but you can not find the actual .css files, the .css files are not there on the file system but still contained in the WAR.
As for #2, pre-compiling JSPs, for some reason this is still a "jump through flaming hoops" process that is only semi-automated.
Pre-compiling JSPs before deployment entails the converting of the JSP file to a Java source file, compiling that file, and then mapping that resulting class as a servlet in the final web app, and then finally removing the JSP file from the web app.
There is a Tomcat Page that discusses the process, but only offers part of the solution (from an automation stand point).
Of course, one reason pre-compiling is not popular is that pre-compiled JSPs are not portable across containers, nor necessarily versions of the same container. So, that's a notable issue.

Tomcat6 refuses to recognize the classes in WEB-INF/classes folder

Instead of using a certain jar in my WEB-INF/lib folder, I want to use its source code (same directory structure and everything) in my WEB-INF/classes folder, so that I may be able to modify its classes more story.
Yet (re)starting my tomcat after deleting the original jar and uploading the corresponding directory into WEB-INF/classes gives me the following error:
SEVERE: Error configuring application listener of class no.something.something1.http.LifecycleListener
java.lang.ClassNotFoundException: no.something.something1.http.LifecycleListener
I am certain that the directory path is the same as the one inside the jar. Also, I have previously tried using classes in my WEB-INF folder for this web application, and tomcat has also been unable to load them, for some reason.
Does anyone know how I go about troubleshooting this error?
Tomcat can only load .class files, it doesn't know what to do with raw source code files. Tomcat doesn't do hot loading of .class files like that anyway. You would have to restart the application or server after you recompiled them either way, packaging them as a .war isn't that much of a burden either way once you automate it.
If you take the time to automate the build and deployment of a proper .war you can just rebuild the .war and it will automagically undeploy and redeploy the application itself, which is many times faster than restarting the entire server.
You can't do what you are trying to do the way you are trying to do it. Tools like JRebel address these issues, but I don't find them as useful as their marketing makes them sound.
You could use embedded tomcat (or embedded jetty) to map directory structure of the application as you like. It probably will require some tinkering if you need some JNDI resources within your application but still worth the trouble.
Here's an example

Web Services in Unix. What should be the directory structure

I earlier got to create a simple RESTful webservice on my localhost using Eclipse IDE, Tomcat, and JAX-RS libraries.
I am now trying to move the same on to a different unix server which has Tomcat installed. I am not knowing how to get started as in what is equivalent to creating a "Dynamic Web Project" that I do in Eclipse. Do I need to just create a directory myself with all the sub-directories as created by Eclipse? Should this directory be placed in webapps folder in Tomcat container. Should META-INF and WEB-INF also be created by myself?
Where should I put my Java classes?
Can somebody please clarify this or direct me to any documentation about the same.
You need to package your application in a WAR file.
The Sun Java EE 6 Tutorial has a chapter deciated to packaging.
It's pretty easy to export a web application as a war in Eclipse.
Dynamic Web Project (right click) => Export => Web =>war file =>war export dialog
Creation of web application archive - WAR is the solution for your problem,
but take care about all libraries that you need there.
You can easily extract (unzip) WAR file content
and check your project structure and libraries needed
and they will be in WAR's WEB-INF/lib.
Make sure that both Tomcats are set same way,
make sure your code is all OS friendly (users, file paths, permissions)
Always write some test simple code that will run up on app start,
and check all dependencies and libs, system clock, outside world network communication, so you can trace it in web app console or logger easily.
regards

Can you pick up the source from a tomcat-deployed application?

Can you extract source from tomcat application? The webapp is not deployed as a .war file, it's a bunch of directories, xmls, configurations, .class files, .jars and stuff.
Your comments to Paul Tomblin indicate you already have access to the server. As he said, if you didn't upload the source to start with (which is normal), you can't get it off the server. However, there are a couple of things to note:
Unless you compiled your JSPs prior to uploading, they will contain their own source code and you can download them for use in another project or whatever it is you're trying to do
If you're desperate, you can decompile the .class files using something like JD (http://java.decompiler.free.fr). The decompiled code will not include comments and is not always spot-on, but it will get you much further than you are now.
You don't have to put the source code on your web server, just the compiled class files. So no, if the source isn't on the server, nobody can "pick it up". In a normal configuration, I don't think it's possible even to download the individual class files, but it might be possible if you put your Tomcat webapps directory somewhere where your normal web server (Apache) can find them.

Understanding imported WAR in Eclipse and its folder structure

I have just imported a WAR file from an external site, which is basically a servlet into Eclipse IDE (the project runs on Apache-Tomcat).
When I import it it has a folder called Web App Libraries. So here are a few of my newbie questions:
I am unsure about what the exact purpose is of this folder is? What does it do, why would you choose to have it in your project?
I see that it has a folder called Improted Classes and foobar.class files inside it - why?
(These seemed to be mirrored in Web Content folder - although here you can modify the code as they are foobar.java.)
There are references to foobar.jar files too - these are also mirrored in WEB-INF/lib folder too - why?
I know these are basic type questions but I'm just getting to grips with Java and website dev, so apologies if they sound a bit dumb! - BTW if anyone knows any good online resource to understand more about project file structures like this, then let me know. I just need to get to grips with this stuff asap - as the project deadline is fairly soon.
Cheers.
Here's a screenshot just to help you visualise:
I assume this is a screenshot from the 'Project Explorer' view. It does not display exact folders and files structure, is adds a few candy constructed from project's metadata.
To see real structure of your project, try switching to the 'Navigator' view.
During a WAR file import, Eclipse basically does two things:
Creates a new web project and copies WAR's content to 'WebContent' subfolder of the new project.
Based on the WAR, it constructs project's metadata (.project and .classpath files).
The 'Web App Libraries' section displays list of jar files that the WAR contained (in WEB-INF/lib
'Imported classes' (which I also see for a first time) seem to contain classes found in the imported WAR (WEB-INF/classes), for which Eclipse was not able to find any corresponding source files. To fix this, create a new Java source folder in the project and move the classes you now have in 'firstResource' folder to it.
Web App Libraries isn't a real directory, but rather a listing of what Eclipse thinks are this project's libraries.
Generally, this consists of all the jar files in WebContent/WEB-INF/lib/
Sometimes, Eclipse no longer lists them in their real directory in Eclipse's Package Explorer... but they're still there if you look with another program.
In Eclipse, if you are using the Java Web Development view, you'll have configured:
A Tomcat Server runtime that provides the servlet libraries
A Java Runtime
Other required libraries
The Web App Libraries that are in the project duplicate the first setting, so that you don't need a local Tomcat installed on the development box.
The rest sounds messy to me.
You have your src / JavaSource folder with the raw Java files in it. They shouldn't be in Web Content - that's for your HTML, images, JSPs, etc.
So a typical project setup:
Project Name/
JavaSource/ or src/ // holds all the Java Source Files, Servlets, Struts Actions
WebContent/ // Nice root folder to hold web content files
content files and folders
WEB-INF/ // Web App Config folder
lib/ // Libraries (but not tomcat ones)
web.xml
classes/ // Where your compiled Java goes, and configs (log4j.properties)
Some people put the JSP inside WEB-INF too, as it isn't required to be accessible in the JSP file state, only in the compiled state that Tomcat does itself.
Its simple, eclipse provides multiple view to your project structure. The view you are looking at is definitely the Package Explorer view. In that view, everything that has a special icon in front is a helper item which is there to help you out by simplifying access to certain stuff like external libraries (which are provided by software on your computer or eclipse itself or other project).
In eclipse, go to menu->window->show view->navigator
The Navigator view will tell you the real folder structure of your project.

Categories

Resources