CMake to compile java code -


is possible use cmake compile , run java code?

from command line commands write on terminal is:

javac -classpath theclasspath mainclass.java

java -classpath theclasspath mainclass

if so, please give me idea of how can achieved?

ps: not want generate jar file; compile java class , if possible run it.

thanks.

update: have changed command. not know why additional text not displayed. might because used "<" , ">".

cmake has limited support compiling java code , executing java class files.

the standard module findjava can used find jdk installed on local machine. standard module usejava provides few functions java. among function add_jar compile java source files jar file.

here small example demonstrates how use add_jar. given java sample source file helloworld.java:

public class helloworld {     public static void main(string[] args) {         system.out.println("hello, world!");     } } 

the following cmake list file compile helloworld.java jar file helloworld.jar , add cmake test runs jar jvm:

cmake_minimum_required (version 2.8)  find_package(java required) include(usejava)  enable_testing()  project (helloworld)  set(cmake_java_compile_flags "-source" "1.6" "-target" "1.6")  add_jar(helloworld helloworld.java)  get_target_property(_jarfile helloworld jar_file) get_target_property(_classdir helloworld classdir)  message(status "jar file ${_jarfile}") message(status "class compiled ${_classdir}")  add_test(name testhelloworld command ${java_java_executable} -cp ${_jarfile} helloworld) 

the cmake variable cmake_java_compile_flags can used specify compile flags. side effect add_jar command set target properties jar_file , classdir can used obtain path generated jar file , compiled class files directory, respectively.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -