How to configure a Google Web Toolkit application with Datanucleus + PostgreSQL - postgresql

I created an application using GWT and support for the Google Datastore but now i'm trying to move my application to my own server and i'm also trying to detach my app from Google App Engine and from Datastore.
To be more precise: I want to stop using Google Datastore and start using JDO and Datanucleus but with PostgreSQL (or other relational database). I tried searching in Datanucleus.org but there was no simple tutorial for me to use.
Please, can someone help me?
Thank you very much!
=)

I've discovered how to do it though I think it should be more easy eheheh.
Here it goes:
1) First we must setup PostgreSQL server;
2) Create our web application with webAppCreator (from GWT SDK);
3) Since we must enhance our domain classes for them to be used by datanucleus and JDO, we have multiple options to do it. I used an Apache Ant task ( from Google App Engine SDK). If we do this we can use the good parts from app engine (simple class enhancement) but our application won't be tied to the restrictions of App Engine.
The additions to the build.xml created with webAppCreator:
<!-- this refers to the location of my Google AppEngine SDK -->
<property name="sdk.dir" location="C:/Projects/appengine-java-sdk" />
<import file="${sdk.dir}/config/user/ant-macros.xml" />
<target name="copyjars"
description="Copies the App Engine JARs to the WAR.">
<copy
todir="war/WEB-INF/lib"
flatten="true">
<fileset dir="${sdk.dir}/lib/user">
<include name="**/*.jar" />
</fileset>
</copy>
</target>
<target name="compile" depends="copyjars"
description="Compiles Java source and copies other source files to the WAR.">
<mkdir dir="war/WEB-INF/classes" />
<copy todir="war/WEB-INF/classes">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<javac
srcdir="src"
destdir="war/WEB-INF/classes"
classpathref="project.class.path"
debug="on" />
</target>
<target name="datanucleusenhance" depends="compile"
description="Performs JDO enhancement on compiled data classes.">
<enhance_war war="war" />
</target>
4) Download the PostgreSQL JDBC Driver from the official site;
5) Download the datanucleus-rdbms.jar file from the official sourceforge page;
6) Add these jars to the Project Classpath;
7) Create a file with the following content:
javax.jdo.PersistenceManagerFactoryClass=org.datanucleus.jdo.JDOPersistenceManagerFactory
javax.jdo.option.ConnectionDriverName=org.postgres.jdbc.Driver
javax.jdo.option.ConnectionURL=jdbc:postgres://localhost:5432/myschool
javax.jdo.option.ConnectionUserName=root
javax.jdo.option.ConnectionPassword=rootroot
datanucleus.autoCreateTables=true
8) Create a PersistenceManagerFactory like this:
File propsFile = new File("Insert the location of the properties file here");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(propsFile);
9) Create the domain classes and run the new Ant Target datanucleusenhance;
10) This will create enhanced classes and the connection with the relational database and also store the information in the PostgreSQL's tables.
11) If I'm not mistaken and if I didn't forget anything than that's all :)
Thank you for reading the question.
Please, if you notice anything wrong, can you tell me? It's my first time here :P
==== Some References ====
http://code.google.com/intl/en/appengine/docs/java/tools/ant.html#Enhancing_JDO_Classes

Related

.war file won't be updated

I have an old project, built using Google Web Toolkit in Eclipse. When I created it, I did the following steps, in order to get the .war file
GWT Compile Project
Run the following Ant script
<project name="The" basedir="." default="default">
<target name="default" depends="buildwar,deploy"></target>
<target name="buildwar">
<war basedir="war" destfile="The.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="The.war" todir="." />
</target>
</project>
Get the .war file
Now, I had to change a port in my project, so I changed it in my code and did the same steps in order to get the .war
However, when I deploy my updated project in Tomcat, it still makes requests to the old port number (I found this reading catalina.out)
So, What can I do in order to get a new, fresh .war ???
You don't mention it, but did you change the ports in tomcat? I assume you did, but I just want to cover all possibilities.

Automate jar export across projects in eclipse

I have a Google Web Toolkit project for which i include a second project into the build path. This other project has a lot of my commonly used functions and classes. Building the project works fine but to avoid run time errors i have to jar the second project into the WAR folder of the GAE project.
The process of jar/exporting the second project into the first is a manual process that i do with a right click in eclipse.
Is there a way to automate the process of jar/exporting to WAR of the second project into a location on the first?
Would i do this with an ANT script?
Or is there a way this can be done within Eclipse itself.
Thanks for you help
You are in for some reading mate :)
Step 1 : Create a JAR of the first project ( Read this). In the jar task you could put as the path of your GAE's folder lib as the destfile like so :
<target name="jar">
<jar basedir="bin" destfile="../GAE_PROJECT/war/WEB-INF/lib/${project-name}.jar">
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</jar>
</target>
Step 2 : Create the WAR for your GAE project ( Read the official documentation here ). The documentation shows how the jars in the lib are included :
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>

script to execute the eclipse PDE Tools > Build site

i want to write a script to do the Build site of plugin Update site site.xml?
i could not find a way to do this?
i found very easy to build a plugin feature. I can automatically creat the ant file build.xml via eclipse but i could not find the same for the update site.xml
thank you all
stefania
Are you trying to build an Eclipse plugin from Ant? You want to use the Ant4Eclipse external add-on for Ant. It lets you build the run-configurations you've made in Eclipse (right click>run as>...) from your .project file. You can download it here and there is a tutorial here.
I attempted to do what you're asking at a previous job without using Ant4Eclipse, I don't remember how I got it working, but I do remember it being extremely difficult.
Edit: you can build an Eclipse update site from the command line, which can be run from Ant. There is some [possibly out of date] documentation here, but I found you a sample from an Apache projects build.xml:
<target name="build-site" depends="init">
<copy todir="target/eclipse-update-site/web" preservelastmodified="true">
<fileset dir="web"/>
</copy>
<copy todir="target/eclipse-update-site" file="index.html" preservelastmodified="true"/>
<copy todir="target/eclipse-update-site" file="site.xml" preservelastmodified="true"/>
<!-- copy all the features to the target -->
<copy todir="target/eclipse-update-site/features" preservelastmodified="true" >
<fileset dir="features"/>
</copy>
<!-- see http://wiki.eclipse.org/Update_Site_Optimization -->
<java jar="${eclipse.home}/plugins/org.eclipse.equinox.launcher.jar" fork="true" failonerror="true"
maxmemory="256m">
<arg line="-application org.eclipse.update.core.siteOptimizer"/>
<arg line="-digestBuilder -digestOutputDir=target/eclipse-update-site"/>
<arg line="-siteXML=target/eclipse-update-site/site.xml"/>
</java>
</target>

Using Guava with GWT

Could someone tell me what I need to do to enable Guava support in GWT.
I have downloaded Guava R07 and in there there are the following two files:
guava-r07.jar
guava-r07-gwt.jar
I have a few questions regarding this:
Where do these files go? I am guessing that the standard Jar is made available to my IDE for coding, and that both are made available to the GWT compiler for building the JavaScript?
Do I need to add all the .gwt.xml files from the -gwt.jar into my project's main gwt.xml file or only the portions I need?
There are other Jars on the trunk of the Guava&GWT project (ie not in the download, such as one for jsr305) which I think I may need, but I'm not sure.
Sorry, normally I don't have trouble with this kind of thing, but I can't quite work out what goes where.
FYI I'm using GWT 1.6 for the time being, but am hoping to move to 2 soon. If Guava isn't compatible with 1.6 that is not a problem.
Update
I have the following files in a folder called gwtlib:
guava-r07-gwt.jar
guava-r07.jar
jsr305-1.3.9.jar
And my Ant script does the following:
<path id="project.class.path">
<fileset dir="gwtlibs" includes="guava-r07.jar"/>
<fileset dir="gwtlibs" includes="guava-r07-gwt.jar"/>
<fileset dir="gwtlibs" includes="jsr305-1.3.9.jar"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
</path>
<target name="gwtc">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="app"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-localWorkers"/>
<arg value="2"/>
<arg value="-war"/>
<arg value="gwt-public"/>
<arg value="Main"/>
</java>
</target>
Running the above command, I get the following errors:
Errors in 'jar:file:///project/gwtlibs/guava-r07-gwt.jar!/com/google/common/collect/Constraints.java'
Line 254: The method subList(int, int) is undefined for the type List
Without the jsr jar on the classpath, I get the following errors:
The import javax.annotation cannot be resolved
Nullable cannot be resolved to a type
Thanks
Rich
Add these jars to your classpath. If you're using IDE, add them to your Build Path by right-clicking "Referenced Libraries" in your Package Exporer, select "Configure Build Path" and add them as external JARs.
You only need to inherit the modules you plan on using in your .gwt.xml file. For example, if you only use the common.collect package, just add <inherits name="com.google.common.collect.Collect" />
You probably don't need jsr305.jar, but if you do, just add it the same way as you added the other jars.
Guava should work just fine with GWT 1.6, if it doesn't then it's probably a bug.
Guava isn't compatible with GWT 1.6. List.subList, in particular, is added to GWT in GWT 2. The earliest version that we fully supported is GWT 2.0.4

Problem with .cod deployment to simulator

This is a re-post of a topic on the Blackberry Development Forums, but I wasn't getting any answers there, so I thought I would try SO.
I have an in-house library that I developed called Ichabod that is required by one of our applications, Spyder, which runs on the Blackberry 4.5.0 operating system (our original target was for 8330 devices). I had everything working with bb-ant-tools to compile the library, which is in a separate project, and deploy it to C:\Program Files\eclipse\plugins\net.rim.ejde.componentpack4.5.0_4.5.0.21\components\simulator. The Spyder application debugged just fine in the eclipse plugin (I am using Galileo with the 1.1.2 version of the RIM plugin).
Today, however, I went to debug the Spyder application after making a couple of changes to the code (no code changes were made in Ichabod), and found that the application couldn't find the Ichabod module all of a sudden. I noticed that there was now a net.rim.ejde.componentpack4.5.0_4.5.0.28\ directory in my eclipse plugins folder, so thinking that perhaps I updated the component packs without realizing it, I adjusted the target path of the Ichabod library, and rebuilt it with bb-ant-tools. Same problem. So, I tried removing the .cod and all associated files from both the 4.5.0.21 and 4.5.0.28 directories, recompiled the Ichabod library to deploy to both locations, and found that it works with 4.5.0.21, but not with 4.5.0.28 (it's not listed in the modules screen under Settings, either).
I have verified that the .cod file is present in the components\simulator folder, but I can't seem to figure out why the simulators don't recognize the file.
Any suggestions?
My bb-ant-tools build.xml script is attached.
Thanks,
~Scott
<taskdef resource="bb-ant-defs.xml" classpath="lib/bb-ant-tools.jar" />
<property name="jdehome" value="C:\Program Files\eclipse\plugins\net.rim.ejde.componentpack4.5.0_4.5.0.28\components" />
<property name="simulator" value="${jdehome}\simulator" />
<property name="bin" value="${jdehome}\bin" />
<target name="deploy" depends="build" description="Builds and Deploys Project (installs to simulator)">
<copy todir="${simulator}" overwrite="true">
<fileset dir="output">
<include name="*.cod" />
<include name="*.debug" />
<include name="*.csl" />
<include name="*.cso" />
</fileset>
</copy>
</target>
<target name="clean" description="Cleans the output directory">
<delete dir="output"/>
<mkdir dir="output"/>
</target>
<target name="build" depends="clean" description="Builds Project">
<rapc jdehome="${jdehome}"
destdir="output"
output="Ichabod"
quiet="false">
<jdp type="library"
title="Ichabod Library"
vendor="My Company"
version="0.3"
description="Ichabod Library for Mobile Applications"
arguments=""
systemmodule="false"
runonstartup="false"
startuptier="7"
ribbonposition="0">
</jdp>
<src>
<fileset dir=".">
<include name="src/**/*.java" />
<!-- <include name="resource/**/*.*" /> -->
</fileset>
</src>
</rapc>
</target>
</project>
So it appears, after removing the 4.5.0.28 plugin from Eclipse and reinstalling it, that this was what was causing my troubles. I don't know whether this has anything to do with it, but I also removed the JDE 4.5.0 library (which was correctly set at version 28) from the build path of the Ichabod project and replaced it with the same JDE.
After all of this nonsense, my library now shows up in the simulator. Thanks to all who looked at this. Hopefully this will help someone else.