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

To Run Maven Project #8

Closed
pritip123 opened this issue Sep 11, 2017 · 4 comments
Closed

To Run Maven Project #8

pritip123 opened this issue Sep 11, 2017 · 4 comments

Comments

@pritip123
Copy link

I have a Java with Maven project with all dependencies ,I have done mvn package and trying to run the main class but it could not able to resolve the dependencies can you please provide the steps to run the maven project with all dependencies.

@miha-plesko
Copy link
Contributor

@pritip123 thanks for asking. Until now I've always been compiling my simple Java application with javac directly. Let me play a little with mvn, I'll let you know when it works on OSv.

BTW, if you can, it would help if you could share your maven application with us so that we can play with it directly. If this is not possible, then no problem, we will create our own small application.

@gasper-vrhovsek
Copy link
Contributor

gasper-vrhovsek commented Sep 12, 2017

@pritip123 did you perhaps package the jar with dependencies? Check if your maven build configuration looks something like this:

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>com.example.Main</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

@miha-plesko
Copy link
Contributor

Hello @pritip123, we've been playing with following Java application that makes use of some external dependencies:

package org.xlab;

import org.apache.commons.io.output.StringBuilderWriter;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        StringBuilderWriter sbw = new StringBuilderWriter();

        sbw.append("Hello");
        sbw.append(" ");
        sbw.append("world");

        System.out.println(sbw.toString());
    }
}

We then used Maven to build a fat jar by using the snippet that @gasper-vrhovsek kindly provided in the comment above. The result was a target/osv_sample-1.0-SNAPSHOT-jar-with-dependencies.jar file that we've copied into a new directory with following structure:

demo/
├── meta/
│   ├── package.yaml
│   └── run.yaml
└── osv_sample-1.0-SNAPSHOT-jar-with-dependencies.jar

The content of the two meta files was as follows:

# meta/package.yaml

name: demo
title: Maven Demo
author: me
# meta/run.yaml

runtime: java
config_set: 
  hello:
    jvm_args:
      - "-jar"
    main: /osv_sample-1.0-SNAPSHOT-jar-with-dependencies.jar
    classpath:
      - /

config_set_default: hello

Then I cd into the demo/ directory and execute:

$ cd demo
$ capstan package compose demo --pull-missing
$ capstan run demo --boot hello
Command line will be set based on --boot parameter
Created instance: demo
Setting cmdline: runscript /run/hello
OSv v0.24-434-gf4d1dfb
eth0: 192.168.122.15
java.so: Starting JVM app using: io/osv/nonisolated/RunNonIsolatedJvmApp
java.so: Setting Java system classloader to NonIsolatingOsvSystemClassLoader
Hello world

Most probably you were using the incorrect parameters inside meta/run.yaml since we haven't documented how one is to run .jar files yet. I will update README on Capstan to make this clear, thanks for noticing!

@pritip123
Copy link
Author

Thanks a lot @gasper-vrhovsek and @miha-plesko . I was not adding jvm_args as jar file and so its always looking for the main class instead of jar file .Its working fine now.

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

3 participants