CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/msfJavaToolkit/testCompilation.rb
Views: 11766
1
#!/usr/bin/ruby
2
3
require 'rubygems'
4
require 'rjb'
5
6
#Rjb::load('.', jvmargs=[])
7
Rjb::load("#{ENV['JAVA_HOME']}/lib/tools.jar:.",jvmargs=[])
8
9
clsJavaCompile = Rjb::import('javaCompile.CompileSourceInMemory')
10
clsCreateJar = Rjb::import('javaCompile.CreateJarFile')
11
clsFile = Rjb::import('java.io.File')
12
system = Rjb::import('java.lang.System')
13
#clsString = Rjb::import('java.lang.String')
14
15
classNames = [ "HelloWorld1", "HelloWorld2" ]
16
17
codez = Array.new
18
19
classNames.each { |name|
20
codez << %Q^
21
public class #{name} {
22
public static void main(String args[]) {
23
System.out.println("This is from #{name}.");
24
}
25
}^}
26
27
#compileOpts = [""]
28
#outputDir = system.getProperty('java.io.tmpdir')
29
outputDir = "testoutdir"
30
compileOpts = [ "-target", "1.3", "-source", "1.3", "-d", outputDir ]
31
32
success = clsJavaCompile._invoke('CompileFromMemory','[Ljava.lang.String;[Ljava.lang.String;[Ljava.lang.String;', classNames, codez, compileOpts)
33
34
fileOutJar = clsFile.new_with_sig('Ljava.lang.String;', 'output.jar')
35
filesIn = Array.new
36
37
classNames.each { |name|
38
filesIn << clsFile.new_with_sig('Ljava.lang.String;', "#{outputDir}/#{name}.class")
39
}
40
41
clsCreateJar._invoke('createJarArchive', 'Ljava.io.File;[Ljava.io.File;', fileOutJar, filesIn)
42
43
44