Closed pritip123 closed 7 years ago
@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.
@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>
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!
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.
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.