SchemaExport task in IDEA's Ant and relative bean paths - how do you do it?

I've tried to raise this issue in the past, but maybe I should have first asked the
folks here on the EAP:

I've got a project with Hibernate which uses an XML configuration file which in turn
includes bean mapping files. This is using the mapping construct (]]>) .
The mapping files themselves are in a subdirectory relative to the
Hibernate configuration file as follows:

...
]]>


When running the SchemaExport task on the command line, the task completes
successfully, which indicates, to me at least, that all the paths are set correctly
and somehow, importing these relative resources can be done.

When run from IDEA (by executing the target in an, I keep getting exceptions that state that the mapped resource files
cannot be found (well, really only the first one in the list, but the building process
stops then.)

The question I wanted to ask was: is there someone among you that has a similar
setup and have you been able to configure the Ant build file within IDEA such that
this error does not come up? It is really annoying to have to go to the command line every time the schema changes...
I suspect that the issue is related to the different class loaders used by IDEA's
ant launcher and the one run from the command line.

Any help would be appreciated.

Cheers,

Bonny

0

Hello Bonny,

You need to make sure that "hibernate" directory (with *.hbm.xml) is in the
classpath. In IDEA editing Additional Classpath setting of build file can
help.

I've tried to raise this issue in the past, but maybe I should have
first asked the folks here on the EAP:

I've got a project with Hibernate which uses an XML configuration file
which in turn
includes bean mapping files. This is using the mapping construct
(<mapping resource=...>) .
The mapping files themselves are in a subdirectory relative to the
Hibernate configuration file as follows:

 root
> +--build.xml
> +--etc
> +-- hibernate.cfg.xml
> +-- hibernate
> +-- bean1.hbm.xml
> +-- bean2.hbm.xml
> +-- ...
> and a snippet from the configuration file:
> ..
> 
> ..
> ]]>


When running the SchemaExport task on the command line, the task
completes successfully, which indicates, to me at least, that all the
paths are set correctly and somehow, importing these relative
resources can be done.

When run from IDEA (by executing the target in an, I keep getting
exceptions that state that the mapped resource files cannot be found
(well, really only the first one in the list, but the building process
stops then.)

The question I wanted to ask was: is there someone among you that has
a similar

setup and have you been able to configure the Ant build file within
IDEA such that

this error does not come up? It is really annoying to have to go to
the command line every time the schema changes...

I suspect that the issue is related to the different class loaders
used by IDEA's

ant launcher and the one run from the command line.

Any help would be appreciated.

Cheers,

Bonny

Alexander.


0

Alexander,

Given the directory structre, do you refer to the configuratin directory ('etc'?),
or the child directory ('hibernate'?). Or both?

The 'etc' directory is on the class path as it is defined as a source in the project.
given that, I would have expected this to work. Also, the ant build file itself
defines all the paths in the taskdef for the SchemaExport task.

Cheers,

Bonny

I have got it to work when I explicitly added the class path of both the xml files and the bean classes themselves.
It seems that the class path given to the task is exactly
the path specified in the 'Additional Class Path' and there
is no reference to all the paths that are defimed as part of the module definition. Is this correct? If so, why is this the case? Why isn't the 'Additional' class path being
added to the module/project class path?

Message was edited by: Bonny
Bonny Rais

0

Hello Bonny,

So, we have:
etc/hibernate.cfg.xml
etc/hibernate/mapping.hbm.xml.

hibernate.cfg.xml refers to mapping so: In IDEA project I have defined "etc" as source root, plus source root for java classes. After compilation .class and .xml files go to output folder (say, path-to-project/classes/production/mymodule/). The task in ant file: ]]>

Plus I have added path-to-project/classes/production/mymodule/ as additional
classpath for this ant in IDEA.

It successfully generates sample.sql.

Alexander,

Given the directory structre, do you refer to the configuratin
directory ('etc'?), or the child directory ('hibernate'?). Or both?

The 'etc' directory is on the class path as it is defined as a source
in the project. given that, I would have expected this to work. Also,
the ant build file itself defines all the paths in the taskdef for the
SchemaExport task.

Cheers,

Bonny

Alexander.


0

Hello Bonny,

So, we have:
etc/hibernate.cfg.xml
etc/hibernate/mapping.hbm.xml.

hibernate.cfg.xml refers to mapping so: <mapping
resource="hibernate/mapping.hbm.xml"/>

In IDEA project I have defined "etc" as source root,
plus source root for
java classes. After compilation .class and .xml files
go to output folder
(say, path-to-project/classes/production/mymodule/).

The task in ant file:
<schemaexport config="./etc/hibernate.cfg.xml"
quiet="no" text="no" drop="no"
delimiter=";" output="./sample.sql"/>


So far this is the same for me, and in addition, the task's class path includes
all the necessary paths (to class and mapping files)


Plus I have added
path-to-project/classes/production/mymodule/ as
additional
classpath for this ant in IDEA.


This is the bit I do not understand: If the Ant build file contains all these
paths so that as a standalone build this works, and if the project/module
files contain references to all the relevant paths in the project so that builds
and other tasks are successful in IDEA, why do I have to add explicit paths
once again to the ant file in IDEA - shouldn't the ant support either pick these
paths from the paths defined in the build file or the paths defined for the module?


Cheers,

Bonny

0

Hi,

This is the bit I do not understand: If the Ant build file contains
all these
paths so that as a standalone build this works,


I tried a bit different case. I run standalone Ant with -cp option, and passed
the path to compiler output. This was in fact the analogue to "Additional
classpath" IDEA setting. Is there a way to specify classpath for schema export
via ant tasks?

Alexander.


0

Hi,


I tried a bit different case. I run standalone Ant
with -cp option, and passed
the path to compiler output. This was in fact the
analogue to "Additional
classpath" IDEA setting. Is there a way to specify
classpath for schema export
via ant tasks?

Alexander.


Yes, and by specifying this in the ]]> part of the build file - you can pass
the necessary class path to the task to ensure is completes successfully. In my
case, this is where I provide all the jars (including hibernate), the path to the
classes (from the project) and the paths to the XML files as needed. That is why
I am surprised that when running in IDEA, this does not work - the standalone
version is providing all these elements of the class path to the task. Maybe someone
from JB would care to comment on this.

In the meantime, I had to add explicitly all these paths to the buildfile additional
class paths, which is rather annoying since it's redundant and manual and another
step to forget.

Cheers,

Bonny

0

Hi,

>> I tried a bit different case. I run standalone Ant
>> with -cp option, and passed
>> the path to compiler output. This was in fact the
>> analogue to "Additional
>> classpath" IDEA setting. Is there a way to specify
>> classpath for schema export
>> via ant tasks?
>> Alexander.
>>

Yes, and by specifying this in the <taskdef> part of the build file -
you can pass
the necessary class path to the task to ensure is completes
successfully. In my
case, this is where I provide all the jars (including hibernate), the
path to the
classes (from the project) and the paths to the XML files as needed.


Ok, now I see. But this works in Selena 7096. My taskdef is:
]]>
And this works without additional classpath.

Alexander.


0

Alexander,

This must have beed a fix in B7096 then and that's great news. I'll try it now.

Cheers,

Bonny

0

请先登录再写评论。