0

How to include the java "main" class in the launcher / run configuration in maven archetype project?

run.launch:

<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
    <listEntry value="/${artifactId}/src/main/java/MY/PACKAGE/STRUCTURE/Start.java"/>

The result (after archetype generation) should look like /MYPROJECT/src/main/java/MY/PACKAGE/STRUCTURE/Start.java. So, the main issue is how to replace the dynamic java package structure, since it's different for each project.

Property ${package} resolves to "MY.PACKAGE.STRUCTURE" rather then the required "MY/PACKAGE/STRUCTURE".

Krabat
  • 133
  • 1
  • 6
  • Looks like you want below solution? https://stackoverflow.com/questions/17397440/how-to-setup-main-class-in-run-configurations-in-eclipse – SeanH May 15 '22 at 09:25
  • @SeanH Sorry, but my question is about the maven archetype, which will generate that launcher file. Thanks for taking a look at my issue. – Krabat May 15 '22 at 09:33
  • Oh, sorry. You can edit the pom.xml file directly. If you don't mind, I can paste some content for the plugin used to generate the one single jar file for the package. – SeanH May 15 '22 at 09:36
  • @SeanH My issue is a maven archetype issue. I need a archetype directive, which is able to resolve the dynamically assigned java package structure in the archetype generation step, which results in the package structure with dashes instead of dots. – Krabat May 15 '22 at 09:51
  • OK. Understood. You need a dynamic generation based on the java package definition in the generation step but not manually editing in the hard code pom.xml? – SeanH May 15 '22 at 09:54
  • @SeanH Sort of... The package definition should be resolved in a property, which has "/" instead of ".". The property is referenced/replaces in a eclipse launcher configuration. The generation process itself is automatically done by maven archetype. – Krabat May 15 '22 at 10:42

1 Answers1

0

Posting my solution for other users, which might stumble across the same issue.

Define a new property in my-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml:

<requiredProperties>
    <requiredProperty key="package-with-slash">
        <defaultValue>${package.replace(".", "/")}</defaultValue>
    </requiredProperty>

Note, that the replacement is done by the apache velocity engine.

Then, reference it in the run.launch:

<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
        <listEntry value="/${artifactId}/src/main/java/${package-with-slash}/Start.java"/>
Krabat
  • 133
  • 1
  • 6