You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mansour Al Akeel <ma...@gmail.com> on 2014/07/24 23:18:47 UTC

antrun classpath with taskdef

I am running a target in ant. This target depends on external task
from ddlutils.


<profile>
            <id>db</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.
plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>setup-db</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <detail>true</detail>
                            <target name="database-setup"  >
                                <path id="current.classpath">
                                    <path refid="maven.plugin.classpath" />
                                    <path refid="maven.compile.classpath" />
                                    <path refid="maven.runtime.classpath" />
                                </path>
                                <taskdef name="ddlToDatabase"
classname="org.apache.ddlutils.task.DdlToDatabaseTask"
classpathref="current.classpath">
                                    <!-- <classpath
refid="current.classpath" /> -->
                                </taskdef>
                                <property name="current_classpath"
refid="current.classpath" />
                                <!-- <pathconvert
pathsep="${line.separator}| |..... " property="formatted.classpath"
refid="current.classpath"  /> -->
                                <ddlToDatabase>
                                    <database
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost/test" username="postgres"
password="postgres" />
                                    <fileset dir="src/sql/">
                                        <include name="schema.xml" />
                                    </fileset>
                                    <createDatabase failonerror="true" />
                                    <writeSchemaToDatabase />
                                </ddlToDatabase>
                            </target>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.ddlutils</groupId>
                                <artifactId>ddlutils</artifactId>
                                <version>1.0</version>
                            </dependency>
                            <dependency>
                                <groupId>log4j</groupId>
                                <artifactId>log4j</artifactId>
                                <version>1.2.17</version>
                            </dependency>
                            <!-- <dependency> -->
                            <!-- <groupId>org.postgresql</groupId> -->
                            <!-- <artifactId>postgresql</artifactId> -->
                            <!-- <version>9.3-1100-jdbc41</version> -->
                            <!-- </dependency> -->
                        </dependencies>
                    </plugin>


The task creates a jdbc connection to load data into a DB. The
connection needs the JDBC driver.
If I add the driver to the <dependencies> section, everything works
fine. However, the dependency on the driver is declared somewhere else
(in the global dependencies), and this driver may change depending on
the DB. Therefore we don't want to declare it twice. The option we
have is to use "maven.compile.classpath". However, for some reason, I
am getting an  exception about the driver class not found:

Caused by: org.apache.ddlutils.DatabaseOperationException: Error while
trying to create a database: org.postgresql.Driver
        at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createOrDropDatabase(PostgreSqlPlatform.java:164)
        at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createDatabase(PostgreSqlPlatform.java:201)
        at org.apache.ddlutils.task.CreateDatabaseCommand.execute(CreateDatabaseCommand.java:80)
        ... 35 more
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:188)
        at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createOrDropDatabase(PostgreSqlPlatform.java:155)
        ... 37 more


To troubleshoot the issue, I printed out the classpath ref
"current.classpath", and the driver jar was there, and can be seen as
the last dependency in the output !


Setting project property:
maven.dependency.org.apache.portals.bridges.portals-bridges-common.jar.path
-> /home/mansour/.m2/repository/org/apache/portals/bridges/portals-bridges-common/2.0/portals-bridges-common-2.0.jar
Setting project property:
maven.dependency.org.apache.portals.applications.apa-logging.jar.path
-> /home/mansour/.m2/repository/org/apache/portals/applications/apa-logging/1.0/apa-logging-1.0.jar
Setting project property:
maven.dependency.org.postgresql.postgresql.jar.path ->
/home/mansour/.m2/repository/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar
[INFO] Executing tasks Build sequence for target(s) `database-setup'
is [database-setup]
Complete build sequence is [database-setup, ]

database-setup:
Adding reference: current.classpath
Class org.apache.ddlutils.task.DdlToDatabaseTask loaded from parent
loader (parentFirst)
 +Datatype ddlToDatabase org.apache.ddlutils.task.DdlToDatabaseTask
Setting project property: current_classpath ->
/home/mansour/.m2/repository/org/apache/maven/plugins/maven-antrun-plugin/1.7/maven-antrun-plugin-1.7.jar:
........:
/home/mansour/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.3.2/jackson-mapper-asl-1.3.2.jar:/home/mansour/.m2/repository/org/codehaus/jackson/jackson-xc/1.3.2/jackson-xc-1.3.2.jar:/home/mansour/.m2/repository/org/slf4j/slf4j-log4j12/1.6.6/slf4j-log4j12-1.6.6.jar:/home/mansour/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.4/jcl-over-slf4j-1.7.4.jar:/home/mansour/.m2/repository/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar


Is there something wrong I am doing, that is preventing antrun taskdef
from using the current.classpath ref ??

Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: antrun classpath with taskdef

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 24/07/2014 5:52 PM, Mansour Al Akeel wrote:
> Let me make sure I understand what you suggest.
>
> You are suggesting to add all available JDBC drivers to the plugin
> dependencies list. This should solve the problem.

It also allows the system administrator to select the database at 
installation or  run-time rather than have to build a bunch of separate 
installation packages.
> It might be a work around, but wondering if there's a solution that
> allows me to access maven pom dependencies from taskdef, for the
> future as well.
If you use an installer, you could make the jars part of package options 
that could be selected during the installation.
> Please note that ddlutils needs log4j. log4j is included in the pom
> dependencies as well.
>
>
>
> On Thu, Jul 24, 2014 at 5:32 PM, Ron Wheeler
> <rw...@artifact-software.com> wrote:
>> Can you not just add all database drivers and have any of them available at
>> run-time?
>>
>> Ron
>>
>>
>>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: antrun classpath with taskdef

Posted by Mansour Al Akeel <ma...@gmail.com>.
Let me make sure I understand what you suggest.

You are suggesting to add all available JDBC drivers to the plugin
dependencies list. This should solve the problem.
It might be a work around, but wondering if there's a solution that
allows me to access maven pom dependencies from taskdef, for the
future as well.

Please note that ddlutils needs log4j. log4j is included in the pom
dependencies as well.



On Thu, Jul 24, 2014 at 5:32 PM, Ron Wheeler
<rw...@artifact-software.com> wrote:
> Can you not just add all database drivers and have any of them available at
> run-time?
>
> Ron
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: antrun classpath with taskdef

Posted by Ron Wheeler <rw...@artifact-software.com>.
Can you not just add all database drivers and have any of them available 
at run-time?

Ron


On 24/07/2014 5:18 PM, Mansour Al Akeel wrote:
> I am running a target in ant. This target depends on external task
> from ddlutils.
>
>
> <profile>
>              <id>db</id>
>              <build>
>                  <plugins>
>                      <plugin>
>                          <groupId>org.apache.maven.
> plugins</groupId>
>                          <artifactId>maven-antrun-plugin</artifactId>
>                          <version>1.7</version>
>                          <executions>
>                              <execution>
>                                  <id>setup-db</id>
>                                  <phase>process-resources</phase>
>                                  <goals>
>                                      <goal>run</goal>
>                                  </goals>
>                              </execution>
>                          </executions>
>                          <configuration>
>                              <detail>true</detail>
>                              <target name="database-setup"  >
>                                  <path id="current.classpath">
>                                      <path refid="maven.plugin.classpath" />
>                                      <path refid="maven.compile.classpath" />
>                                      <path refid="maven.runtime.classpath" />
>                                  </path>
>                                  <taskdef name="ddlToDatabase"
> classname="org.apache.ddlutils.task.DdlToDatabaseTask"
> classpathref="current.classpath">
>                                      <!-- <classpath
> refid="current.classpath" /> -->
>                                  </taskdef>
>                                  <property name="current_classpath"
> refid="current.classpath" />
>                                  <!-- <pathconvert
> pathsep="${line.separator}| |..... " property="formatted.classpath"
> refid="current.classpath"  /> -->
>                                  <ddlToDatabase>
>                                      <database
> driverClassName="org.postgresql.Driver"
> url="jdbc:postgresql://localhost/test" username="postgres"
> password="postgres" />
>                                      <fileset dir="src/sql/">
>                                          <include name="schema.xml" />
>                                      </fileset>
>                                      <createDatabase failonerror="true" />
>                                      <writeSchemaToDatabase />
>                                  </ddlToDatabase>
>                              </target>
>                          </configuration>
>                          <dependencies>
>                              <dependency>
>                                  <groupId>org.apache.ddlutils</groupId>
>                                  <artifactId>ddlutils</artifactId>
>                                  <version>1.0</version>
>                              </dependency>
>                              <dependency>
>                                  <groupId>log4j</groupId>
>                                  <artifactId>log4j</artifactId>
>                                  <version>1.2.17</version>
>                              </dependency>
>                              <!-- <dependency> -->
>                              <!-- <groupId>org.postgresql</groupId> -->
>                              <!-- <artifactId>postgresql</artifactId> -->
>                              <!-- <version>9.3-1100-jdbc41</version> -->
>                              <!-- </dependency> -->
>                          </dependencies>
>                      </plugin>
>
>
> The task creates a jdbc connection to load data into a DB. The
> connection needs the JDBC driver.
> If I add the driver to the <dependencies> section, everything works
> fine. However, the dependency on the driver is declared somewhere else
> (in the global dependencies), and this driver may change depending on
> the DB. Therefore we don't want to declare it twice. The option we
> have is to use "maven.compile.classpath". However, for some reason, I
> am getting an  exception about the driver class not found:
>
> Caused by: org.apache.ddlutils.DatabaseOperationException: Error while
> trying to create a database: org.postgresql.Driver
>          at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createOrDropDatabase(PostgreSqlPlatform.java:164)
>          at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createDatabase(PostgreSqlPlatform.java:201)
>          at org.apache.ddlutils.task.CreateDatabaseCommand.execute(CreateDatabaseCommand.java:80)
>          ... 35 more
> Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
>          at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
>          at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
>          at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
>          at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
>          at java.lang.Class.forName0(Native Method)
>          at java.lang.Class.forName(Class.java:188)
>          at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.createOrDropDatabase(PostgreSqlPlatform.java:155)
>          ... 37 more
>
>
> To troubleshoot the issue, I printed out the classpath ref
> "current.classpath", and the driver jar was there, and can be seen as
> the last dependency in the output !
>
>
> Setting project property:
> maven.dependency.org.apache.portals.bridges.portals-bridges-common.jar.path
> -> /home/mansour/.m2/repository/org/apache/portals/bridges/portals-bridges-common/2.0/portals-bridges-common-2.0.jar
> Setting project property:
> maven.dependency.org.apache.portals.applications.apa-logging.jar.path
> -> /home/mansour/.m2/repository/org/apache/portals/applications/apa-logging/1.0/apa-logging-1.0.jar
> Setting project property:
> maven.dependency.org.postgresql.postgresql.jar.path ->
> /home/mansour/.m2/repository/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar
> [INFO] Executing tasks Build sequence for target(s) `database-setup'
> is [database-setup]
> Complete build sequence is [database-setup, ]
>
> database-setup:
> Adding reference: current.classpath
> Class org.apache.ddlutils.task.DdlToDatabaseTask loaded from parent
> loader (parentFirst)
>   +Datatype ddlToDatabase org.apache.ddlutils.task.DdlToDatabaseTask
> Setting project property: current_classpath ->
> /home/mansour/.m2/repository/org/apache/maven/plugins/maven-antrun-plugin/1.7/maven-antrun-plugin-1.7.jar:
> ........:
> /home/mansour/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.3.2/jackson-mapper-asl-1.3.2.jar:/home/mansour/.m2/repository/org/codehaus/jackson/jackson-xc/1.3.2/jackson-xc-1.3.2.jar:/home/mansour/.m2/repository/org/slf4j/slf4j-log4j12/1.6.6/slf4j-log4j12-1.6.6.jar:/home/mansour/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.4/jcl-over-slf4j-1.7.4.jar:/home/mansour/.m2/repository/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar
>
>
> Is there something wrong I am doing, that is preventing antrun taskdef
> from using the current.classpath ref ??
>
> Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org