运行依赖第三方jar包和本项目的类的scala脚本

前端之家收集整理的这篇文章主要介绍了运行依赖第三方jar包和本项目的类的scala脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


以guava-14.0.1.jar为例

==============================scala编译================================:

scalac -cp guava-14.0.1.jar src/com/pojo/SoitemRpt.scala src/Sample.scala -d target/

scala -cp guava-14.0.1.jar:target/ Sample


使用sourcelist进行编译

scalac -cp guava-14.0.1.jar @sourcelist -d target/

scala -cp guava-14.0.1.jar:target/ Sample



==============================java编译==============================:

javac -cp guava-14.0.1.jar src/main/B.java src/abc/A.java -d target/

java -cp guava-14.0.1.jar:target/ main.B


使用sourcelist进行编译

cat sourcelist

src/main/B.java

src/abc/A.java

javac -cp guava-14.0.1.jar @sourcelist -d target/

java -cp guava-14.0.1.jar:target/ main.B


===========================scala 代码=================================

==

import com.google.common.base.Splitter

import com.pojo.SoitemRpt


//import scala.collection.parallel.Splitter

import scala.io.Source


object Sample {

def widthOfLength(s: String) = s.length.toString.length


def main(args: Array[String]) {

val g = new SoitemRpt

g.greet()

println("==============")

val splitter=Splitter.on(',').split("one,two,three");

val it=splitter.iterator()


while(it.hasNext){

println(it.next())

}



System.exit(0)


if (args.length > 0) {

val lines = Source.fromFile(args(0)).getLines.toList

val longestLine = lines.reduceLeft(

(a,b) => if (a.length > b.length) a else b

)

val maxWidth = widthOfLength(longestLine)

for (line <- lines) {

val numSpaces = maxWidth-widthOfLength(line)

val padding = " " * numSpaces

println(padding + line.length +" | "+ line)

}

}

else

Console.err.println("Please enter filename")

}

}


==

package com.pojo


class SoitemRpt {

val greeting = "Hello,world!"

def greet() = println(greeting)

}


===========================java 代码=================================

==

package main;


import abc.A;

import com.google.common.base.Splitter;


import java.util.Iterator;



public class B {

public static void main(String args[]) {

A a=new A();

a.println();


Iterable<String> spliter= Splitter.on(',three");

Iterator it=spliter.iterator();

while(it.hasNext()){

System.out.println(it.next());

}


}

}


package abc;


==

public class A {


public void println(){

System.out.println("AAA");

}

}

原文链接:https://www.f2er.com/javaschema/284320.html

猜你在找的设计模式相关文章