tomcat server giving issues to run the application - netbeans

I am trying to run the application. just i installed the tomcat and netBeans.
It is giving following error. if i try to give build alone,,, build is successful. but i am unable to deploy in server ...
Created dir: D:\Test\build\generated\src
Created dir: D:\Test\build\generated\classes
Compiling 1 source file to D:\Test\build\generated\classes
Undeploying ...
undeploy?path=/excelRD
OK - Undeployed application at context path /excelRD
In-place deployment at D:\Test\build\web
D:\Test\build\web\META-INF\context.xml (The system cannot find the file specified)
D:\Test\nbproject\build-impl.xml:686: The module has not been deployed.
Please do needful

The error message seems clear you need a file context.xml in your project.
In a regular apache project created with Netbeans, you have in the directory Web Pages an other directory names META-INF and in this directory the file context.xml.
Try to respect this architecture. The minimal context.xml contant is :
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/excelRD"/>

He may also be seeing an issues I've seen on NetBeans for years. You have a perfectly valid context.xml file that can't be found by NetBeans during deployment. If you open the file, touch it in anyway (type in a character, delete that character, then save), the problem goes away. I've had this happen so many times that I've gotten in the habit of always touching the context.xml file before I deploy.

Related

org.springframework.aop.framework.AopConfigException Error in WebLogic 12c

I am in the process of upgrading WebLogic Server 11g (10.3.6.0) to 12c (12.2.1.3.0).
I installed the war file without a problem onto the 12c server. Then, I tried to start the module. I was getting weblogic.application.ModuleException: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.springframework.aop.framework.AopConfigException error due to missing a particular class file. It seems like the class file belongs to "spring-aop-2.5.2.jar."
When I deployed the same war file onto the WebLogic Server 11g environment, I did not observe any problem. I ensured that "spring-aop-2.5.2.jar" exists in the war file. I am using the version 2.5.2 for the SpringFramework. I suspect it may also be a problem.
Based on my research, some people suggested to append <package-name>net.sf.cglib.*</package-name> into the to <prefer-application-packages> in your weblogic-application.xml. I do not have the weblogic-application.xml in my project or in the war file. I only see the file on the server. Although I appended the tag into weblogic-application.xml, I am still geting the same error.
Should I configure anything else based on my description? Any idea?
Having the same issue, I got it to work by putting both spring and cglib jars in the ear APP-INF/lib folder and using the following META-INF/weblogic-application.xml
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.3/weblogic-application.xsd">
<prefer-application-packages>
<package-name>net.sf.cglib.*</package-name>
<package-name>org.springframework.*</package-name>
</prefer-application-packages>
</weblogic-application>
From my understanding, it's important that:
Both cglib and spring jars are in the same classpath folder
Both are present in "prefer-application-packages"
Using "prefer-application-packages" in weblogic.xml inside my .war file did not seem to work for some reason.
You should modify your weblogic.xml file to use the proper libraries with prefer-application-packages. However, do not forget to include this.
<prefer-web-inf-classes>false</prefer-web-inf-classes>
Oracle states here
Note that in order to use prefer-application-packages or prefer-application-resources, prefer-web-inf-classes must be set to false.

Make per-context JNDI variable available to Tomcat in Eclipse

I'm using Tomcat 8.5.6 inside Eclipse 4.6.1. I have my web-app project/context foo, which has a JAX-RS (using RESTEasy 3.1.0.CR3) endpoint of bar, so I can fire up Tomcat inside Eclipse and access:
http://localhost:8080/foo/bar
I have a variable named foobar which I want to access inside my JAX-RS implementation using JNDI:
final String foobar = (String) new InitialContext().lookup("java:comp/env/foobar");
I plan on deploying the produced WAR in production using Tomcat autodeploy. I want to configure the foobar variable for Tomcat externally to the WAR. How can I do that so that I can test it in Eclipse?
After a lot of reading, I found what I thought to be the $CATALINA_HOME of Eclipse: …\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\. So I created a context file for foo at …\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\foo.xml to correspond to my project/context, and put the following inside it:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Environment name="foobar" type="java.lang.String" value="123"/>
</Context>
Yes, I know that Eclipse erases this directory whenever I rebuild. But after building, I saved to file at least want to see if it works. It doesn't. I get an error:
javax.naming.NameNotFoundException: Name [foobar] is not bound in this Context. Unable to find [foobar].
I want to at least get it working so I can know how to do this in production, and worry later about the context file deletion thing in Eclipse. So what did I do wrong? Why can't Tomcat in Eclipse find this JNDI variable?
Note: I am not using a web.xml file and have no desire to do so; besides, this variable should be defined outside the WAR in the production deployment.
Update: The good news is that (on Windows 10 Professional Anniversary Edition 64-bit) using the same Tomcat but in standalone mode, I put the same foobar.xml file inside the standalone Tomcat's conf\Catalina\localhost\foo.xml, and my JAX-RS application picked it up just fine. So how can I define a JNDI variable in Tomcat inside Eclipse for testing?
It appears that in order to get Eclipse+Tomcat to recognize the per-module context files, you have to go into the server configuration (double-click on the server) and turn on the Publish module contexts to separate XML files. This way Tomcat will use the specific context XML file you created. Otherwise it apparently puts them in conf/server.xml and ignores the context-specific file you created.
There is still the problem that Eclipse regenerates this file each time you do a rebuild, destroying whatever JNDI variables you placed there. I'm trying to get the workaround in https://stackoverflow.com/a/22380248/421049 to work, but not yet succeeding. Anyone have any better ideas?
At least I'm able to reproduce a production environment now --- albeit temporarily, until the next rebuild.
Your link to Markus' answer on https://stackoverflow.com/a/22380248/1794485 allowed me to get this working, or at least as described in his workaround. But the remaining problem to solve was ordering.
As he said, you can workaround this by having a local copy of the META-INF/context.xml somewhere else, and adding this folder to the Deployment Assembly in the project properties of the Eclipse project.
This didn't pick up for me initially though. It looks like that while the Deployment Assembly in the properties shows as sorted by name, in fact it has an order like any other path. When I then removed the src/main/webapp entry (so the one containing the normal META-INF/context.xml) and added it back in, this effectively moved it down the pecking order. The next Tomcat deploy and startup in Eclipse finally put my preferred copy of META-INF/context.xml in .metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myapp\META-INF
If in doubt about the true sequence of that Deployment Assembly path, have a look under your Eclipse project on the file system - at .settings\org.eclipse.wst.common.component.

How can I deploy a war-file to a subdirectory of my JBoss server?

this has got to be a stupid question but my Google-fu fails me. I have a JBoss server (actually EAP 6.1) and a packaged web application, myapp.war.
By copying the file to .../standalone/deployments/ it gets deployed to <server>/myapp. Renaming the file to somename.war, it becomes <server>/somename, and ROOT.war gets deployed directly on <server.
So far so good.
But how do I get the application to appear under e.g. <server>/antares/myapp?
I tried simply making a subdirectory under deployments/ and placing my war file there, but that still gets deployed simply as <server>/myapp. I also read somewhere on a Tomcat forum to call my file antares#myapp.war, but that resulted in an error when the deployment scanner tried to run it.
Searching around on the web, I so far mostly found (a) descriptions of the folder and subfolder structure of a web project or (b) things about projects and sub-projects and how to handle dependencies.
I don't need all of that, I just want my perfectly fine war file to show up with a slightly deeper path. Preferably without having to touch many configuration files.
What am I missing?
You need to wrap your .war in to a .ear and add the following information in to the application.xml in order to achieve what you want.
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>Your App name</display-name>
<module>
<ejb>a-ejb-module-if-you-have-one.jar</ejb>
</module>
<module>
<web>
<web-uri>myapp.war</web-uri>
<context-root>antares/myapp</context-root>
</web>
</module>
</application>
Please take a look at the documentation here: Setting the context root of a web application

Problems deploying WAR file from Netbeans to Tomcat

I'm trying to configure build.xml files for build forge, but it seems like I am having trouble with the libraries required for the java servlet pages. I am actually trying to use OWASP's AntiSamy library but I keep getting a Policy Exception followed by a file not found
org.owasp.validator.html.PolicyException: java.io.FileNotFoundException: C:\Program%20Files \Apache%20Software%20Foundation\apache-tomcat-6.0.29\webapps\XSSDemo\WEB-INF\classes\...\antisamy.xml (The system cannot find the path specified)
The antisamy.xml file is definitely in this location, however.
So I tried using Netbeans to clean and build a WAR file that I would have expected to work, since the web app works fine when I run it through Netbeans. However, I get the same problem. Is there possible some reference that Netbeans is creating when I run the app through the ide that is not occurring in the WAR deployment? Could the URL Encoding in the antisamy.xml location be causing problems?
Thanks for the help.
Edit: I compressed the long class path into the three dots here. The actual response has the actual class path. I am not getting any kind of security errors.
The problem I had was not actually with the deployment--it was the file reference itself in my java servlet. The encoding in the path '%20' in the Program Files folder caused a FileNotFoundException. The reason this did not occur in netbeans is because the deployed files are in a c:\users... folder and there are no spaces to be encoded. The also explained why the application ran well on other computers with their tomcat folders directly on the root directory. This is the actual solution to my problem. Thanks for all your help.

Deployment of Web Application to a Running Tomcat

I would like to collect some best-practices on deployment of a web-application to a running Tomcat. Not long ago I had to describe the deployment process of our web-application and the process appeared rather confusing.
Say, we have an application in a WAR file (foo.war) correctly configured and not requiring additional configuration. In this case, the deployment process is rather easy:
Copy the foo.war file to the $CATALINA_HOME/webapps directory. If the application starts correctly, the application will automatically deploy to $CATALINA_HOME/webapps/foo directory.
To undeploy the application:
Remove the foo.war file from the $CATALINA_HOME/webapps. If the application unloads correctly, it will be unloaded and the $CATALINA_HOME/webapps/foo will be removed.
Now I want to override some context parameters in my running application. Having read the docs, all I need to do:
Create a context.xml file called foo.xml
Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
Unfortunately, that did not work: the application would not restart. Empirically, we found out that the only working solution is when the war file is deployed to a location outside the $CATALINA_HOME/webapps.
Besides, the default values of the configurable context parameters in the WAR file should be specified in the web.xml, since context.xml in the WAR file is not read when there is a context.xml outside.
Here is an easy example of the foo.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/path-to-deployment-directory/foo.war">
<Parameter name="myparam" value="newvalue" override="false"/>
</Context>
Be sure to specify override=false for the parameter if you want the 'newvalue' to override the value specified in the WAR's web.xml. This was not obvious for us.
Thus, to deploy an aplication to a running Tomcat:
Create a context.xml file called foo.xml
Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
Copy the foo.war to the location specified in the docBase of the foo.xml; the application will deploy automatically.
To apply new context parameters:
Add the parameter values to the foo.xml and save the file; the application will re-deploy automatically.
To undeploy the application:
Remove the foo.xml from the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory
Note that removing the foo.war will also work, but will remove the foo.xml as well.
By now, I have the following questions:
Is it a best-practice at all to deploy a web-application without stopping the tomcat? I heard an opinion that deployment to a running tomcat is never needed since people run each application in a separate tomcat.
Is it a good idea to copy WAR files to $CATALINA_HOME/webapps or they should better be kept in a separate location?
How can I configure an application deployed to $CATALINA_HOME/webapps
Why there is no INFO line in the catalina.out for deployment of an application and there is one for undeployment? Is it configurable?
On question (1), Tomcat works great for deploying servlets into a running server. There may be concerns w.r.t. security or possibly D.O.S. or provisioning reasons why you would have separate server instances.
You have the flexibility to do either way, but it is often more convenient to deploy to an already running server. This is a BUILT-IN feature in the servlet architecture. :)
For (2), again it is at your discretion where you you want to put WARs. It sounds like you already have it configured a non-standard (non-default I should say) way. Check your server.xml file for the settings in your server instance(s). Check for attributes like unpackWARs and autoDeploy.
For (3) and (4), plus your (1,2) questions, it might be a good idea to consult the Tomcat docs for your version of Tomcat on its deployment model. You should be able to use the same docs to figure out how your server has been configured.
See Tomcat Web Application Deployment in the Tomcat manual, adjusting for your version of Tomcat.
One solution would be to use the manager application. If you decide that is safe to use it, then you can easily deploy, start, stop and undeploy applications:
http://localhost:8080/manager/deploy?path=[context_path]
http://localhost:8080/manager/start?path=[context_path]
http://localhost:8080/manager/stop?path=[context_path]
http://localhost:8080/manager/undeploy?path=[context_path]
There are ant tasks that can help you with these.
I am guessing, but do not know for sure, that stopping and starting an application will make it reread the context.xml.
Regarding your second question, I believe it is better for maintenance reasons to keep the war files in the webapps directory.