Question

I am using Google Gin for generating an Event in my GWT project like this:

package com.lokur.motd.client.events;

import com.gwtplatform.dispatch.annotation.GenEvent;

@GenEvent
public class EditorChange {
}

Now, when I compile my project with "mvn clean install -e", it generates required classes viz. EditorChangeEvent.class, EditorChangeEvent$EditorChangeHandler.class, EditorChangeEvent$HasEditorChangeHandlers.class in the target folder of my project.

But, when I try accessing particular generated class e.g. EditorChangeEvent in my project, it gives me compilation error with message:

"package com.lokur.motd.client.events.EditorChangeEvent does not exist"

...

I don't understand this behavior. Do we need to explicitly add "target" folder of Maven in class-path or somewhere in the pom.xml or something else is causing this?

Here are the plug-ins from maven pom.xml:

<plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>gwt-maven-plugin</artifactId>
                        <version>${gwt.plugin.version}</version>
                        <configuration>
                            <runTarget>myMessage/myMessage.html</runTarget>
                            <disableCastChecking>true</disableCastChecking>
                            <disableClassMetadata>true</disableClassMetadata>
                            <!-- <logLevel>INFO" -bindAddress 0.0.0.0 -logLevel "INFO</logLevel> -->
                            <logLevel>ERROR</logLevel>
                            <style>OBF</style>
                            <!-- OBF, PRETTY, DETAILED -->
                            <noServer>false</noServer>
                            <additionalPageParameters>log_level=OFF</additionalPageParameters>
                            <extraJvmArgs>-Xmx512m -Ddev.mode=true -DuseCache=false</extraJvmArgs>
                            <extraTestArgs>-Xmx512m -Ddev.mode=true</extraTestArgs>
                            <gwtVersion>${gwtVersion}</gwtVersion>
                            <testFilter>*</testFilter>
                            <hostedWebapp>
                                ${project.build.directory}/${project.build.finalName}
                            </hostedWebapp>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>compile</goal>
                                    <goal>test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>Unzip usp Config &amp; Env Modules</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.dig.configs</groupId>
                                            <artifactId>common-configs</artifactId>
                                            <version>${commonConfigs.version}</version>
                                            <type>zip</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${basedir}/target/tmp</outputDirectory>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>${pom.groupId}</groupId>
                                            <artifactId>usp-env</artifactId>
                                            <version>${pom.version}</version>
                                            <type>zip</type>
                                            <outputDirectory>${basedir}/target/tmp</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>Copy Config, Env Modules</id>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <tasks>
                                        <copy todir="${basedir}/target/myMessage/WEB-INF/classes/config" overwrite="true" verbose="true" failonerror="true">
                                            <fileset dir="${basedir}/target/tmp/config">
                                                <include name="**" />
                                            </fileset>
                                            <fileset dir="${basedir}/target/tmp/env">
                                                <include name="**" />
                                            </fileset>
                                        </copy>
                                        <copy todir="${basedir}/target/myMessage/WEB-INF/classes/config" overwrite="true" verbose="true" failonerror="true">
                                            <fileset dir="../config/test" includes="**" />
                                        </copy>
                                        <copy file="${basedir}/../config/usp-app-config.xml" todir="${basedir}/target/myMessage/WEB-INF/classes/config" />
                                        <copy file="${basedir}/../usp-env/src/test/env/usp-app-config.properties" todir="${basedir}/target/myMessage/WEB-INF/classes" />
                                        <copy file="${basedir}/../usp-env/src/test/env/app-config.properties" todir="${basedir}/target/myMessage/WEB-INF/classes" />
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
Était-ce utile?

La solution 3

The issue was with the version of GWT supported by our project. It did not support @GenEvent as the project was not configured to use Gin. So, created Event and Handler classses manually instead of relying on Gin's annotations. Now, it works well. Closing this thread. Thank you all.

Autres conseils

I'm not familiar enough with GWT to know if it's that plug that's generating the EditorChangeEvent classes but I'd guess it is.

That said, I am however all too familiar with both IntelliJ and Maven. I can therefore explain how this problem can arise and how to solve it.

If you're going to try to build everything as a single project then you need to find the source files for the EditorChangeEvent classes. It's common for plugins that generate classes to put the source for those classes in target/generated-sources but I can't say for sure in the case of GWT (sometimes it's an option on the plugin to indicate whether the source is kept or not). If this is the case, the plugin should have added a compile source root to the Maven project. IntelliJ will recognise this and mark the target/generated-sources directory a source root in the IntelliJ project. If the target/generated-sources directory exists but hasn't been automatically marked as a source root you can do this by right-clicking the directory and selecting Mark Directory As.

The other possiblity is that the source never exists. If this is the case then you going to have to break you project in two - one project containing the generated classes and one containing the classes that use the generated classes. Obviously this second project depends on the first using Maven's dependency mechanism.

http://mojo.codehaus.org/gwt-maven-plugin/compile-mojo.html says

generateDirectory

Folder where generated-source will be created (automatically added to compile classpath). ${project.build.directory}/generated-sources/gwt

So Maven should be able to compile your project correctly. However as Nick point target/generated-sources/gwt included as a source directory in your IDE you will have compilation problems.

You need to update your question with more specific details as you have not been clear exactly where in the target folder the classes are generated; or what is giving you compilation errors (Maven or your IDE - and which IDE are you using)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top