1

I need to compile a scala code which calls a java code from it.

What I did:

1]I have a scala main file check.scala

package com.code
     class check {
       var Rectvalue = Array.ofDim[Int](5)
       val str = Array.ofDim[String](1)
       def nativeacces(arg: String, loop: Integer) {
         val test = new testing()
         test.process(arg, Rectvalue,str)
         }
     }

2.For creating instance val test = new testing() ,i added two .class(sample.class,testJNI.class) file from java source code inside the folder(package) com/code.

3.When I compile the scala code using

scalac check.scala

It generates the class file for the scala file.

What I have to do:

1.Instead of .class(sample.class,testJNI.class) file added inside the package ,i need to add jar file.

2.I tried, created jar file for the .class file and compile the Scala, it shows the error:

 scala:6: error: not found: type testing
 val test = new testing()

3.I need to link the .jar file and compile the scala main file

2
  • use –classpath to reference your JAR. Even better let SBT handle all that. Commented Mar 8, 2016 at 8:16
  • @Aleksey Izmailo ,thanks for your reply.Can you please expain it in detail or help me with any links. Commented Mar 8, 2016 at 9:02

1 Answer 1

1

You can reference classes/directories/JARs via classpath option:

scalac -classpath your.jar check.scala

Related question: Adding .jar's to classpath (Scala).

If you want a proper build use SBT, put your JAR in lib directory in the root of project and it will figure out what to do for you. Here is Hello World of SBT.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the reply,I used package com.code in the project whether it change for that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.