Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven WAR dependency - cannot resolve package?

I have a war dependency:

    <dependency>
        <groupId>my.package</groupId>
        <artifactId>myservices</artifactId>
        <version>0.3</version>
        <type>war</type>
    </dependency>

Now, this exists in my local repository, and the class exists at WEB-INF/classes/my/package/myservices. When I go to use myservices, however, I get package my.package does not exist. Intelli-J knows to change myservices into my.package.myservices, but trying to import seems to not work at all.

Is there something special I need to do with this war dependency?

like image 543
Stefan Kendall Avatar asked Apr 08 '11 15:04

Stefan Kendall


People also ask

Can we add war as dependency in Maven?

It worked great with classes originating from external libraries which I could add as dependencies. However, it failed with classes originating from the Hippo CMS Site module because it was compiled into a . war archive which Maven can't handle as a dependency.

What is Maven war plugin?

The Maven WAR plugin is responsible for collecting and compiling all the dependencies, classes, and resources of the web application into a web application archive. There are some defined goals in the Maven WAR plugin: war: This is the default goal that is invoked during the packaging phase of the project.

What is type in Maven dependency?

There are two types of dependencies in Maven: direct and transitive. Direct dependencies are the ones that we explicitly include in the project.


1 Answers

It just doesn't work that way. war files are not supposed to be put on the classpath, but deployed to application servers (or servlet containers) that can deal with their special structure.

Of course you can probably find a custom classloader somewhere that can deal with java war files, but it's just not the way to do it.

Keep your code in a jar, include the jar in your war and in this application. But don't use a war as a dependency, unless you are building an EAR file.

like image 164
Sean Patrick Floyd Avatar answered Sep 20 '22 03:09

Sean Patrick Floyd