Web application not found src/main/webapp - java

I am currently using intellij for my java code. When i try to run the Project, it throws the below error.
2016-06-21 09:19:46.691::INFO: jetty-6.1.14
2016-06-21 09:19:46.843::WARN: Web application not found src/main/webapp
2016-06-21 09:19:46.843::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext#359d136a{/admin,src/main/webapp}
java.io.FileNotFoundException: src/main/webapp

In RUN >> Edit Configurations, Working directory $MODULE_WORKING_DIR$
Example

Did you add the folder "webapp" to your classpath/resources-folder?
I guess you have something like:
applicationContext.setBaseResource(Resource.newClassPathResource("webapp", true, true));
In your WebAppContext-configuration - so, just add a folder named "webapp" under "src/main/resources/." and I guess it should be working as intended.

Related

Is ApplicationContext file necessary if I want to run the unit test?

everyone,
I'm new on web development. Recently, I start a tutorial to build Registration and Login with Spring Boot and MySQL Database. When I run the unit test, there are errors showing up. I cannot find ApplicationContext file in the tutorial, and also try serval methods on stack overflow e.g. change plug setting in pom.xml but isn't working.
Can anyone answer this problem?
Errors on IDE
The application context is not a file – it's a term Spring uses to describe the entire state of your application. So the error means that Spring is not able to start your application because of missing database configuration.
Looks like you are using maven (src/main/java). In this case put the applicationContext.xml file in the src/main/resources directory. It will be copied in the classpath directory and you should be able to access it with
#ContextConfiguration("/applicationContext.xml")
A plain path, for example, "context.xml", will be treated as a classpath resource from the same package in which the test class is defined. A path starting with a slash is treated as a fully qualified classpath location, for example "/org/example/config.xml".
So, it's important that you add the slash when referencing the file in the root directory of the classpath.

Getting error running struts2 helloworld program

I m new in Struts2. Creating a hello world program using struts. When I run it got first screen where i put my input but when click on submit button giving following error.
Source of this helloworld example: http://www.tutorialspoint.com/struts_2/index.htm
HTTP Status 404 - /HelloWorldStruts2/hello
type Status report
message /HelloWorldStruts2/hello
description The requested resource (/HelloWorldStruts2/hello) is not available.
Apache Tomcat/6.0.29
Suggest what is the issue?
Got the solution.
In index.jsp there was <form> tag. When I changed it to <s:form> its working fine.
Or change from
<form action="hello">
to
<form action="hello.action">
This is what worked for me, specific to the question. Tomcat 8 was used:
Make sure you have created the classes folder under WebContent\WEB-INF.
In that create the logging.properties file and add the following content to it. (It doesn't matter if the file jumps on its own to Java Resources > Libraries) :-
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \ java.util.logging.ConsoleHandler
Then in the location of Tomcat's webapps folder delete your HelloWorldStruts2.war file.
Now follow the site's instructions to Export your project to a new HelloWorldStruts2.war file (remember to overwrite the existing .war file with the same name if it's there).
Again, deploy this file by copying it to your Tomcat directory's webapps folder.
In the browser, go to http://localhost:8080/HelloWorldStruts2/index.jsp again, though I'm not sure it will work for sure this time.
But this time, watch the Tomcat server application's verbose output. You will get some kind of exception like this (leave out Warnings for now):
30-Mar-2014 17:39:29.273 SEVERE [localhost-startStop-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)
at org.apache.struts2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:102)
...
Seeing this, what I did immediately was copy the commons-lang3-x.y.z.jar to the WebContent\WEB-INF\lib folder, and then exported and deployed the project again.
This time, again the page wasn't showing, so I watched the logs and found out that Tomcat did not explicitly clear the contents of the webapps\HelloWorldStruts2 folder.
After deleting both HelloWorldStruts2 and HelloWorldStruts2.war and refreshing the index.jsp page in the browser, my project did work fine!

build-impl.xml:1025: The module has not been deployed. (Wicket)

I have been working on a Java web application using wicket framework on Netbeans 7.2 and out of a sudden I encountered this problem. I tried cleaning the build-impl.xml then restarting the IDE and I should say I have fairly low knowledge on this. Can someone please tell me why it is giving an error and how I can fix that?
The lines 1024, 1025 and 1026 are :
<target if="netbeans.home" name="-run-deploy-nb">
<nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
</target>
The error message says :
nbproject/build-impl.xml:1025: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 4 seconds)
I came up with a solution by myself, I cloned the project and changed the project's directory name back to original, that worked fine for me. But it seems to have a better and proper solution, though.
/* START BY RESTARTING YOUR GLASSFISH SERVER */
1-add DBMS(ex:oracle,MySQL,MsSQL..) jdbc connector jar to domain
"glassfish directory/domain/{yourDomain}/lib"
2-add connection pool in glassfish server "JDBC-->ConnectionPool"
3-add your JNDI "JDBC-->jdbc ressource"
4-Test connection
5-add additional properties
IF YOU HAVE NO PASSWORD ON YOUR DATABASE ACCOUNT YOU CAN EASILY
6- glassfish/config/domain.xml change password value to "" in your jdbc-connection-pool
may its so late but the response useful for others so : Sometimes, when you don't specify a server or servlet container at the creation of the project, NetBeans fails to create a context.xml file.
In your project under Web Pages, create a folder called META-INF.
Do this by right mouse button clicking on Web pages, and select:
New->Other->Other->File Folder
Name the folder META-INF. Case is important, even on Windows.
Create a file called context.xml in the META-INF folder.
Do this by right mouse button clicking on the new META-INF folder, and select:
New->Other->XML->XML Document
Name it context (NetBeans adds the .xml) Select Well-formed Document Press Finish
Edit the new document (context.xml), and add the following:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/app-name"/>
Replace app-name with the name of your application.
Now your in-place deployment should work. If not, make sure that the file can be read by everyone.
The context.xml file is specific to Tomcat. For more information about that file, see the Tomcat documentation at tomcat.apache.org.

package com.x.y.z does not exist

I'm trying to run old servlet under resin. I have deployed it as a war file. After starting resin there is a dir ic. It contains Webcontent dir with WEB-INF/lib/ic.jar (fatjar), jsp etc. While extracting this ic.jar I see there package com/x/y/z but while trying to access servlet page I'm getting an error: package com.x.y.z does not exist.
Can anyone give me any clue?
The jar needs to be in WEB-INF/lib, not in WEB-INF.
When extracting the JAR file, you should see
com/x/y/z/ClassName.class
not
com.x.y.z/ClassName.class
Assuming that what you wrote wasn't a summary of what you saw (or a typo).

Where should I put the log4j.properties file?

I wrote a web service project using netbeans 6.7.1 with glassfish v2.1, put log4j.properties to the root dir of project and use:
static Logger logger = Logger.getLogger(MyClass.class);
in Constructor:
PropertyConfigurator.configure("log4j.properties");
and in functions:
logger.info("...");
logger.error("...");
// ...
but, it is error info(actually, I have tried to put it almost every dir that I could realize):
log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
at com.corp.ors.demo.OrsDemo.main(OrisDemo.java:228)
log4j:ERROR Ignoring configuration file [log4j.properties].
log4j:WARN No appenders could be found for logger (com.corp.ors.demo.OrsDemo).
log4j:WARN Please initialize the log4j system properly.
the example project could be get from http://www.91files.com/?N3F0QGQPWMDGPBRN0QA8
I know it's a bit late to answer this question, and maybe you already found the solution, but I'm posting the solution I found (after I googled a lot) so it may help a little:
Put log4j.properties under WEB-INF\classes of the project as mentioned previously in this thread.
Put log4j-xx.jar under WEB-INF\lib
Test if log4j was loaded: add -Dlog4j.debug # the end of your java options of tomcat
Hope this will help.
rgds
As already stated, log4j.properties should be in a directory included in the classpath, I want to add that in a mavenized project a good place can be src/main/resources/log4j.properties
You can specify config file location with VM argument -Dlog4j.configuration="file:/C:/workspace3/local/log4j.properties"
You have to put it in the root directory, that corresponds to your execution context.
Example:
MyProject
src
MyClass.java
log4j.properties
If you start executing from a different project, you need to have that file in the project used for starting the execution. For example, if a different project holds some JUnit tests, it needs to have also its log4j.properties file.
I suggest using log4j.xml instead of the log4j.properties. You have more options, get assistance from your IDE and so on...
For a Maven Based Project keep your log4j.properties in src/main/resources. Nothing else to do!
If you put log4j.properties inside src, you don't need to use the statement -
PropertyConfigurator.configure("log4j.properties");
It will be taken automatically as the properties file is in the classpath.
Try:
PropertyConfigurator.configure(getClass().getResource("/controlador/log4j.properties"));
The file should be located in the WEB-INF/classes directory.
This directory structure should be packaged within the war file.
My IDE is NetBeans. I put log4j.property file as shown in the pictures
Root
Web
WEB-INF
To use this property file you should to write this code:
package example;
import java.io.File;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger;
import javax.servlet.*;
public class test {
public static ServletContext context;
static Logger log = Logger.getLogger("example/test");
public test() {
String homeDir = context.getRealPath("/");
File propertiesFile = new File(homeDir, "WEB-INF/log4j.properties");
PropertyConfigurator.configure(propertiesFile.toString());
log.info("This is a test");
}
}
You can define static ServletContext context from another JSP file.
Example:
test.context = getServletContext();
test sample = new test();
Now you can use log4j.property file in your projects.
A few technically correct specific answers already provided but in general, it can be anywhere on the runtime classpath, i.e. wherever classes are sought by the JVM.
This could be the /src dir in Eclipse or the WEB-INF/classes directory in your deployed app, but it's best to be aware of the classpath concept and why the file is placed in it, don't just treat WEB-INF/classes as a "magic" directory.
I've spent a great deal of time to figure out why the log4j.properties file is not seen.
Then I noticed it was visible for the project only when it was in both MyProject/target/classes/ and MyProject/src/main/resources folders.
Hope it'll be useful to somebody.
PS: The project was maven-based.
I found that Glassfish by default is looking at [Glassfish install location]\glassfish\domains[your domain]\ as the default working directory... you can drop the log4j.properties file in this location and initialize it in your code using PropertyConfigurator as previously mentioned...
Properties props = System.getProperties();
System.out.println("Current working directory is " + props.getProperty("user.dir"));
PropertyConfigurator.configure("log4j.properties");
Your standard project setup will have a project structure something like:
src/main/java
src/main/resources
You place log4j.properties inside the resources folder, you can create the resources folder if one does not exist
I don't know this is correct way.But it solved my problem.
put log4j.properties file in "project folder"/config and use PropertyConfigurator.configure("config//log4j.properties");
it will works with IDE but not when run the jar file yourself.
when you run the jar file by yourself just copy the log4j.properties file in to the folder that jar file is in.when the jar and property file in same directory it runs well.
Put log4j.properties in classpath.
Here is the 2 cases that will help you to identify the proper location-
1. For web application the classpath is /WEB-INF/classes.
\WEB-INF
classes\
log4j.properties
To test from main / unit test the classpath is source directory
\Project\
src\
log4j.properties
There are many ways to do it:
Way1: If you are trying in maven project without Using PropertyConfigurator
First:
check for resources directory at scr/main
if available,
then: create a .properties file and add all configuration details.
else
then: create a directory named resources and a file with .properties
write your configuration code/details.
follows the screenshot:
Way2: If you are trying with Properties file for java/maven project Use PropertyConfigurator
Place properties file anywhere in project and give the correct path.
say: src/javaLog4jProperties/log4j.properties
static{
PropertyConfigurator.configure("src/javaLog4jProperties/log4j.properties");
}
Way3: If you are trying with xml on java/maven project Use DOMConfigurator
Place properties file anywhere in project and give correct path.
say: src/javaLog4jProperties/log4j.xml
static{
DOMConfigurator.configure("src/javaLog4jProperties/log4j.xml");
}
For me, it worked when I put the file inside the resources folder.
Also, it was a war file for my project. My recommendation is to ensure that the name of the file is log4j.properties, as my project didn't recognize "log4j2.properties"
Actually, I've just experienced this problem in a stardard Java project structure as follows:
\myproject
\src
\libs
\res\log4j.properties
In Eclipse I need to add the res folder to build path, however, in Intellij, I need to mark the res folder as resouces as the linked screenshot shows: right click on the res folder and mark as resources.
You don't need to specify PropertyConfigurator.configure("log4j.properties"); in your Log4J class, If you have already defined the log4j.properties in your project structure.
In case of Web Dynamic Project: -
You need to save your log4j.properties under WebContent -> WEB-INF -> log4j.properties
I hope this may help you.
Open spark-shell
Then type System.getenv("SPARK_CONF_DIR")
That will print where your log4j.properties should go.

Categories

Resources