Why does the WTP plugin deploy one Maven dependenc

2019-03-18 19:08发布

I have a very strange problem with Maven and the Eclipse WTP. I have a multi-module project, let's call it project. It consists of two modules project-base and project-web. I have the workspace resolution enabled (and it works fine with several other very similar Maven projects).

project-base is a dependency of project-web and it's normally deployed as a jar file. But for several days, it keeps being deployed as a class folder in my local Tomcat, as you can see here: Dependency deployed as folder, not as jar

Therefore, my Tomcat does not recognize any of my class files in there, because it expects them to be jars, not folder. The -tests suffix comes from the need to have the test from base in my web project. I don't think this is the problem.

project-web has three dependencies being resolved from the workspace. Two of them are deployed correctly, as jar, but the third one is not.

project-base's pom.xml is shown here:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>project</artifactId>
        <groupId>com.company.project</groupId>
        <version>4.0.0</version>
    </parent>
    <artifactId>project-base</artifactId>
    <name>projectBase</name>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>windows-1251</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.4</version>
            </plugin>
        </plugins>
    </build>
</project>

The dependency project-base as it is defined in project-web looks like this:

<dependency>
    <groupId>com.company.project</groupId>
    <artifactId>project-base</artifactId>
    <version>${project.version}</version>
</dependency>

<dependency>
    <groupId>com.company.project</groupId>
    <artifactId>project-base</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

I don't have an idea why one dependency is deployed in such a strange way and I don't know how to fix this. I cleaned the projects, the tomcat, redeployed the web project, purged my whole Maven repository, checked out the whole project fresh from VCS, nothing helped.

What could cause Eclipse WTP to deploy this dependency as a folder instead of a jar file?

4条回答
够拽才男人
2楼-- · 2019-03-18 19:26

I solved the problem by deleting the dependency in the "Deployment assembly" project settings page and adding it back.

查看更多
▲ chillily
3楼-- · 2019-03-18 19:34

I was just having the same problem. Upgrading m2e to version 1.2 fixed it.

查看更多
▲ chillily
4楼-- · 2019-03-18 19:34

If that folder is an exploded JAR (so it is like a JAR file, but appearing as a folder, not archived), in my case it was a server connector issue.

Although I use JBoss instead of Tomcat, this might be helpful for others struggling with this problem.

Provided you have the latest JBoss Tools installed on your Eclipse, you can double-click the server in Server view to open the settings.

On Deployment tab, you can select Zip Module Yes/No for each project. When I selected YES for my utility jar files, JBoss then deployed the dependency as a normal JAR file instead of a folder.

查看更多
Juvenile、少年°
5楼-- · 2019-03-18 19:35

I ultimately solved my problem: I had problems with the properties section Deployment Assembly for the project-base project. I could not save it, as Eclipse mentioned, the current page does contain errors.

I then looked into the settings file .settings/org.eclipse.wst.common.component. It was completely empty (I don't know why). I then added the following block:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="project-base">
        <wb-resource deploy-path="/" source-path="/src/main/java"/>
        <wb-resource deploy-path="/" source-path="/src/main/resources"/>
    </wb-module>
</project-modules>

After this, the settings page is accessible again and the JAR is assembled correctly. Workspace resolution does work, too.

查看更多
登录 后发表回答