You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Adrian Herscu <bm...@fastmail.fm> on 2008/03/05 21:55:36 UTC

[m2] compiling a generic method with maven fails

Hi all,

I have this generic method which compiles fine under Eclipse 3.3:

public abstract class AbstractApplication<M extends AbstractModel, V 
extends AbstractView, C extends AbstractControl> {
     ...
     private V getViewFor(final Class<? extends V> viewClass) {
         class InternalRunnable
                 implements Runnable {
             private V frame;

             public void run() {
                 try {
                     frame = viewClass.newInstance();
                     frame
                         .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                     frame.setVisible(true);
                 } catch (final InstantiationException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                 } catch (final IllegalAccessException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                 }
             }
         }
     ...
}

And the code runs OK on the Sun JRE 6.0.

Now, I discovered that under Maven 2 with the following 
maven-compiler-plugin configuration:
         <configuration>
           <source>1.6</source>
           <target>1.6</target>
         </configuration>

the build fails with the following compilation error:

[INFO] Compilation failure
C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible 
types
found   : org.wirexn.sandbox.wsgui.view.AbstractView
required: V



C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible 
types
found   : org.wirexn.sandbox.wsgui.view.AbstractView
required: V

Any suggestions?

Thanks in advance,
Adrian.


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


Re: [m2] compiling a generic method with maven fails

Posted by Wayne Fay <wa...@gmail.com>.
We regularly see people on this list complaining that things compile
in Eclipse but not with Maven (or vice versa). Eventually it comes
down to differences in JDT and javac. That's why I asked what I did...

Wayne

On 3/5/08, Adrian Herscu <bm...@fastmail.fm> wrote:
> Checked the eclipse.tools.jdt newsgroup; seems that there are many more
> inconsistencies like these between the JDT compiler and javac, all of
> those which I saw are regarded to generics.
> Adrian.
> P.S. And there is no switch in Eclipse to make it compile with javac,
> except making it create and ANT build file.
>
> Adrian Herscu wrote:
> > I thought about this... Problem is, that there are more than ten
> > dependencies and the sources are stored into three different
> > directories... Configuring javac for this, seems like a nightmare!
> >
> > I have changed the return type of the method from V to AbstractView,
> > added a cast to V somewhere, and that solved the problem with Maven.
> > Knew that these generics are more trouble than worth!
> >
> > Is there some switch in Eclipse to make it compile with javac?
> >
> > Wayne Fay wrote:
> >> Can you try compiling with the Sun JDK 1.6 directly eg javac ...?
> >>
> >> Wayne
> >>
> >> On 3/5/08, Adrian Herscu <bm...@fastmail.fm> wrote:
> >>> Hi all,
> >>>
> >>> I have this generic method which compiles fine under Eclipse 3.3:
> >>>
> >>> public abstract class AbstractApplication<M extends AbstractModel, V
> >>> extends AbstractView, C extends AbstractControl> {
> >>>     ...
> >>>     private V getViewFor(final Class<? extends V> viewClass) {
> >>>         class InternalRunnable
> >>>                 implements Runnable {
> >>>             private V frame;
> >>>
> >>>             public void run() {
> >>>                 try {
> >>>                     frame = viewClass.newInstance();
> >>>                     frame
> >>>                         .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> >>>                     frame.setVisible(true);
> >>>                 } catch (final InstantiationException e) {
> >>>                     // TODO Auto-generated catch block
> >>>                     e.printStackTrace();
> >>>                 } catch (final IllegalAccessException e) {
> >>>                     // TODO Auto-generated catch block
> >>>                     e.printStackTrace();
> >>>                 }
> >>>             }
> >>>         }
> >>>     ...
> >>> }
> >>>
> >>> And the code runs OK on the Sun JRE 6.0.
> >>>
> >>> Now, I discovered that under Maven 2 with the following
> >>> maven-compiler-plugin configuration:
> >>>         <configuration>
> >>>           <source>1.6</source>
> >>>           <target>1.6</target>
> >>>         </configuration>
> >>>
> >>> the build fails with the following compilation error:
> >>>
> >>> [INFO] Compilation failure
> >>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
> >>>
> >>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
> >>> types
> >>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
> >>> required: V
> >>>
> >>>
> >>>
> >>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
> >>>
> >>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
> >>> types
> >>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
> >>> required: V
> >>>
> >>> Any suggestions?
> >>>
> >>> Thanks in advance,
> >>> Adrian.
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>> For additional commands, e-mail: users-help@maven.apache.org
> >>>
> >>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: [m2] compiling a generic method with maven fails

Posted by Adrian Herscu <bm...@fastmail.fm>.
Checked the eclipse.tools.jdt newsgroup; seems that there are many more 
inconsistencies like these between the JDT compiler and javac, all of 
those which I saw are regarded to generics.
Adrian.
P.S. And there is no switch in Eclipse to make it compile with javac, 
except making it create and ANT build file.

Adrian Herscu wrote:
> I thought about this... Problem is, that there are more than ten 
> dependencies and the sources are stored into three different 
> directories... Configuring javac for this, seems like a nightmare!
> 
> I have changed the return type of the method from V to AbstractView, 
> added a cast to V somewhere, and that solved the problem with Maven. 
> Knew that these generics are more trouble than worth!
> 
> Is there some switch in Eclipse to make it compile with javac?
> 
> Wayne Fay wrote:
>> Can you try compiling with the Sun JDK 1.6 directly eg javac ...?
>>
>> Wayne
>>
>> On 3/5/08, Adrian Herscu <bm...@fastmail.fm> wrote:
>>> Hi all,
>>>
>>> I have this generic method which compiles fine under Eclipse 3.3:
>>>
>>> public abstract class AbstractApplication<M extends AbstractModel, V
>>> extends AbstractView, C extends AbstractControl> {
>>>     ...
>>>     private V getViewFor(final Class<? extends V> viewClass) {
>>>         class InternalRunnable
>>>                 implements Runnable {
>>>             private V frame;
>>>
>>>             public void run() {
>>>                 try {
>>>                     frame = viewClass.newInstance();
>>>                     frame
>>>                         .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>>                     frame.setVisible(true);
>>>                 } catch (final InstantiationException e) {
>>>                     // TODO Auto-generated catch block
>>>                     e.printStackTrace();
>>>                 } catch (final IllegalAccessException e) {
>>>                     // TODO Auto-generated catch block
>>>                     e.printStackTrace();
>>>                 }
>>>             }
>>>         }
>>>     ...
>>> }
>>>
>>> And the code runs OK on the Sun JRE 6.0.
>>>
>>> Now, I discovered that under Maven 2 with the following
>>> maven-compiler-plugin configuration:
>>>         <configuration>
>>>           <source>1.6</source>
>>>           <target>1.6</target>
>>>         </configuration>
>>>
>>> the build fails with the following compilation error:
>>>
>>> [INFO] Compilation failure
>>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\ 
>>>
>>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
>>> types
>>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
>>> required: V
>>>
>>>
>>>
>>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\ 
>>>
>>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
>>> types
>>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
>>> required: V
>>>
>>> Any suggestions?
>>>
>>> Thanks in advance,
>>> Adrian.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>


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


Re: [m2] compiling a generic method with maven fails

Posted by Adrian Herscu <bm...@fastmail.fm>.
I thought about this... Problem is, that there are more than ten 
dependencies and the sources are stored into three different 
directories... Configuring javac for this, seems like a nightmare!

I have changed the return type of the method from V to AbstractView, 
added a cast to V somewhere, and that solved the problem with Maven. 
Knew that these generics are more trouble than worth!

Is there some switch in Eclipse to make it compile with javac?

Wayne Fay wrote:
> Can you try compiling with the Sun JDK 1.6 directly eg javac ...?
> 
> Wayne
> 
> On 3/5/08, Adrian Herscu <bm...@fastmail.fm> wrote:
>> Hi all,
>>
>> I have this generic method which compiles fine under Eclipse 3.3:
>>
>> public abstract class AbstractApplication<M extends AbstractModel, V
>> extends AbstractView, C extends AbstractControl> {
>>     ...
>>     private V getViewFor(final Class<? extends V> viewClass) {
>>         class InternalRunnable
>>                 implements Runnable {
>>             private V frame;
>>
>>             public void run() {
>>                 try {
>>                     frame = viewClass.newInstance();
>>                     frame
>>                         .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>                     frame.setVisible(true);
>>                 } catch (final InstantiationException e) {
>>                     // TODO Auto-generated catch block
>>                     e.printStackTrace();
>>                 } catch (final IllegalAccessException e) {
>>                     // TODO Auto-generated catch block
>>                     e.printStackTrace();
>>                 }
>>             }
>>         }
>>     ...
>> }
>>
>> And the code runs OK on the Sun JRE 6.0.
>>
>> Now, I discovered that under Maven 2 with the following
>> maven-compiler-plugin configuration:
>>         <configuration>
>>           <source>1.6</source>
>>           <target>1.6</target>
>>         </configuration>
>>
>> the build fails with the following compilation error:
>>
>> [INFO] Compilation failure
>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
>> types
>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
>> required: V
>>
>>
>>
>> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
>> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
>> types
>> found   : org.wirexn.sandbox.wsgui.view.AbstractView
>> required: V
>>
>> Any suggestions?
>>
>> Thanks in advance,
>> Adrian.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>


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


Re: [m2] compiling a generic method with maven fails

Posted by Wayne Fay <wa...@gmail.com>.
Can you try compiling with the Sun JDK 1.6 directly eg javac ...?

Wayne

On 3/5/08, Adrian Herscu <bm...@fastmail.fm> wrote:
> Hi all,
>
> I have this generic method which compiles fine under Eclipse 3.3:
>
> public abstract class AbstractApplication<M extends AbstractModel, V
> extends AbstractView, C extends AbstractControl> {
>     ...
>     private V getViewFor(final Class<? extends V> viewClass) {
>         class InternalRunnable
>                 implements Runnable {
>             private V frame;
>
>             public void run() {
>                 try {
>                     frame = viewClass.newInstance();
>                     frame
>                         .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>                     frame.setVisible(true);
>                 } catch (final InstantiationException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 } catch (final IllegalAccessException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 }
>             }
>         }
>     ...
> }
>
> And the code runs OK on the Sun JRE 6.0.
>
> Now, I discovered that under Maven 2 with the following
> maven-compiler-plugin configuration:
>         <configuration>
>           <source>1.6</source>
>           <target>1.6</target>
>         </configuration>
>
> the build fails with the following compilation error:
>
> [INFO] Compilation failure
> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
> types
> found   : org.wirexn.sandbox.wsgui.view.AbstractView
> required: V
>
>
>
> C:\documents\pm\project-trunks\wirexn\sandbox\swing-client-sample\src\main\java\
> org\wirexn\sandbox\wsgui\AbstractApplication.java:[103,23] incompatible
> types
> found   : org.wirexn.sandbox.wsgui.view.AbstractView
> required: V
>
> Any suggestions?
>
> Thanks in advance,
> Adrian.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: [m2] compiling a generic method with maven fails

Posted by Adrian Herscu <bm...@fastmail.fm>.
VUB Stefan Seidel wrote:
>>
>> Now, I discovered that under Maven 2 with the following 
>> maven-compiler-plugin configuration:
>>         <configuration>
>>           <source>1.6</source>
>>           <target>1.6</target>
>>         </configuration>
>>
> Add <fork>true</fork>
> 
> Stefan


Why should that work?
Adrian.


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


Re: [m2] compiling a generic method with maven fails

Posted by VUB Stefan Seidel <ss...@vub.de>.
> 
> Now, I discovered that under Maven 2 with the following 
> maven-compiler-plugin configuration:
>         <configuration>
>           <source>1.6</source>
>           <target>1.6</target>
>         </configuration>
> 
Add <fork>true</fork>

Stefan

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