Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run example using Maven, no IDE required #4

Closed
mattys101 opened this issue Sep 26, 2017 · 2 comments
Closed

Run example using Maven, no IDE required #4

mattys101 opened this issue Sep 26, 2017 · 2 comments

Comments

@mattys101
Copy link
Contributor

I noticed you mentioned that the current stuff can only be run using the IDE.
You could set up an execution target in Maven so that you can run it easily without the IDE. If you want to that is. The code I use is below ;-)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <configuration>
        <executable>java></executable>
        <mainClass>st.redline.Stic</mainClass>
        <arguments>
            <argument>st.redline.example.Test</argument>
        </arguments>
    </configuration>
</plugin>

The only problem with this, is you need to make your classpath handling more robust since Maven modifies the classpath at runtime, rather than specifying java.class.path variable.

Here's my hacky change to Stic's classPaths() method:

public String[] classPaths() {
    String[] classPaths = classPath().split(File.pathSeparator);

    ArrayList<String> urlClassPaths = new ArrayList<>(java.util.Arrays.asList(classPaths));
    URLClassLoader cl = (URLClassLoader) (Thread.currentThread().getContextClassLoader());
    for (URL url : cl.getURLs()) {
        if ("file".equals(url.getProtocol())) {
            urlClassPaths.add(url.getFile());
        }
    }

    classPaths = urlClassPaths.toArray(classPaths);

    return classPaths;
}

Cheers,

Matt

@jamesladd
Copy link
Owner

jamesladd commented Sep 26, 2017 via email

@jamesladd
Copy link
Owner

jamesladd commented Sep 26, 2017

branch: jcl/classpath

Redline must find a Smalltalk file in the classpath or in a JAR.
This also enables Redline to be run from the command line.

You can run Redline from the command line with the following command to run Test.st

java -cp redline-0.6-SNAPSHOT.jar -jar redline-0.6-SNAPSHOT.jar st.redline.example.Test

NOTE

When compiling with Maven (mvn clean package) the resulting JAR is in the target folder, including the Smalltalk sources so the following shorter command line also works.

java -jar target/redline-0.6-SNAPSHOT.jar st.redline.example.Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants