I'm having trouble getting a simple Java servlet to run under tomcat7 (fresh install from ubuntu repository).
It is a single .java file with #WebServlet("/TestServlet"). I put it into /var/lib/tomcat7/webapps/TestServlet/WEB-INF and would like Tomcat to recognize and automatically compile it (also, when I change the source file). How do I set this up in a simple way?
You have to compile your code using java compiler (or IDE). Then deploy *.class file(s) under servlet container (Tomcat in your case).
The class file must be under your WEB-INF/classes directory. If you class belongs to package like com.myservlet and its name is HellowServlet put it into file /var/lib/tomcat7/webapps/TestServlet/WEB-INF/com/myservlet/HelloServlet.class
EDIT:
if you indeed want make tomcat to compile your servlet, write JSP. This is a key feature of JSP: it can be deployed as a source code and is compiled automatically to servlet by container.
Use Eclipse IDE and click "Add Server" to add TomCat server. It will work directly
Related
I am trying to use opencv 2.4.9. in a Java Servlet with NetBeans, i have two files - the first one is a Servlet java file Login.java which is called by index.html , and the second one is CamCap.java a java file with all the opencv imports but this file is in the same package, am calling a function of second java file from the first one. The two files run fine separately as java project but when I try to run the complete servlet project it throws this Error - (java.lang.NoClassDefFoundError: org/opencv/core/Core)
How to resolve this!!?
You need to make your OpenCV jar available to both the IDE as well as the application server. I believe you've already made it available to your IDE by adding it to your web project's classpath.
Now to satisfy the dependency when running on the application server too, just copy the jar to your web project's /WEB-INF/lib directory, build your war and deploy it again.
I suggest you to always copy your dependency to /WEB-INF/lib first, and then adding it to your project's classpath. This takes care of such errors and also makes sure that both the IDE and the application server are using the same version of the jar.
I've installed Eclipse with web development and during download have installed Tomcat7 to dir E:\Eclipse\tomcat7.
When in Eclipse and trying to test the program I'm getting a realPath of
C:/Users/user/Documents/eclipseJEEWorkspace/javaWebPages/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.example.web/WEB-INF/classes/
as my real path and not what I expect which is E:\Eclipse\tomcat7\webapps\org.example.web/WEB-INF/classes/
1) how do I get the real path of the servlet rather than the temporary path...
or am I missing something with how Eclipse uses the installed server? If this is the way then do I have to continuously create the WAR and fiddle around recreating/deleting all the time?
The reason for this is I'm also trying to get a JAVA Servlet getting access to a file in a path higher than webapps. I'm new to servlets....
My development includes third party software that all reference an individual file our.properties so changing the structure is unfortunately not a option.
My directory structure is:
/tomcat
/mycompany
/properties
our.properties //the file we want to access
/*otherfiles
/html
/*not used in this context but to show usage
/javascript
/*not used in this context but to show usage
/webapps
/org.example01.web
/META-INF
/WEB-INF
/org.example02.web
/META-INF
/WEB-INF
/org.example03.web
/META-INF
/WEB-INF
How do I tell my Servlet to access the our.properties file?
I've tried getPath, getResource but without getting the first bit to work, I doubt I'll be getting anywhere fast.
Thanks
When you run Tomcat under Eclipse, via the Tomcat plugin, the webapps path is changed. Eclipse uses .metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ folder to deploy the project. That's not a temporary path, it's the actual path since your web application is deployed there.
If you run tomcat from command line, or as a service and deploy your web application, you'll see that the path of the servlet will be as you expected.
In order the change the default path to deploy for Eclipse, double click to your Tomcat under Servers view and modify Server locations section.
when we directly upload JSP page into tomcat where application deployed directory then why we don't need to restart Tomcat? how tomcat know that it has new JSP page?
when user hit the url /myapp/mynewjsp.jsp He/She always get new jsp deployed page.
Tomcat has an auto deploy feature. When you update JSP files it detects you have done so, compiles it, and replaces the old compiled JSP page with the new one that it compiles into a java class.
http://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html
If you don't want that to happen, you can turn off the auto deploy feature for your web application. It is described in the link how you do that.
Hey you can use jetty plugin for auto deploying tomcat folder . You don't need to paste your file on webapps folder. If you using maven project structure then add jetty plugin on pom.xml file . There is some command to run like mvn jetty:run etc... May these solution get you out from these problem
I am trying to deploy a WAR file on weblogic server.
This is a simple java application.
I am new to this and experimenting.
JRE: 1.5.0_41, OS: redhat 5.8, Weblogic: WebLogic Server 10.0 MP2
The contents just include a jsp file and a java file (jsp inside jsp folder and java class inside WEB-INF\classes folder and correct package structure). I am using this java util file inside the jsp for some common utility methods.
However, when I deploy the WAR, it gives me NoClassDefinitionFoundError for this java utility class.
I have searched the threads and found that this exception points to some other inherent issue in the deployment. It also mentioned class path conflicts etc. I can understand this issue when it comes to using a class from an external JAR file, but could not understand how it fails to locate a file in the same context as that of the jsp.
How come the import statements in the jsp worked and the jsp got compiled and rendered and failed only when the part of accessing this object came into picture? (runtime problem maybe?)
Please educate me on this. My debugging efforts are still on. Thanks a lot, folks!!
[P.S.: Could it be because i compiled and built my source using eclipse setting 1.7 compliance and used it on a lesser JRE?]
For a war file classes is normally packaged inside WEB-INF/classes, not classes.
I'm using Eclipse Java EE IDE and launch Tomcat from the Server's tab on Eclipse.
Where does Eclipse store generated servlet .java files for JSP files? I've checked the Tomcat installation directory, but nothing there.
Thanks.
Doubleclick the server entry in Servers view and check the path represented by Server path. Explore in there from inside the workspace directory. The generated classes are there.
If you choose the 2nd option Use Tomcat installation, then it will be available Tomcat's /work folder, there where you expected it to be.
go to your application work space directory(not eclipse installation directory) in windows explorer(not in eclipse IDE explorer).
in my laptop it is d:/applicationdata/j2ee
then follow the path as:
work space directory(in my case j2ee)/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/catalina/localhost
here u will find your application
Eclipse doesn't generate servlet files for JSP files. Validation happens directly on JSP syntax. When a JSP is deployed to an app server like Tomcat, the server may choose to generate servlet files to disk, but that is not required. The generation and compilation can happen in memory or the app server may even compile JSP files directly to bytecode.
I don't know specifically about Tomcat, but if it does generate servlet files to disk, the temporary directory containing these files will be somewhere under your Tomcat install.
/home/waheguru/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/jspnotes/org/apache/jsp
localhost or your website name,
project name is jspnotes, whatever your project.
This path is shown in Linux Mint.
Check META-INF\context.xml file from your work space. There will be path metioned like below
workDir="C:\apache-tomcat-7.0.39\work"
In above path you will find the package structure of your project and in it there will be both *_jsp.java and *_jsp.class