DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page J2EE help
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default J2EE help - 04-01-2008, 09:41 AM

Hi all,

I have a few questions. I am new to both maven and spring and am having problems getting dependency injection working in my web application which is deployed on tomcat 6. I also cannot seem to get the maven webstart plugin working the way I'd like.

When I try to run the web application through jetty, I get a configuration exception, could not bind resource to name jdbc/walterjwhite. I am trying to use JNDI instead of a local resource for the datasource.

The exception I get inside of tomcat is merely a null pointer exception meaning that the dependency was not injected because it is null when I try to use a manager. Inside my web.xml, I have a listener which should startup spring, but is there anything else I need to do to get Spring working in tomcat?


The last issue is with webstart. I would like to generate a webstart application within my web application project. So, when the .war file is created, inside it will have a jar containing all the classes in my web app, and a jnlp which will allow me to execute it. I'm unsure how to use the webstart plugin as I thought I could do it in one project, but it looks like I may have to have 2, one for webstart, the other for the web application.


Please let me know, I am not sure where else to find this information and I don't see a whole lot of posts regarding these topics.


Walter
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default 04-02-2008, 11:56 AM

First in your web.xml do you have this?
<web-app>
<listener> <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
</listener>
</web-app>

This loads a spring context for your webapp. Now in your WEB-INF directory there should be a file called applicationContext.xml which then references your other spring configuration files or this file can have all your spring DI beans.
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default 04-02-2008, 11:58 AM

Another note if you don't want to have the default name of applicationContext you can add this line to your web.xml. Then where I have mySpringContext.xml you have your spring context name in there.

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mySpringContext.xml
</param-value>
</context-param>
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default spring dependency injection not working - 04-02-2008, 12:16 PM

Hi,

Thanks for your reply.

I actually have that in my web.xml, when I get home today, I will post all my configuration files. I do have dependency injection working properly when running my unit tests so that part is configured properly.

I am wondering if there is anything special I need to do for Tomcat 6 or the web environment? I also have issues with Jetty not resolving my dataSource jdbc/walterjwhite which is setup to use JNDI or so I think.


Thanks,
Walter
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default 04-02-2008, 12:55 PM

Nothing special for spring configurations in tomcat or other web environments.

The Jetty problem in resolving datasources should be as simple as having someinthing like this:
<bean id="myJndiDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean" lazy-init="true">
<property name="jndiName" value="java:myDS" />
</bean>

As far as spring picking up the jndi I've noticed in the past for instance in JBoss 4+ if my web app had contained one of the Jboss-client.jar or jbossall-client.jar jndi in the application would fail. Being that you are using maven make sure that your webapplication lib directory is free of any uncessary libraries and if libraries do creap in you will have to in the maven dependencies add to the library <scope>provided</scope>. With Maven2 this is a bigger problem as libraries that have dependencies to other libraries will pull thme into your application, despite your application container possibly having the library already. This causes weird classpath loading issues, such as unable to resolve JNDI.
Reply With Quote
  (#6 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default J2ee - 04-02-2008, 01:30 PM

Hi,

Thanks. I will double check my code tonight to make sure that is in there.

Now, I just need to find someone with maven webstart experience so I can get that part of the application working.

Once I get these puzzles solved, the rest is up to me to write the code.


Walter
Reply With Quote
  (#7 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default J2ee - 04-02-2008, 08:36 PM

Hi,

Here is my current setup:

web.xml
Code:
<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value> 
	    /WEB-INF/applicationContext*.xml
	</param-value>
    </context-param> 
    
    <listener>
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

<resource-ref>
	<res-ref-name>jdbc/walterjwhite</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
    </resource-ref>
ApplicationContext.xml
Code:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/walterjwhite" resource-ref="true"/>
    <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
	<property name="persistenceXmlLocations">
	    <list>
		<value>classpath:****-INF/persistence.xml</value>
	    </list>
	</property>
	<property name="defaultDataSource" ref="dataSource"/>
    </bean>
    
    <bean id="entityManagerInterceptor" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
	<property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    
    <!-- JPA EntityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
	<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
    </bean>
    
    <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
	<property name="entityManagerFactory" ref="entityManagerFactory"/>
	<!--<property name="dataSource" ref="dataSource"/>-->
    </bean>
    
    <!--
		Instruct Spring to perform declarative transaction management automatically
		on annotated classes.  transaction-manager="transactionManager"
    -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    <!-- Needed so the @PersistenceUnit annotation is recognized -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
    <bean id="finderIntroductionAdvisor" class="com.walterjwhite.aspect.FinderIntroductionAdvisor"/>
Walter
Reply With Quote
  (#8 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default 04-02-2008, 11:42 PM

Here is my maven project build with webstart

Quote:
<pluginRepositories>
<pluginRepository>
<id>maven-snapshots</id>
<url>http://snapshots.repository.codehaus.org</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>common-gui</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>hal</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>jsapi</artifactId>
<version>1.2.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>freetts</artifactId>
<version>1.2.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>en_us</artifactId>
<version>1.2.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>cmudict04</artifactId>
<version>1.2.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>cmulex</artifactId>
<version>1.2.1</version>
<!--<scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>cmutimelex</artifactId>
<version>1.2.1</version>
<!--<scope>provided</scope> -->
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
org.softlanding.hal.Hal9000
</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>jsapi</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>jsapi-1.2.1.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>freetts</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>freetts.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>en_us</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>en_us.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>en_us</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>en_us-1.2.1.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>cmulex</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>cmulex.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>cmutimelex</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>cmutimelex.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.sun</groupId>
<artifactId>cmu_us_kal</artifactId>
<version>1.2.1</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>cmu_us_kal.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>${pom.groupId}</groupId>
<artifactId>common-gui</artifactId>
<version>${pom.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>common-gui-${pom.version}.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>${pom.groupId}</groupId>
<artifactId>hal</artifactId>
<version>${pom.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${pom.name}-${pom.version}/dist</outputDirectory>
<destFileName>hal-${pom.version}.jar</destFileName>
</artifactItem>
</artifactItems>

<!-- other configurations here -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.softlanding.hal.Hal9000</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.png</include>
<include>**/*.jpg</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
My project hiearchy has main/webapp/ where I have a jsp page.
Quote:
<html>
<head><SCRIPT LANGUAGE="JavaScript">

var javawsInstalled = 0;
var javaws142Installed=0;
var javaws150Installed=0;
isIE = "false";
if (navigator.mimeTypes && navigator.mimeTypes.length) {
x = navigator.mimeTypes['application/x-java-jnlp-file'];
if (x) {
javawsInstalled = 1;
javaws142Installed=1;
javaws150Installed=1;
}
}
else {
isIE = "true";
}

</SCRIPT>
<SCRIPT LANGUAGE="VBScript">

on error resume next
If isIE = "true" Then
If Not(IsObject(CreateObject("JavaWebStart.isInstalle d"))) Then
javawsInstalled = 0
Else
javawsInstalled = 1
End If
If Not(IsObject(CreateObject("JavaWebStart.isInstalle d.1.4.2.0"))) Then
javaws142Installed = 0
Else
javaws142Installed = 1
End If
If Not(IsObject(CreateObject("JavaWebStart.isInstalle d.1.5.0.0"))) Then
javaws150Installed = 0
Else
javaws150Installed = 1
End If
End If

</SCRIPT>
</head>


<a name="Quick Installation"></a><div class="section"><h2>Quick Installation</h2>
<p>This is a quick easy installing application, because it is a webstart enabled application. That means if you have the latest Java runtime (Java 1.5 or higher) installed on your
system; you should be able to run the application with one click on this page. If you see the Launch button click on it to automatically install otherwise follow the instructions to
install a Java runtime environment.</p>
<SCRIPT language="JavaScript">

/* Note that the logic below always launches the JNLP application
*if the browser is Gecko based. This is because it is not possible
*to detect MIME type application/x-java-jnlp-file on Gecko-based browsers.
*/
if (javawsInstalled || (navigator.userAgent.indexOf("Gecko") !=-1)) {
document.write("Install latest version of Heang 2000 <a href=heang-2000.jnlp><img src=webstart-button.gif></a>");
} else {
document.write("Click ");
document.write("<a href=http://java.sun.com/PluginBrowserCheck?pass=http://10.1.10.114:8080/index.jsp&fail=http://java.sun.com/j2se/1.5.0/download.html>here</a>");
document.write("to download and install JRE 5.0 and the application.");
}

</SCRIPT>
</p>
</div>
</html>
It references my webstart.jnpl file

To run my maven build I use mvn clean dependency:copy install

My JNLP file references jar dependencies in the war which should have been created in a directory inside the war called dist/somejarname.jar
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does your Java/J2EE Resume Stand-Out? arulk Java 0 07-01-2008 10:50 PM
Eclipse and j2ee preview MrMiagi Eclipse 6 03-11-2008 06:06 AM
Can't remove j2ee.jar from build path joezaloom Eclipse 1 02-12-2008 08:46 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com