Page 1 of 2 12 LastLast
Results 1 to 20 of 23
Like Tree1Likes

Thread: Struts2 blues

  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Struts2 blues

    Some might have missed me? I enrolled, a few month ago, in a intensive JavaEE training. Together with my excellent Java monitor, I developed a larger, servlet based, DB-web-application, using Eclipse-Luna (respecting, of course, the 3-tier design of resource/ business/ presentation layer).

    I finished that part of the course successfully.

    I am collaborating with other programmers and my monitor controls me almost rigidly in order that I stick to a companies-program: so my “freewheeling-lonely-programmers” attitude is definitely over. It is hard for me, but I am trying to accomplish this new paradigm very much! So I have a much better understanding of gimbals2’s attitude towards me in the past, and I’d like to say that I was wrong and he was right, and I hope that he will accept my apologies!

    Now to my problem that deals with the above servlet application but this time changed into a struts2, Rest and Maven application. There are two Java-projects. I started with an application which holds the DB-model (POJOs), the DAOs, the DAO-implementations, the JPA-entity-manager and some user-case-controllers (actually the DB/resource part and the business part which holds the application-logic). This part of the larger application works perfectly and I can apply the CRUDs on the MYSQL database successfully!

    (In order to understand, there are two phases of developing a single Java dynamic web-application project
    -each containing two Java-applications that ought to work together:
    1) a DB-JPA-Java-Application and web-application in the form a servlet;
    2) the same DB-JPA-Java-Application and a web-application in the form of a struts2 application)

    Now than to the presentation layer.
    The previous Servlet part, which accomplishes the DB-DAO-JPA-application, works in the following way: I created a jar of the DB-JPA-application and placed that jar in the WEB-INF/lib of the servlet-application. Understand please that I did NOT work with Maven than, so I needed to get all the jars manually (quite a hustle)!

    The second phase, the struts2.app, that follows the servlet-app.
    Like I said the Struts2 has a REST-plugin. Both, the previous DB-JPA-application and the Struts web-application run now on Maven (amazing technology but quite a hustle to get the pom right).

    I created the Maven/struts application in the following manner:
    1) Eclipse Luna-new-project-maven project-maven archetype web app. (Now, some later I regretted doing that!);
    2) I made JPA available through: properties-project facets.
    3) The file tree is:
    src/main/java
    resources
    webapp
    under java you’ll find the Java code in several packages
    under resources you’ll find the struts.xml and the META-INF (!)
    under webapp you’ll find WEB-INF that holds the web.xml and a content folder that holds all the JSP-files

    There are also the directories: “java resources”, “javaScript Resources” and “Deployed Resources” and the las one holds: the webapp mentioned above and a folder called “web-resources” which contains again (!) the META-INF/maven etc.

    Ok here comes the problem:
    When using the same technic that I used in the previous servlet-project and I enter the DB-model-JPA application through a jar file into the Struts2 application I get the following error:

    WARN: HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost:3306/petstore
    Jul 14, 2014 8:39:06 PM com.opensymphony.xwork2.util.logging.commons.Commo nsLogger error
    SEVERE: Exception occurred during processing request: [PersistenceUnit: petstore-jpa] Unable to build EntityManagerFactory
    javax.persistence.PersistenceException: [PersistenceUnit: petstore-jpa] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityMan agerFactory(Ejb3Configuration.java:915)

    From here on I tried many things (I am more then three days trying!):
    Making the first application available by properties-java build path-source. Finally merging the two applications together into one single Struts2-Maven-JPA project.

    The above error persists and I do not know anymore what to do!

    BTW an important piece of information is, is that the persistence.xml always resides in the META-INF, right? The problems is where does that folder META-INF resides?
    I believe at src/main/META-INF (that’s where I put it)!
    But there are also other options like WEB-INF/classes?

    And when I test the application part without the Struts2 (DB-model-JPA application), of the combined application, the entity-manager works
    and the CRUDs as well!

    This META-INF might be the problem……
    I am at the end of my story literally!
    Last edited by willemjav; 07-15-2014 at 01:58 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: Struts2 blues

    "No suitable driver found for jdbc:mysql://localhost:3306/petstore."

    That's telling you that the MySQL driver is not on the runtime classpath.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    Quote Originally Posted by willemjav View Post
    So I have a much better understanding of gimbals2’s attitude towards me in the past, and I’d like to say that I was wrong and he was right, and I hope that he will accept my apologies!
    Sure thing buddy. I accept some blame too, I have a hard time reading when someone needs a soft push and when someone needs a hard push and that sometimes blows up in my face.

    To maintain our new mutual understanding, I'm going to keep my mouth shut right now ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    Thanks, gimbal2.
    When running the DAO-tester of the DB-JPA-application (merged with the struts2) the driver is present (see pom) and on the path!
    But when starting up the Eclipse-server maybe not? How come tolls?

    Java Code:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.company.petstore</groupId>
    	<artifactId>petstore</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<packaging>war</packaging>
    	
    
    
      <build>
        <resources>
          <resource>
            <directory>src/resources</directory>
          </resource>
        </resources>
      </build>
    
    
      
    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
    
    	<dependency>
    		<groupId>mysql</groupId>
    		<artifactId>mysql-connector-java</artifactId>
    		<version>5.1.6</version>
    	</dependency>
    	<dependency>
    		<groupId>org.hibernate.common</groupId>
    		<artifactId>hibernate-commons-annotations</artifactId>
    		<version>4.0.1.Final</version>
    	</dependency>
    	<dependency>
    		<groupId>org.hibernate</groupId>
    		<artifactId>hibernate-entitymanager</artifactId>
    		<version>4.1.2</version>
    	</dependency>
    	<dependency>
    		<groupId>taglibs</groupId>
    		<artifactId>standard</artifactId>
    		<version>1.1.2</version>
    	</dependency>
    	<dependency>
    		<groupId>javax.mail</groupId>
    		<artifactId>mail</artifactId>
    		<version>1.4.1</version>
    	</dependency>
    	<dependency>
    		<groupId>javax.servlet</groupId>
    		<artifactId>jstl</artifactId>
    		<version>1.2</version>
    	</dependency>
    	<dependency>
    		<groupId>javax.servlet</groupId>
    		<artifactId>javax.servlet-api</artifactId>
    		<version>3.0.1</version>
    		<scope>provided</scope>
    	</dependency>
    	<dependency>
    		<groupId>javax.servlet</groupId>
    		<artifactId>jsp-api</artifactId>
    		<version>2.0</version>
    		<scope>provided</scope>
    	</dependency>
    <!--  Struts 2  -->
    	<dependency>
    		<groupId>org.apache.struts</groupId>
    		<artifactId>struts2-core</artifactId>
    		<version>2.3.16.1</version>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.struts</groupId>
    		<artifactId>struts2-sitemesh-plugin</artifactId>
    		<version>2.3.16.1</version>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.struts</groupId>
    		<artifactId>struts2-convention-plugin</artifactId>
    		<version>2.3.16.1</version>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.struts</groupId>
    		<artifactId>struts2-rest-plugin</artifactId>
    			<version>2.3.16.1</version>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.struts</groupId>
    		<artifactId>struts2-javatemplates-plugin</artifactId>
    		<version>2.3.16.1</version>
    	</dependency>
    	<dependency>
    		<groupId>javax.persistence</groupId>
    		<artifactId>persistence-api</artifactId>
    		<version>1.0.2</version>
    	</dependency>
    
    </dependencies>
    </project>

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: Struts2 blues

    This is where I'd look at the deployed environment.
    Is it in the war file, or in the deployed directory?

    I tend not to use an IDE server for just this reason, and deploy to a separate Tomcat one (or similar).
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    I can share some generic stuff;

    - if your application makes the connection (generally: you don't use a datasource), the jar needs to be on the classpath of the application (WEB-INF/lib)
    - if you use a datasource, the server will probably be the one managing that datasource and so the server needs access to the driver jar

    So say if you use Tomcat, then if you define a datasource in tomcat you need to add the mysql driver to the tomcat/lib directory. But you'd need to figure out which tomcat is actually being used in your environment to know where to put the jar. Whatever server you're using, you'll need to figure out what the proper place is to put "shared" libraries.

    I see mention of the generic petstore application of the JEE tutorial, so you are using Glassfish?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    I am using tomcat7 and indeed as part of eclipse-luna (EE-edition)
    It is a little confusing which jars actually go into the tomcat lib (I added mysql-connector-java-5.1.29-bin but no change
    still getting that error)

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    let me see if I can show a screen shot of the lib

    (Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost:3306/petstore)

    petstore is a name I invented!

  9. #9
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    let me see if I can show a screen shot of the lib

    (Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost:3306/petstore)

    petstore is a name I invented!

    here are the present files at tomcat/lib

    lib peerforce$ ls
    catalina-ant.jar
    servlet-api.jar
    catalina-ha.jar
    tomcat-api.jar
    catalina-tribes.jar
    tomcat-coyote.jar
    catalina.jar
    tomcat-dbcp.jar
    ecj-P20140317-1600.jar
    tomcat-i18n-es.jar
    el-api.jar
    tomcat-i18n-fr.jar
    jasper-el.jar
    tomcat-i18n-ja.jar
    jasper.jar
    tomcat-jdbc.jar
    jsp-api.jar
    tomcat-util.jar
    mysql-connector-java-5.1.29-bin.jar
    tomcat7-websocket.jar
    not used
    websocket-api.jar
    peerforce3:lib peerforce$

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    that is fine. What is in the persistence.xml? What other configuration did you do for the database?

    I would expect:

    - an entry in the context.xml to define the datasource
    - an entry in your web.xml to make the datasource available to your web application
    - the persistence.xml referring to the datasource's JNDI name

    The Tomcat specific bit as documented here: Apache Tomcat 7 (7.0.54) - JNDI Datasource HOW-TO


    You might also adopt some ideas from this article I wrote; its not about Struts though:

    http://entjavastuff.blogspot.nl/2012...-tomcat-7.html
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    here is the persistence.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    	<persistence-unit name="petstore-jpa">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<properties>
    			<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/petstore"/>
    			<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    			<property name="javax.persistence.jdbc.user" value="root"/>
    			<property name="javax.persistence.jdbc.password" value=""/>	
    		</properties>
    	</persistence-unit>
    </persistence>


    and the content.xml

    Java Code:
    <?xml version='1.0' encoding='utf-8'?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <!-- The contents of this file will be loaded for each web application -->
    <Context>
    
        <!-- Default set of monitored resources -->
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
    
        <!-- Uncomment this to disable session persistence across Tomcat restarts -->
        <!--
        <Manager pathname="" />
        -->
    
        <!-- Uncomment this to enable Comet connection tacking (provides events
             on session expiration as well as webapp lifecycle) -->
        <!--
        <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
        -->
    
    </Context>

  12. #12
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    Going over your article, good stuff!
    Noted that there can be a context.xml at
    src/main/webapp/META-INF/context.xml
    I did not know that!
    Where would be the META-INF/persistence.xml at a struts2/maven/JPA application?

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    There is no difference, its all a "java application" so it is always in exactly the same location. It needs to be in a folder META-INF in the root of the classpath. In Maven terms: in a src/main/resources/META-INF.

    Note: the context.xml bit of the article is actually one of those things on the todo list that I need to update... I don't know if you're using Eclipse, but Eclipse generates its own context.xml when you setup the Tomcat server inside of it and you need to modify -that- context.xml file. If everything is correct Eclipse will have setup a 'Servers' item in your project view where you can find the file to edit.

    It is not a good idea to deploy a context.xml with a datasource as part of your application since on each server where you will want to deploy the application (development, test, production) you will want a different context.xml pointing to a different database. But that's an easy to overcome detail to worry about much later.
    Last edited by gimbal2; 07-15-2014 at 03:11 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    Thanks, yes I do use eclipse (luna EE) and I will find out where she holds that content.xml!
    Ok so it is the one inside the server folder.
    Last edited by willemjav; 07-15-2014 at 03:36 PM.

  15. #15
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    After again constructing the project (getting some help and reading the article of gimbal2) I got a little further. The error message now shows also this:

    javax.persistence.PersistenceException: Invalid persistence.xml.
    Error parsing XML (line-1 : column -1): cvc-elt.1: Cannot find the declaration of element 'persistence'.


    That I do not understand here, see pls again the xml at previous post 11!

    No, I am actually using this one now (sorry):

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    	<persistence-unit name="petstore-jpa">
    		<properties>
    			<property name="hibernate.connection.username" value="root"/>
    			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/tempura"/>
    			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    		</properties>
    	</persistence-unit>
    </persistence>
    Last edited by willemjav; 07-16-2014 at 10:35 AM.

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    If you had help from my article then your persistence.xml should not look anymore like it does in post #11.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  17. #17
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    ok I´ll look into that again!

  18. #18
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    btw: you went backwards, not forwards. There was a point in time (yesterday) where your persistence.xml did not fail to be parsed so I would review all the things you've been doing since then.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  19. #19
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: Struts2 blues

    Yesterday´s was <persistence version="2.0"
    today´s is <persistence version="2.1"
    I do not even remember doing that!
    I taught there might lay the problem, and that I have to change the
    hibernates from 4.0.1/ 4.1.2 to 3.5......
    And you are right if you do not get the pom "right" IT TURNS INTO A MESS!

  20. #20
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: Struts2 blues

    Basically you've just been trying stuff and hope for the best; that is your main problem. You can't blame the tools.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 1 of 2 12 LastLast

Similar Threads

  1. Newbie connection blues
    By byterbit in forum JDBC
    Replies: 9
    Last Post: 12-09-2011, 10:07 PM
  2. Replies: 0
    Last Post: 10-30-2011, 03:38 PM
  3. struts2 tag
    By aaruviswa in forum Web Frameworks
    Replies: 1
    Last Post: 03-17-2011, 10:34 AM
  4. struts2
    By catchme33 in forum Web Frameworks
    Replies: 4
    Last Post: 03-25-2009, 10:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •