Re: EnterpriseObjects in a regular Java application
Re: EnterpriseObjects in a regular Java application
- Subject: Re: EnterpriseObjects in a regular Java application
- From: Mike Schrag <email@hidden>
- Date: Mon, 30 Jan 2006 18:24:35 -0500
- Resent-date: Mon, 30 Jan 2006 18:36:08 -0500
- Resent-from: Mike Schrag <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: "email@hidden Apple" <email@hidden>
That NPE is a result of your Main Bundle being null ... If you're not
running inside of a bundle, it falls back to using JavaFoundation as
your bundle (this officially explains why when things get funky
people end up launching JavaFoundation.woa!). Double check that
JavaFoundation is, in fact, in your classpath.
At the top of your main method, add:
System.out.println("Main.main: main bundle = " +
NSBundle.mainBundle());
System.out.println("Main.main: JavaFoundation bundle = " +
NSBundle.bundleForName("JavaFoundation"));
In my main method, this prints out:
Main.main: main bundle = <com.webobjects.foundation.NSBundle
name:'JavaFoundation' bundlePath:'/System/Library/Frameworks/
JavaFoundation.framework' packages:'("com.webobjects.foundation",
"com.webobjects.foundation.xml")' 212 classes >
Main.main: JavaFoundation bundle =
<com.webobjects.foundation.NSBundle name:'JavaFoundation'
bundlePath:'/System/Library/Frameworks/JavaFoundation.framework'
packages:'("com.webobjects.foundation",
"com.webobjects.foundation.xml")' 212 classes >
ms
PS, for eclipse people -- that "Main.main" is a result of a template
I have that's really handy. I call it "sop", and it's defined as
System.out.println("${enclosing_type}.${enclosing_method}: ${cursor}");
So I can type sop<cmd-space> and it will fill in the class and method
name of where the cursor is located. Just spreading the love :)
(apologies if anyone saw this message multi times ... i had to fight
the mailing list max message size a bit because pasting directly from
eclipse apparently pastes huge amounts of markup to preserve the
syntax coloring, etc)
On Jan 30, 2006, at 6:00 PM, John Huss wrote:
Calling EOModelGroup.defaultGroup() causes the exception I listed
below. So apparently I'm missing something.
John
----- Original Message -----
From: Mike Schrag
To: John Huss
Cc: Ruenagel, Frank ; email@hidden
Sent: Monday, January 30, 2006 3:56 PM
Subject: Re: EnterpriseObjects in a regular Java application
It's a lot easier than that .. Here's a little bit of sample code
from a test main method I have:
public static void main(String[] args) throws
MalformedURLException {
EOModelGroup.defaultGroup().addModelWithPathURL(new File
("MyEOModel.eomodeld").toURL());
EOEditingContext ec = new EOEditingContext();
TestEntity te = ...;
ec.saveChanges();
}
classpath contains:
my source
frontbaseplugin.jar
javaeoaccess.jar
javaeocontrol.jar
javafoundation.jar
javajdbcadaptor.jar
javawebobjects.jar
javaxml.jar
ms
On Jan 30, 2006, at 4:46 PM, John Huss wrote:
I'm still having problems with this. It seems to be having
trouble loading Bundles or something.
I tried several different things. The most promising has been the
approach described here:
http://www.wodeveloper.com/omniLists/eof/2002/March/msg00018.html
My code looks like this (Import.java):
public static void main (String args[]) {
try {
JDBCAdaptor adaptor = new JDBCAdaptor("JavaJDBCAdaptor");
EODatabase database = new EODatabase(adaptor);
EODatabaseContext dbContext = new EODatabaseContext(database);
EOObjectStoreCoordinator.defaultCoordinator
().addCooperatingObjectStore(dbContext);
//Using EOModelGroup.defaultGroup() caused an exception (same
one reported below), so I created a new one instead.
EOModelGroup modelGroup = new EOModelGroup();
EOModel model = modelGroup.addModelWithPathURL( new File
("MyModel.eomodeld").toURL() );
adaptor.setConnectionDictionary(model.connectionDictionary());
database.addModel(model);
// this causes an exception
modelGroup.loadAllModelObjects();
} catch (java.net.MalformedURLException e) {
e.printStackTrace();
}
.....
}
When I run it I get this exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at
com.webobjects.eoaccess.EOAdaptor.infoDictionaryForAdaptorNamed
(EOAdaptor.java:238)
at
com.webobjects.eoaccess.EOAdaptor.classNameForAdaptorNamed
(EOAdaptor.java:254)
at com.webobjects.eoaccess.EOAdaptor.classForAdaptorNamed
(EOAdaptor.java:271)
at com.webobjects.eoaccess.EOAdaptor.adaptorWithName
(EOAdaptor.java:295)
at com.webobjects.eoaccess.EOAdaptor.adaptorWithModel
(EOAdaptor.java:325)
at com.webobjects.eoaccess.EOModel.createPrototypeCache
(EOModel.java:610)
at com.webobjects.eoaccess.EOModel.prototypeAttributeNamed
(EOModel.java:652)
at com.webobjects.eoaccess.EOAttribute.<init>
(EOAttribute.java:923)
at com.webobjects.eoaccess.EOEntity.attributes
(EOEntity.java:675)
at com.webobjects.eoaccess.EOEntity._loadEntity
(EOEntity.java:3704)
at com.webobjects.eoaccess.EOModel.loadAllModelObjects
(EOModel.java:1830)
at com.webobjects.eoaccess.EOModelGroup.loadAllModelObjects
(EOModelGroup.java:682)
at SalondataComparisonImport.main(Import.java:23)
Caused by: java.lang.NullPointerException
at
com.webobjects.foundation.NSBundle.LoadUserAndBundleProperties
(NSBundle.java:640)
at com.webobjects.foundation.NSBundle.<clinit>
(NSBundle.java:367)
... 13 more
I've included all the necessary jars I think: EOAccess, EOControl,
JavaFoundation, JavaXML, JDBCAdaptor, FrontBasePlugIn
Any ideas are welcome.
Thanks!
John
----- Original Message -----
From: "Ruenagel, Frank" <email@hidden>
To: "John Huss" <email@hidden>
Cc: <email@hidden>
Sent: Monday, January 30, 2006 3:24 AM
Subject: RE: EnterpriseObjects in a regular Java application
> 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:
40mdimension.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