You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ahardy42 <ad...@cyberspaceroad.com> on 2018/01/04 16:12:33 UTC

ServiceLoader not loading FileTypeDetector implementation in jar

I created, tested and packaged a java.nio.file.spi.FileTypeDetector
implementation in a utility jar for use by Files.probeContentType(path). 

So it works beautifully in my utility project. 

I'm now trying to use it in another project but despite hours of trying, I
can't work out why the JVM can't find or load my implementation and keeps
defaulting back to the JDK's RegisterFileTypeDetector.

I have double checked that the utility jar is in my classpath with
dependency:tree, contains the
META-INF/services/java.nio.file.spi.FileTypeDetector file naming my
implementation, and also the actual implementation class.

The JDK javadoc documentation claims that it will seek it out anywhere on
the application's classpath:

https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html

but I only see it searching on the system classpath during debugging. 

My efforts are hampered by the use of nested arrays of Enumeration<URL> with
sun.misc.CompoundEnumeration. It's really convoluted and I haven't been able
to see where it fails.

What could I be doing wrong? 





--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

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


Re: ServiceLoader not loading FileTypeDetector implementation in jar

Posted by ahardy42 <ad...@cyberspaceroad.com>.
Actually there is a third scenario that might be relevant. 

It fails in Intellij's maven env.

It works in teamcity's maven run.

It fails in the maven plugin where it is used by my mojo, in Intellij. 

The 4th scenario is the teamcity build using my mojo. Haven't tried that
yet. 



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

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


Re: ServiceLoader not loading FileTypeDetector implementation in jar

Posted by ahardy42 <ad...@cyberspaceroad.com>.
I tried checking in my code and lo, the tests pass on the CI server
(teamcity), i.e. on teamcity the classloader finds my FileTypeDetector in
the dependency jar.




--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

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


Re: ServiceLoader not loading FileTypeDetector implementation in jar

Posted by ahardy42 <ad...@cyberspaceroad.com>.


System.getSecurityManager().checkPermission(new
RuntimePermission("fileTypeDetector"));

is not possible.

System.getSecurityManager() returns null.


Regards
Adam






--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

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


Re: ServiceLoader not loading FileTypeDetector implementation in jar

Posted by Martin Gainty <mg...@hotmail.com>.

________________________________
From: ahardy42 <ad...@cyberspaceroad.com>
Sent: Thursday, January 4, 2018 11:12 AM
To: users@maven.apache.org
Subject: ServiceLoader not loading FileTypeDetector implementation in jar

I created, tested and packaged a java.nio.file.spi.FileTypeDetector
implementation in a utility jar for use by Files.probeContentType(path).

So it works beautifully in my utility project.

I'm now trying to use it in another project but despite hours of trying, I
can't work out why the JVM can't find or load my implementation and keeps
defaulting back to the JDK's RegisterFileTypeDetector.

I have double checked that the utility jar is in my classpath with
dependency:tree, contains the
META-INF/services/java.nio.file.spi.FileTypeDetector file naming my
implementation, and also the actual implementation class.

The JDK javadoc documentation claims that it will seek it out anywhere on
the application's classpath:

https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html
ServiceLoader (Java Platform SE 8 ) - Oracle Help Center<https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html>
docs.oracle.com
A simple service-provider loading facility. A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific ...

MG>*possible permissions error* on the maven user you are implementing
MG>System.getSecurityManager<http://www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/System.java#System.getSecurityManager%28%29>().checkPermission<http://www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/SecurityManager.java#SecurityManager.checkPermission%28java.security.Permission%29>(new RuntimePermission<http://www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/RuntimePermission.java#RuntimePermission>("fileTypeDetector"));
MG>what is the result of the above statement?
http://www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/nio/file/spi/FileTypeDetector.java#FileTypeDetector
GC: FileTypeDetector - java.nio.file.spi.FileTypeDetector (.java) - GrepCode Class Source<http://www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/nio/file/spi/FileTypeDetector.java#FileTypeDetector>
www.grepcode.com
java.nio.file.spi.FileTypeDetector - A file type detector for probing a file to guess its file type




but I only see it searching on the system classpath during debugging.

My efforts are hampered by the use of nested arrays of Enumeration<URL> with
sun.misc.CompoundEnumeration. It's really convoluted and I haven't been able
to see where it fails.

What could I be doing wrong?





--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html
Maven - Maven - Users | Mailing List Archive<http://maven.40175.n5.nabble.com/Maven-Users-f40176.html>
maven.40175.n5.nabble.com
This forum is an archive for the mailing list users@maven.apache.org (more options) Messages posted here will be sent to this mailing list.




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