Setting custom runtime classpath for a maven project in netbeans

╄→гoц情女王★ 提交于 2019-12-02 13:12:18

问题


I want to add a custom classpath when I'm running my maven project from within netbeans. So far I've tried adding the following to the Run Project action in the project properties:

exec.args=-classpath %classpath;c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName} 

exec.args=-cp %classpath;c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName}

exec.args=-cp c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName}  

but no luck, the custom runtime classpath is not set.


回答1:


You should add a new profile run-with-netbeans in your pom that declares the additional dependencies (use the provided scope to not include them in the release).

Then you'll have to add the new profile to your IDE to run the pom with the -P run-with-netbeans option in the command line.

<properties>
    <!-- provided by default -->
    <my-dynamic-scope>provided</my-dynamic-scope>
</properties>

<profiles>
    <profile>
        <id>run-with-netbeans</id>
        <properties>
            <!-- compile when running in IDE -->
            <my-dynamic-scope>compile</my-dynamic-scope>
        </properties>
        <dependencies>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>


<dependencies>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>${commons-lang.version}</version>
        <scope>${my-dynamic-scope}</scope>
    </dependency>
</dependencies>

The snippet above add log4j only when running with the run-with-netbeans profile. It also sets a property my-dynamic-scope that can be used in your dependency block to change the scope.

HIH M.



来源:https://stackoverflow.com/questions/11615164/setting-custom-runtime-classpath-for-a-maven-project-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!