I just crafted a short proposal on the problem and a possible solution (see
below).
@Romain: Does it cover your problem/solution?
@Elliotte: Is this kind of the one pager you were thinking of?
@Martin: Wrt. your performance considerations, could the solution do some
caching to make it more lightweight (after first execution)?
# Proposal: mvn --execute for Java Scripts with Dependencies
## Problem
JDK 25 finalizes Compact Source Files (JEP 512) for simple Java programs
without class declarations.
However, dependency management remains unsolved for single-file scripts.
Using pom.xml + exec-maven-plugin is too heavy, and JBang introduces a separate
ecosystem.
## Proposal
Add `mvn --execute` (or `mvn -E`) that:
1. Parses //MVN comments for dependency declarations
2. Resolves dependencies using Maven Resolver (respects ~/.m2/settings.xml)
3. Executes the script with the resolved classpath
## Example
File: analyze.java
```
#!/usr/bin/env mvn --execute
//MVN com.google.guava:guava:33.0.0-jre
//MVN org.slf4j:slf4j-simple:2.0.9
import com.google.common.collect.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
void main() {
Logger log = LoggerFactory.getLogger("analyze");
var items = ImmutableList.of("alpha", "beta", "gamma");
log.info("Processing {} items", items.size());
items.forEach(item -> println(" - " + item));
}
```
Run: `chmod +x analyze.java && ./analyze.java`
Or: `mvn --execute analyze.java`
## Performance
Cache resolved classpath next to script, recompute only when dependencies
change.
> On 22. Dec 2025, at 01:10, Martin Desruisseaux via dev <[email protected]>
> wrote:
>
> Le 21/12/2025 à 21:11, Romain Manni-Bucau a écrit :
>
>> I just want to run a "java -cp xxxx foo.java" with xxx being filled portably
>> accross machines.
>>
> But using Maven for launching an application is heavy. Could it be instead a
> plugin or command which generates the `java` options in a file? The content
> of that file may be specific to each machine, but we can handle that as a
> cache. A shell script can invoke a Maven plugin for generating that file if
> it does not exist, otherwise just invoke `java @the-file`.
>
> Martin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
--
Gerd Aschemann --- Veröffentlichen heißt Verändern (Carmen Thomas)
+49/173/3264070 -- [email protected] -- http://www.aschemann.net