mojohaus / mojohaus/exec-maven-plugin
Cannot use custom protocol handler when executing the program
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 191
- Forks
- 111
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
The issue is similar to one fired for maven-surefire-plugin. In particular when I do:
mvn -Djava.protocol.handler.pkgs=com.test.protocol -Dexec.mainClass=... exec:java
the protocol handler cannot be instantiated from given package as maven does classloader isolation.
The workaround is to set custom URLStreamHandlerFactory but it would be nice if above works without extra coding.
P.S. I tried -Dexec.classpathScope=system just for case but it does not help.
static class HttpHandlerFactory implements URLStreamHandlerFactory {
private final URLStreamHandler handler;
public HttpHandlerFactory(URLStreamHandler handler) {
this.handler = handler;
}
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
if (protocol.equals("http")) {
return handler;
}
return null;
}
}
public static void main(String[] args) throws Exception {
try {
Class<?> cl = Class.forName("com.test.protocol.http.Handler");
URL.setURLStreamHandlerFactory(new HttpHandlerFactory((URLStreamHandler) cl.newInstance()));
}
catch (ClassNotFoundException e) {
// Specific handler is not in the classpath
}
...
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the exec:java goal and how it builds the classloader for the program, then compare that behavior with the reported Maven Surefire issue. Reproduce the command using com.test.protocol and verify whether the custom protocol handler can be instantiated without a URLStreamHandlerFactory; completion means the documented -Djava.protocol.handler.pkgs usage works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100