AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.
Other
711 stars 123 forks source link

Adding dependencies to Alloy #252

Closed liangyiliang closed 5 months ago

liangyiliang commented 5 months ago

Hi,

Please excuse me if this is not the right place to ask this question.

I am working on a project that extends Alloy 5.1.0's org.alloytools.alloy.application package with a feature that uses WebSocket to transmit some model details into an external application. I have elected to use the org.Java-WebSocket package.

I have been trying to compile a version of Alloy 5.1.0 that includes the jar for org.Java-WebSocket, but I can't seem to get it to work.

This is what I have done:

  1. In cnf/central.xml, I added these lines:

    <dependency>
    <groupId>org.java-websocket</groupId>
    <artifactId>Java-WebSocket</artifactId>
    <version>1.5.6</version>
    </dependency>
  2. In bnd.bnd from org.alloytools.alloy.application, I added the package into -buildpath:

    -buildpath: \
    lib/apple-osx-ui.jar;version=file,\
    org.alloytools.alloy.core;version=latest,\
    org.alloytools.kodkod.core;version=latest,\
    Java-WebSocket;version=1.5.6
  3. Finally, in settings.gradle I added these lines under dependencies:

    classpath 'org.java-websocket:Java-WebSocket:1.5.6'

But it appears that once I run ./gradlew build and execute the resultant .jar file under org.alloytools.alloy.dist, Java would give me an exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/java_websocket/server/WebSocketServer

So it seems that org.java-websocket hasn't been bundled into the jar file.

Is there anything else that I need to do for this to work?

Thank you!

pkriens commented 5 months ago

There is no cnf/central.xml. There is a cnf/central.mvn which does indeed perform the function of scoping the dependencies.

If you look in this file it should be obvious how to add more dependencies. It follows the Maven Group:Artifact:Version format. In your case org.java-websocket:Java-WebSocket:1.5.6. you will still have to add the Bundle Symbolc Name to the -buildpath, what you did looks ok although the version is not required, it will the version solution from the central.mvn list.

If you use Eclipse with Bndtools then you get a lot of help with these dependencies and the jars are immediately build after each detailed change you make.

We're currently on 6.0, and closing 6.1. Any reason not to use this latest version?

liangyiliang commented 5 months ago

Hi - apologies for the late reply. We have resolved the issue with adding dependencies, thanks!

We're currently on 6.0, and closing 6.1. Any reason not to use this latest version?

In our current project we do not yet want to deal with temporal models - at least for now, we just want to build a quick prototype to work with non-temporal models without dealing with temporal ones. That's why we are still on Alloy 5.1.0. In the near future we will switch to using the latest version.

Thank you!