Home > OS >  Main class in eclipse launcher for maven archetype
Main class in eclipse launcher for maven archetype

Time:05-20

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".

CodePudding user response:

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"/>
  • Related