JZMQ with Tomcat 8.0 keeps throwing NoClassDefFoundError

I have a webapp project that uses maven.

In the project’s pom.xml file, there’s a dependency element referring to the JZMQ jar file which resides in the local filesystem, like this:

    <dependency>
        <groupId>com.external.jzmq</groupId>
        <artifactId>zmq</artifactId>
        <version>3.1.0</version>
        <scope>system</scope>
        <systemPath>${external.lib.path}</systemPath>
    </dependency>

with external.lib.path being the filepath in the local filesystem.

This JZMQ jar file is built from libzmq v4.1.6, and JZMQ v3.1.0, if that helps.

This project is then loaded in Eclipse (x86_x64 Windows, 2023-06) and is supposed to run on a Tomcat v7.0 server.
The thing is, when I try to load and run the project on Tomcat, it always throws this:

java.lang.NoClassDefFoundError: org/zeromq/ZContext
    at hub.wgw.AgentSingleton.<init>(AgentSingleton.java:45)
    at hub.wgw.AgentSingleton.<clinit>(AgentSingleton.java:26)
    at launch.TomcatStartup.contextInitialized(TomcatStartup.java:14)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5128)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5653)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1689)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1679)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.zeromq.ZContext
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1951)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1795)
    ... 12 more

(with hub.wgw.AgentSingleton being a class from this project)

I should also state that JZMQ is the only option here. I cannot use JeroMQ or JCZMQ for some compatibility reasons. Similarly, getting JZMQ from the Maven Repo is out of the option as well.

I am almost absolutely sure that this is not a fault in the JZMQ’s side, for I already have tried using the exact same jar file in a simpler maven project to make sure it correctly runs, using the snippets from here: No jzmq in java.library.path

More precisely, I have created 2 different, smaller sized Maven projects that ping-pongs back and forth using JZMQ, and booted up both. It gave me the expected result, without any errors or whatnot.

I would like to know the reason why this keeps happening when I can use it with no problem with other projects, and if possible, a way to fix it.


Edit: I can solve the problem easily enough by simply copy-pasting the jar file in question inside Tomcat’s lib directory, but that defeats the purpose of using Maven in the first place. I would like an explanation, rather than a workaround. Thanks in advance.

6

Solved! It looks like I was looking at the wrong place.

If a dependency has system as its’ scope, then the dependency in question is omitted in the final build. This was why it kept throwing errors despite the build being successful.

The reason why it worked fine with my test projects was that it managed to grab and use the jzmq jar file right away, since it ran on a standalone project, contrary to this current project which runs on Tomcat.

So, the key was to remove the scope and systemPath attributes, then add something like below:

<repositories>
    <repository>
        <id>com-external-jzmq</id>
        <url>file://[local repository location]</url>
    </repository>
</repositories>

This sets up a local repository, which can then be used to find jar files within. Then, it’s a matter of placing the jzmq jar file such that (some path)com.external.jzmqzmq3.1.0zmq-3.1.0.jar is a valid path.

From what I understand, this path should match the dependency’s group ID, artifact ID and version. i.e. (group ID)(artifact ID)(version) should be the path.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật