//first.kt package testing /** * Created by seyfer on 26.03.14. */ //fun main(args : Array<String>) { // println("Hello, world!") //} //fun main(args : Array<String>) { // if (args.size == 0) { // println("Please provide a name as a command-line argument") // return // } // println("Hello, ${args[0]}!") //} /*fun main(args : Array<String>) { for (name in args) println("Hello, $name!") }*/ fun main(args: Array<String>) { val language = if (args.size == 0) "EN" else args[0] println(when (language) { "EN" -> "Hello!" "FR" -> "Salut!" "IT" -> "Ciao!" "seyfer" -> "seed!" else -> "Sorry, I can't greet you in $language yet" }) }
//first.java package testing; /** * Created with IntelliJ IDEA. * User: seyfer * Date: 24.07.13 * Time: 21:02 * To change this template use File | Settings | File Templates. */ public class first { public static void main(String[] args) { System.out.print("Hello " + args[0] + "\n"); TestingPackage.main(args); } }
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.jetbrains.kotlin.examples</groupId> <artifactId>idea_test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>idea_test</name> <url>http://maven.apache.org</url> <properties> <kotlin.version>0.1-SNAPSHOT</kotlin.version> <junit.version>4.10</junit.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>testing.first</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <artifactId>kotlin-maven-plugin</artifactId> <groupId>org.jetbrains.kotlin</groupId> <version>${kotlin.version}</version> <configuration><sourceDirs> < source > src/ < / s ource > </sourceDirs></configuration> <executions> <execution> <id>compile</id> <phase>process-sources</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>process-test-sources</phase> <goals> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <repositories> <repository> <id>sonatype.oss.snapshots</id> <name>Sonatype OSS Snapshot Repository</name> <url>http://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>sonatype.oss.snapshots</id> <name>Sonatype OSS Snapshot Repository</name> <url>http://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
java -jar /path/to/file.jar argument1 argument2
java -jar target/idea_test-1.0-SNAPSHOT.jar 1 Hello 1 Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at testing.TestingPackage-first-39a20e2.main(first.kt:27) at testing.TestingPackage.main(first.kt:1) at testing.first.main(first.java:16) Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java -cp target/idea_test-1.0-SNAPSHOT.jar:lib/kotlin-runtime.jar testing.first seyfer Hello seyfer seed!
<plugin> <groupId>org.dstovall</groupId> <artifactId>onejar-maven-plugin</artifactId> <version>1.4.5</version> <executions> <execution> <configuration> <binlibs> <fileSet> <directory>${project.build.directory}/../lib/</directory> <includes> <include>kotlin-runtime.jar</include> </includes> </fileSet> </binlibs> <!-- Optional, default is false --> <attachToBuild>true</attachToBuild> <!-- Optional, default is "onejar" --> <classifier>onejar</classifier> </configuration> <goals> <goal>one-jar</goal> </goals> </execution> </executions> </plugin> <pluginRepository> <id>onejar-maven-plugin.googlecode.com</id> <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url> </pluginRepository>
mvn package
java -jar target/idea_test-1.0-SNAPSHOT.one-jar.jar seyfer Hello seyfer seed!
Source: https://habr.com/ru/post/221269/
All Articles