Include the library during programming and compilation, but exclude from assembly, in the NetBeans Maven project

In NetBeans 8, in a Maven based project, how to use jar while programming but omit from assembly?

I need to access some specific classes in a specific JDBC in my Vaadin . But in web apps, we usually don't link JDBC drivers inside our assembly ( jar file ) to be on the classpath while I edit my code and compile. But this jar file must be omitted from the assembly.

exclusions

Tag

I tried to add tags exclusions

and exclusion

to the element dependency

. But it didn't work - postgresql-9.4-1201.jdbc41.jar

appeared in the folder WEB-INF/lib

.

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.4-1201-jdbc41</version>
    <exclusions>
        <exclusion>
            <groupId>org.postgresql</groupId>  Exclude from build 
            <artifactId>postgresql</artifactId>
        </exclusion>
    </exclusions>
</dependency>

      

New profile?

The answer to this question is ZNK-M , Setting up custom run path for maven project in netbeans , maybe what I need.

But creating a new project profile seems like overkill, which seems like a small little task to me. And I always want to exclude this jar from my build output, not just when testing or other limited scenarios.

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

Then you will need to add a new profile to your IDE to run the pom with the -P run-with-netbeans option on the command line.

But I'm only familiar with the basics of editing a POM file . If this approach is the way to go, it would be helpful if someone could expand on the details and necessary steps.

0


source to share


2 answers


<scope>provided</scope>

Use a tag <scope>

in a POM file with a value provided

.

Excerpt from the Dependency Scope section of the Introduction to Dependency Mechanism page :



compile
This is the default scope, used if none is specified. Compilation dependencies are available in all classes of the project. In addition, these dependencies are propagated to dependent projects.

provided
This is very similar to compilation, but indicates that you expect the JDK or container to provide the dependency at runtime. For example, when building a web application for Java Enterprise Edition, you must set a dependency on the Servlet API and its associated Java EE APIs for scope because the web container exposes these classes. This scope is only available in the compilation and test path and is not transitive.

runtime
[...]

test
[...]

system
[...]

import
[...]

Like this:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.4-1201-jdbc41</version>
    <scope>provided</scope>
</dependency>

      

+1


source


Use scope provided

instead compile

of the default scope for this dependency. This is exactly what it is for.



<dependency>
    <scope>provided</scope>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
</dependency>

      

+1


source







All Articles