emacarron / old-google-code-issues

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

"Cannot instantiate object of type..." error generating my plugin #343

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
1.3.1
Please describe the problem.  Unit tests are best!
I developed my plugin extended mybatis generator PluginAdapter. 
1.- I created a maven plugin called myBatisGeneratorTest
2.- I created a maven project with my plugin called 
es.vass.mbg.plugin.MyMapperConfigPlugin
3.- I added the maven project (2) as a maven dependency in the maven plugin (1).
4.- I have the following log:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building myBatisGeneratorTest Maven Plugin 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-plugin-plugin:2.5.1:helpmojo (generated-helpmojo) @ 
myBatisGeneratorTest ---
[INFO] Using 'UTF-8' encoding to read mojo metadata.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 1 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.3.1:generate (Generate MyBatis 
Artifacts) @ myBatisGeneratorTest ---
java.lang.RuntimeException: Cannot instantiate object of type 
es.vass.mbg.plugin.MyMapperConfigPlugin
    at org.mybatis.generator.internal.ObjectFactory.createInternalObject(ObjectFactory.java:137)
    at org.mybatis.generator.internal.ObjectFactory.createPlugin(ObjectFactory.java:174)
    at org.mybatis.generator.config.Context.generateFiles(Context.java:463)
    at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:233)
    at org.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:184)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.ClassNotFoundException: 
es.vass.mbg.plugin.MyMapperConfigPlugin
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.mybatis.generator.internal.ObjectFactory.internalClassForName(ObjectFactory.java:123)
    at org.mybatis.generator.internal.ObjectFactory.createInternalObject(ObjectFactory.java:133)
    ... 25 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.408s
[INFO] Finished at: Mon Jun 13 18:02:48 CEST 2011
[INFO] Final Memory: 6M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal 
org.mybatis.generator:mybatis-generator-maven-plugin:1.3.1:generate (Generate 
MyBatis Artifacts) on project myBatisGeneratorTest: Cannot instantiate object 
of type es.vass.mbg.plugin.MyMapperConfigPlugin -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e 
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please 
read the following articles:
[ERROR] [Help 1] 
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

What is the expected output? What do you see instead?

The maven plugin have a class that generate a "MyMapperConfig.xml". But when i 
generate the sources gave me that error.  

Please provide any additional information below.

I work on eclipse helios 3.6 and generated the sources with the m2 plugin for 
eclipse. Hope answer soon. 

Jorge

Original issue reported on code.google.com by jorge.z...@gmail.com on 13 Jun 2011 at 4:20

GoogleCodeExporter commented 9 years ago

Original comment by jeffgbut...@gmail.com on 29 Aug 2011 at 1:26

GoogleCodeExporter commented 9 years ago
I just did a test and don't experience any errors.  The important thing is to 
make sure that the project containing your MyBatis plugin is declared as a 
dependency of the generator plugin - not just a dependency of the project:

    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.1</version>
        <executions>
          <execution>
            <id>Generate MyBatis Artifacts</id>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
            ...
        </configuration>
        <dependencies>
          <!-- declare your dependency here -->
          <dependency>
            <groupId>foo.bar</groupId>
            <artifactId>MyPlugin</artifactId>
            <version>1.0.0</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>

Original comment by jeffgbut...@gmail.com on 14 Sep 2011 at 1:38

GoogleCodeExporter commented 9 years ago
Closing as invalid.  Feel free to ask further questions on the user list.

Original comment by jeffgbut...@gmail.com on 14 Sep 2011 at 3:22

GoogleCodeExporter commented 9 years ago
Hi ,

I have the same question about this.please help me and verify it ,thanks.

when I use maven install command in eclipse ,there has an error like this:
---------------------------------------------------------------------------
Build errors for spring-mybatis-generator; 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal 
org.mybatis.generator:mybatis-generator-maven-plugin:1.3.1:generate (Generate 
MyBatis Artifacts) on project spring-mybatis-generator: Cannot instantiate 
object of type com.test.spring.mybatis.generator.plugins.TestPlugins
----------------------------------------------------------------------------
TestPlugins was write by myself and configuration like this :
=====================================================================
<context id="mysqlGenerator" targetRuntime="MyBatis3">  

             <plugin type="com.test.spring.mybatis.generator.plugins.TestPlugins"></plugin>              

=====================================================================

I don't know how to resolve it,Please help me. thanks

Original comment by zhoujian...@gmail.com on 5 Jan 2012 at 9:03

GoogleCodeExporter commented 9 years ago
the  same  problem...plz get me some  advice...many thanks
.

Original comment by kasa.l...@gmail.com on 10 Jan 2012 at 9:38

GoogleCodeExporter commented 9 years ago
My advice is to follow the instructions in comment #2 above.

Original comment by jeffgbut...@gmail.com on 10 Jan 2012 at 11:25

GoogleCodeExporter commented 9 years ago
to jeffgbut...@gmail.com :
 <!-- declare your dependency here -->
          <dependency>
            <groupId>foo.bar</groupId>
            <artifactId>MyPlugin</artifactId>
            <version>1.0.0</version>
          </dependency>
What did u mean? if my defined plugin is 
"es.vass.mbg.plugin.MyMapperConfigPlugin"? How to declear it in the pom.xml?

Original comment by hillfall...@gmail.com on 27 Feb 2012 at 7:17

GoogleCodeExporter commented 9 years ago
Your plugin needs to be packaged as a JAR and be made available in your local 
maven repository.  Then you need to declare that JAR as a dependency as shown 
in comment #2.

Original comment by jeffgbut...@gmail.com on 27 Feb 2012 at 2:15