Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed service loading of VerticleFactory from mvn exec java #1438

Closed
wants to merge 1 commit into from
Closed

Fixed service loading of VerticleFactory from mvn exec java #1438

wants to merge 1 commit into from

Conversation

paulmiddelkoop
Copy link

Fixes #1437.

Signed-off-by: paulmiddelkoop <paul@pamisoft.nl>
@vietj
Copy link
Member

vietj commented May 24, 2016

@cescoffier thoughts ?

@cescoffier
Copy link
Contributor

@vietj Let me have a look once I'm back from my trip. I don't understand why we need explicit delegation in this case, and why the class cannot be loaded from the regular classpath (I also remember having fixed something quite similar in 3.2.1).

@paulmiddelkoop
Copy link
Author

@cescoffier this is indeed similar to the fix you made in io.vertx.core.ServiceHelper. When dealing with different classloading mechanisms like OSGI and Maven plugin's, the current thread class loader will not work. I suspect that the Vert.x Service Factory will not be loaded correctly in the DeploymentManager when using OSGI in combination with the current thread class loader.

A similar problem is discussed here: http://stackoverflow.com/questions/36161795/how-to-register-a-spi-implementation-when-running-execjava.

@cescoffier
Copy link
Contributor

Hi,

Do you have a quick reproducer of the issue. I tried with:

<execution>
            <id>run</id>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>io.vertx.core.Launcher</mainClass>
              <arguments>
                <argument>run</argument>
                <argument>${verticle.main}</argument>
                <argument>-cp</argument>
                <argument>${project.build.outputDirectory}</argument>
              </arguments>
            </configuration>
          </execution>

and it works for me (service loaded correctly) for a service defined in the project and a service loaded from a dependency.

That's said, I do agree with your fix, something is wrong here. However, I think it would be better to rely to the ServiceHelper.loadFactory method instead of passing a classloader, just to centralize all (META-INF) service loading.

@paulmiddelkoop
Copy link
Author

Hi @cescoffier,

I added a reproduction project here: https://github.com/paulmiddelkoop/vertx-issue-1438.
When doing a mvn clean install exec:java it will throw an IllegalStateException since service descriptor is discarded. When running the Launcher directly or changing to the vertx version with my patch included it will print Loaded succesfull to the console.

I think ServiceHelper will be a good place to centralize service loading. At the moment this helper only returns the first factory. In the DeploymentManager case it should return all factories.

@cescoffier
Copy link
Contributor

Thanks, for the reproducer, gonna have a look to it tomorrow.

cescoffier added a commit to cescoffier/vert.x that referenced this pull request May 31, 2016
…eHelper` class.

Also add test to check the behavior of the `ServiceHelper` when using different classloaders.

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>
vietj added a commit that referenced this pull request May 31, 2016
…ading-issue

Use Service Helper to avoid classloading issue
@vietj
Copy link
Member

vietj commented May 31, 2016

@cescoffier I'm assuming we should close this one, right ?

@paulmiddelkoop
Copy link
Author

I tested @cescoffier's fix and it works correctly, so this one can be closed.

@vietj vietj removed the to review label Jun 1, 2016
@paulmiddelkoop paulmiddelkoop deleted the issue-1437 branch June 1, 2016 07:02
@vietj
Copy link
Member

vietj commented Jun 1, 2016

great

@paulmiddelkoop
Copy link
Author

Thanks @cescoffier !

vietj pushed a commit that referenced this pull request Jun 4, 2016
Also add test to check the behavior of the `ServiceHelper` when using different classloaders.

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants