Re: EnterpriseObjects in a regular Java application
Re: EnterpriseObjects in a regular Java application
- Subject: Re: EnterpriseObjects in a regular Java application
- From: John Lennard <email@hidden>
- Date: Wed, 1 Feb 2006 08:35:06 +1300
H,
I wrote a script to deal with all of this, but essentially, i
included my jar that contained the application in the class path and
did not use the jar argument and had the class path and the just the
name of the main class to run specified (ignore the config props
part, as this is used by lewstuff, and set the memory as you see fit,
or ignore the memory settings if you are happy with the default sizes).
<snip>
for jar in `cat ./jars`
do
cp=$cp:$jar
done
cp=$cp:$PWD
echo $cp
java -Xmx256m -Dnz.co.lindesay.common.ConfigPropsFile=/Users/john/
Documents/holidaybook/config/config.properties -cp $cp EOFImageMunger
</snip>
and in the jars file i had a list of the jars, one on each line.
<snip>
/System/Library/Frameworks/JavaEOControl.framework/Resources/Java/
javaeocontrol.jar
/System/Library/Frameworks/JavaFoundation.framework/Resources/Java/
javafoundation.jar
/System/Library/Frameworks/JavaEOAccess.framework/Resources/Java/
javaeoaccess.jar
/System/Library/Frameworks/JavaXML.framework/Resources/Java/javaxml.jar
/System/Library/Frameworks/JavaJDBCAdaptor.framework/Resources/Java/
javajdbcadaptor.jar
build/EOFImageMunger.jar
</snip>
also, in reference to the other posts mentioning NSBundles etc, i did
not need to use or fiddle with any of those classes to get my
application working.
i also, manually locked and unlocked the editing context, as i was
unsure how this would behave when not inside a woapplication.
john.
On 1/02/2006, at 7:43 AM, John Huss wrote:
I'm having trouble getting java to recognize the classpath
argument. Here's what I'm doing:
JohnMac:~/Documents/workspace John$ java -cp "./MyApplication.jar:/
System/Library/Frameworks/JavaEOControl.framework/Resources/Java/
javaeocontrol.jar:/System/Library/Frameworks/
JavaFoundation.framework/Resources/Java/javafoundation.jar:/System/
Library/Frameworks/JavaEOAccess.framework/Resources/Java/
javaeoaccess.jar:/System/Library/Frameworks/JavaXML.framework/
Resources/Java/javaxml.jar:/System/Library/Frameworks/
JavaJDBCAdaptor.framework/Resources/Java/javajdbcadaptor.jar:/
Library/Frameworks/FrontBasePlugIn.Framework/Resources/Java/
frontbaseplugin.jar:/Library/Frameworks/ERExtensions.Framework/
Resources/Java/ERExtensions.jar:." -jar ./MyApplication.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/
webobjects/foundation/NSArray
It's all on one line. The classpath is specificied with -cp,
right? And the jars are separated with colons. What's wrong?
John
----- Original Message ----- From: "John Lennard"
<email@hidden>
To: "WebObjects-List Apple" <email@hidden>
Sent: Monday, January 30, 2006 7:02 PM
Subject: Re: EnterpriseObjects in a regular Java application
Hi,
I followed the stepwise article, but found that a few things in
it were no longer relevant or api's had changed.
This is how i got my editingContext etc.
<snip>
//gets a url for the model
modelUrl = new URL("file:holidaybook.eomodeld");
EOModel model = new EOModel(modelUrl);
EOModelGroup mg = EOModelGroup.defaultGroup();
mg.addModel( model );
//use lewo stuff to specify the db to connect to
LEEOHelper.setDBConnectionForNamedModel("file:holidaybook",
LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCDRIVER),
LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCURL),
LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCUSERNAME),
LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCPASSWD));
</snip>
and due to general laziness, this is how i created my editing
context as a class variable (i know, very lazy :-)
<snip>
protected static EOEditingContext ec = new EOEditingContext();
</snip>
with this, i used the lewostuff framework from http://
www.lindesay.co.nz to alter the connection properties of the model.
and this is the list of the jar files that are needed
<snip>
/System/Library/Frameworks/JavaEOControl.framework/Resources/Java/
javaeocontrol.jar
/System/Library/Frameworks/JavaFoundation.framework/Resources/
Java/ javafoundation.jar
/System/Library/Frameworks/JavaEOAccess.framework/Resources/Java/
javaeoaccess.jar
/System/Library/Frameworks/JavaXML.framework/Resources/Java/
javaxml.jar
/System/Library/Frameworks/JavaJDBCAdaptor.framework/Resources/
Java/ javajdbcadaptor.jar
</snip>
I was then happy to run EOF stuff to my hearts content and avoid
those horrid Java collection classes too.
This example was used in a highly threaded application used to
process images and i didn't run into any problems other than those
of my own doing anyway.
The only gotchas are that you need to make sure that xcode has
the jars specified in the project in order to build, and then for
debugging/running you need to add
<snip>
-cp "EOFImageMunger.jar:/System/Library/Frameworks/
JavaEOControl.framework/Resources/Java/javaeocontrol.jar:/System/
Library/Frameworks/JavaFoundation.framework/Resources/Java/
javafoundation.jar:/System/Library/Frameworks/
JavaEOAccess.framework/ Resources/Java/javaeoaccess.jar:/System/
Library/Frameworks/ JavaXML.framework/Resources/Java/javaxml.jar:/
Library/Frameworks/ LEWOStuff.framework/Resources/Java/
lewostuff.jar:/System/Library/ Frameworks/
JavaJDBCAdaptor.framework/Resources/Java/ javajdbcadaptor.jar:."
</snip>
as a run time argument to the java run target so that every thing
can be found, like wise, this needs to be specified if you are
running from a command line.
I can possibly provide a more complete example, but this should
be enough to get it all running, as it was surprisingly simple
once the class paths were correct.
regards
john.
On 30/01/2006, at 10:24 PM, Ruenagel, Frank wrote:
Hi,
there is a little bit outdated stepwise article about this issue:
http://www.stepwise.com/Articles/Technical/2001-07-01.01.html
It has helped me to create a java console app.
HTH
Frank
-----Original Message-----
From: webobjects-dev-bounces
+webobjects=email@hidden
[mailto:webobjects-dev-bounces+webobjects=symposion.de@lists.a
pple.com]O
n Behalf Of John Huss
Sent: Friday, January 27, 2006 9:35 PM
To: email@hidden
Subject: EnterpriseObjects in a regular Java application
Is it possible to use my EnterpriseObjects classes and
EOModel in a regular
Java application without any web interface?
How do I get a connection to the database and get an editing
context?
My ultimate goal is to write a little command-line program
that will import
text files into a database at scheduled times. If this is a
bad approach
I'm open to other ideas.
Thanks,
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40yakmoose.org.nz
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40icsusa.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden