NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Problem with listener

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
meatmontreal



Joined: 21 Dec 2011
Posts: 2

PostPosted: Wed Dec 21, 2011 4:16 am    Post subject: Problem with listener Reply with quote

Hello,

So firstly, i'm new at using NetBeans, but from now (until the error in my project) I just loved that IDE !

So, I have to develop an web project using Servlet, JSP and JPA !
Okay, the environment I work with is :
Apache tomcat 7
Hibernate 1.0

So, to clearly get the problem, I made a new project and try to get as far as I was in my real project, and I was once again stuck, which i'll explain step by step !

1.
Create a new database in Derby, named "test", with username "test" and password "tesst", even if it's not needed, I'd rather prefer give every details.
2.
Into a package named "com.test.entity" I created a fake entity called "tested" to create the persistence file, using Hibernate and my new database.
3.
I create into the package "com.test.util" a java class called "PersistenceManager" which contains :
Code:
package com.test.util;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PersistenceManager {
    private static EntityManagerFactory emf;
   
    public static void createEntityManagerFactory() {
        if(emf == null)
            emf = Persistence.createEntityManagerFactory("SupMarkPU");
    }
    public static EntityManagerFactory getEntityManagerFactory(){
        return emf;
    }
    public static void closeEntityManagerFactory(){
        if(emf != null && emf.isOpen())
            emf.close();
    }
}

4.
So I run the project, and i get a beautiful "Hello World", NetBeans' index default JSP page.
5.
I add in the "com.test.listener" package a Web Application Listener, called "ConnectionListener" and just implement the context listener without adding the web.xml (until now, I don't create the web.xml, and won't if I can do so). The newly file contains :
Code:
package com.test.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener()
public class ConnectionListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

6.
I clean and build the project, then run it, and i got the error :
Quote:
In-place deployment at C:\Users\***\Documents\NetBeansProjects\Test\build\web
deploy?config=file%3A%2FC%3A%2FUsers%2F***%2FAppData%2FLocal%2FTemp%2Fcontext3626557017371864606.xml&path=/Test
ECHEC - Application déployée pour le chemin de contexte /Test mais le démarrage du contexte a échoué
C:\Users\***\Documents\NetBeansProjects\Test\nbproject\build-impl.xml:724:
The module has not been deployed.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
BUILD FAILED (total time: 0 seconds)


So to fix the problem, I have to comment the two "throw" lines and it works, and I can see the "Hello World" again. And for example, i add a "println" fonction to see if the initialization of the context work :

Code:
package com.test.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener()
public class ConnectionListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("contextInitialized called");
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("contextDestroyed called");
    }
}


And it works again, with the "contextInitialized called" string in the apache tomcat 7.0.14.0 log, and the destroy when shutting down the project !

I discover that cause as I wanted to call my persistenceManager create at context's creation, and delete at the context's closing, but it seems I can't use any personal fonctions except "System" 's one.

Please could someone tell me if I did a mistake or if it's NetBeans and i don't need to look any further ?

Thanks for reading.

[EDIT] I'd like to add that this work on eclipse ! But i want to use NetBeans for Derby !!
Back to top
jyeary



Joined: 21 Oct 2008
Posts: 605
Location: Simpsonville, SC

PostPosted: Wed Dec 21, 2011 1:50 pm    Post subject: Re: Problem with listener Reply with quote

The error is not occurring in NetBeans. It is occurring on the deployment to Tomcat. I would use Occam's Razor and say it is likely that something you've coded is incorrect, but I would need to test it first.

John

On Tue, Dec 20, 2011 at 11:18 PM, meatmontreal <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hello,

So firstly, i'm new at using NetBeans, but from now (until the error in my project) I just loved that IDE !

So, I have to develop an web project using Servlet, JSP and JPA !
Okay, the environment I work with is :
Apache tomcat 7
Hibernate 1.0

So, to clearly get the problem, I made a new project and try to get as far as I was in my real project, and I was once again stuck, which i'll explain step by step !

1.
Create a new database in Derby, named "test", with username "test" and password "tesst", even if it's not needed, I'd rather prefer give every details.
2.
Into a package named "com.test.entity" I created a fake entity called "tested" to create the persistence file, using Hibernate and my new database.
3.
I create into the package "com.test.util" a java class called "PersistenceManager" which contains :

Code:
package com.test.util;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PersistenceManager {
Back to top
meatmontreal



Joined: 21 Dec 2011
Posts: 2

PostPosted: Wed Dec 21, 2011 3:56 pm    Post subject: Reply with quote

Thanks for reply.

What should I do ?
I use the default Tomcat from NetBeans 7.0.1 ?

I've learned it like that, and I simply don't see what I can do more ?
I show you everything I coded, except the entity class, but I let it by default, and all the other stuff where automatically coded by NetBeans, so I really don't see the problem...
Could someone try the sample code that I give with the default Tomcat (like I had written) to see if there is still the error ?

[EDIT]
Because of your answer, I tried the Apache Tomcat I used in Eclipse, the 7.0.23, but it still doesn't work !!
I really can't figure it out what is wrong, that's so annoying ...

For being sure, I installed NetBeans all 7.0.1, installed Apache TomCate myself later, but still the same error !!
I don't say that I didn't make a mistake, but I just don't see where, cause I type so less code that it's almost impossible, I let almost everything by default, even the listener who causes the problem, with the "throw" lines, what can I do more ???
It's really urgent, and I'm stuck at that step since 5 days now ...

Can anyone reproduce the sample example I write in my first post to tell me if it's just me or everyone please ?
Back to top
jyeary



Joined: 21 Oct 2008
Posts: 605
Location: Simpsonville, SC

PostPosted: Thu Dec 22, 2011 1:25 pm    Post subject: Re: Problem with listener Reply with quote

The application I sent, and posted online should work on NB 7.0.1 and Tomcat 7.x. I did not try using ServletContextListener. I used HttpSessionListener, and maybe that is the difference. I don't have access to a system to check at the moment.

John

On Wed, Dec 21, 2011 at 10:56 AM, meatmontreal <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks for reply.

What should I do ?
I use the default Tomcat from NetBeans 7.0.1 ?

I've learned it like that, and I simply don't see what I can do more ?
Could someone try the sample code that I give with the default Tomcat (like I had written) to see if there is still the error ?







--
John Yeary
--
http://javaevangelist.blogspot.com
http://www.johnyeary.com
@jyeary

"Far better it is to dare mighty things, to win glorious triumphs, even though checkered by failure, than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the gray twilight that knows not victory nor defeat."
-- Theodore Roosevelt
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo