{"id":270891,"date":"2015-12-22T17:08:02","date_gmt":"2015-12-22T14:08:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=270891"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=270891","title":{"rendered":"Java \u043f\u0440\u043e\u0442\u0438\u0432 Groovy"},"content":{"rendered":"<p>       \u0412\u0434\u0440\u0443\u0433 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0443\u0436\u043d\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0438\u043b\u0438 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f? <br \/>  \u041d\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0433\u0440\u0443\u0432\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u044c\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441 \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u0438\u0432\u043e\u043c. \u0418 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0435\u0449\u0435 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u043f\u0440\u0438\u0447\u0438\u043d \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0433\u0440\u0443\u0432\u0438 \u0432 \u043a\u043e\u0434. \u0425\u043e\u0442\u044c groovy \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u043b\u0438\u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u0437\u043d\u0430\u044e\u0449\u0435\u043c\u0443 java, \u0447\u0435\u043c \u0442\u0430 \u0436\u0435 scala. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/869\/d88\/762\/869d88762a294e60a72ad3942253e957.png\"\/><\/p>\n<p>  \u041d\u043e \u0434\u0430\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c java \u043a\u043e\u0434 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0432 jvm. \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442. \u0414\u0430 \u0438 \u0435\u0449\u0435 \u0431\u044b \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u0434\u0435\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c tools.jar \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u0433\u0440\u0430\u043c\u043c\u0435.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044f \u043d\u0435\u0433\u043e\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b Groovy \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432, \u043f\u0440\u0438\u0437\u043d\u0430\u044e\u0441\u044c \u0447\u0442\u043e \u044f \u0438 \u0441\u0430\u043c <a href=\"http:\/\/habrahabr.ru\/post\/272105\/\">\u043b\u044e\u0431\u043b\u044e<\/a> \u0438 <a href=\"http:\/\/habrahabr.ru\/post\/269793\/\">\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e<\/a> \u044d\u0442\u043e\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u043d\u0435\u0441 \u0441\u0432\u043e\u044e \u0441\u043a\u0440\u043e\u043c\u043d\u0443\u044e \u043b\u0435\u043f\u0442\u0443 \u0432 <a href=\"http:\/\/habrahabr.ru\/post\/270145\/\">Groovy Grape<\/a>. \u041d\u0435 \u0443\u043c\u0430\u043b\u044f\u044f \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432 Groovy, \u0432\u0441\u0435 \u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c java \u0432 \u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0433\u0434\u0435 \u0433\u0440\u0443\u0432\u0438 \u043d\u0430 jvm \u0432\u043d\u0435 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u0438 \u2014 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c java \u043a\u043e\u0434\u043e\u043c \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (\u0442\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 Grape).<\/p>\n<h2>\u041e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 Java. JSR 199<\/h2>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 JSR 199 \u2014 java Compiler API, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u0430\u0432\u043d\u043e. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b API \u043f\u0440\u0438\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 java \u043f\u0430\u043a\u0435\u0442\u0430\u0445 <b>javax.tools.*<\/b> \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c java \u043a\u043e\u0434 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0438\u0437\u0440\u044f\u0434\u043d\u043e <a href=\"http:\/\/blog.nobel-joergensen.com\/2008\/07\/16\/using-eclipse-compiler-to-create-dynamic-java-objects-2\/\">\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u0431\u0438\u0442\u044c \u0432 \u0431\u0443\u0431\u0435\u043d<\/a>. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0435 \u0438\u0434\u0435\u0442 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 JRE \u0438 tools.jar \u043d\u0435\u0442 \u0432 maven \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<h2>\u041a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0441 JSR 199<\/h2>\n<p>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0435, \u043d\u0435 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0430 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"http:\/\/unkrig.de\/w\/Janino\">Janino<\/a>. \u0421\u0430\u043c janino \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 java \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u0439. \u0415\u0441\u0442\u044c org.codehaus.janino:commons-compiler-jdk \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 JSR 199, \u043d\u043e \u0432\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 oracle\/openjdk tools.jar. \u041f\u043e\u0441\u043b\u0435 \u0432\u0435\u0447\u0435\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u043e\u043c \u043d\u0430 \u0441\u0432\u0435\u0442 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <a href=\"http:\/\/central.maven.org\/maven2\/com\/github\/igor-suhorukov\/janino-commons-compiler-ecj\/1.0\/janino-commons-compiler-ecj-1.0.jar\">janino-commons-compiler-ecj<\/a> (2,3 \u041c\u0411) \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f eclipse java compiler \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 \u043d\u0435\u0433\u043e commons-compiler-jdk. \u041e\u043d \u0441\u0430\u043c\u043e\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u0435\u043d \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u0430\u0436\u0435 \u0432 JRE. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 <a href=\"http:\/\/central.maven.org\/maven2\/com\/github\/igor-suhorukov\/mvn-classloader\/1.3\/mvn-classloader-1.3.jar\">mvn-classloader<\/a>, \u0442\u043e \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u043c\u0430\u0433\u0438\u044e \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438, \u043a\u0430\u043a \u0438 \u0432 Groovy Grape.<\/p>\n<p>  \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 <a href=\"http:\/\/central.maven.org\/maven2\/org\/mvel\/mvel2\/2.2.7.Final\/mvel2-2.2.7.Final.jar\">mvel2<\/a> (989 \u041a\u0411) \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u0432 \u043f\u0430\u0440\u0443 \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430, \u043d\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u0435\u0449\u0438 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 try\/catch\/finally \u0434\u0430 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0430 \u043d\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0430\u0434\u043e\u043c.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p>  \u0414\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043d\u0430 java \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c com.github.igor-suhorukov:janino-commons-compiler-ecj:1.0 \u0438 \u043b\u0438\u0448\u044c 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430:  <\/p>\n<pre><code class=\"java\">        SimpleClassPathCompiler simpleCompiler = new SimpleClassPathCompiler(dependenciesUrls);         simpleCompiler.cook(SCRIPT_NAME+&quot;.java&quot;, scriptSourceText);         Class&lt;?&gt; clazz   = simpleCompiler.getClassLoader().loadClass(SCRIPT_NAME); <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0431\u044b\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043b\u043e\u0432\u043d\u044b\u043c, \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e \u0447\u0442\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u043d\u0430 <a href=\"https:\/\/github.com\/igor-suhorukov\/janino-commons-compiler-ecj-example\">github<\/a>. \u0414\u043b\u044f \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f JVM \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 java8, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 Stream API.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c:  <\/p>\n<pre><code class=\"bash\">git clone https:\/\/github.com\/igor-suhorukov\/janino-commons-compiler-ecj-example.git cd janino-commons-compiler-ecj-example mvn test <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 PhantomJsDowloader \u0438\u0437 maven \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 com.github.igor-suhorukov:phantomjs-runner:1.1 \u0432\u044b\u0437\u043e\u0432\u0435\u043c MavenClassLoader \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c classpath \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e maven \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u0430:  <\/p>\n<pre><code class=\"java\">List&lt;URL&gt; urlsCollection = MavenClassLoader.usingCentralRepo().getArtifactUrlsCollection(&quot;com.github.igor-suhorukov:phantomjs-runner:1.1&quot;, null); new SimpleClassPathCompiler(urlsCollection); <\/code><\/pre>\n<p>  <b>janino-commons-compiler-ecj-example\/src\/test\/java\/org.codehaus.commons.compiler.jdk\/SimpleClassPathCompilerTest.java<\/b><\/p>\n<pre><code class=\"java\">package org.codehaus.commons.compiler.jdk;  import com.github.igorsuhorukov.codehaus.plexus.util.IOUtil; import com.github.igorsuhorukov.smreed.dropship.MavenClassLoader; import org.junit.Test;  import java.lang.reflect.Method; import java.net.URL; import java.util.List;  public class SimpleClassPathCompilerTest {      @Test     public void testClassloader() throws Exception {          final String SCRIPT_NAME = &quot;MyScript&quot;;         List&lt;URL&gt; urlsCollection = MavenClassLoader.usingCentralRepo().getArtifactUrlsCollection(&quot;com.github.igor-suhorukov:phantomjs-runner:1.1&quot;, null);          SimpleClassPathCompiler simpleCompiler = new SimpleClassPathCompiler(urlsCollection);         simpleCompiler.setCompilerOptions(&quot;-8&quot;);         simpleCompiler.setDebuggingInformation(true,true,true);          String src = IOUtil.toString(getClass().getResourceAsStream(String.format(&quot;\/%s.java&quot;, SCRIPT_NAME)));         simpleCompiler.cook(SCRIPT_NAME+&quot;.java&quot;, src);          Class&lt;?&gt; clazz   = simpleCompiler.getClassLoader().loadClass(SCRIPT_NAME);         Method main = clazz.getMethod(&quot;main&quot;, String[].class);         main.invoke(null, (Object) null);     }      public static void runIt(){         System.out.println(&quot;DONE!&quot;);     } } <\/code><\/pre>\n<p>  <b>janino-commons-compiler-ecj-example\/src\/test\/resources\/MyScript.java<\/b>  <\/p>\n<pre><code class=\"java\">import com.github.igorsuhorukov.phantomjs.PhantomJsDowloader; import com.github.igorsuhorukov.smreed.dropship.MavenClassLoader; import org.codehaus.commons.compiler.jdk.SimpleClassPathCompilerTest;  import java.util.Arrays; import java.util.List; import java.util.stream.Collectors;  public class MyScript{      public static void main(String[] args)  throws Exception{          class Wrapper{             private String value;              public Wrapper(String value) { this.value = value; }              public String getValue() { return value; }         }          SimpleClassPathCompilerTest.runIt();          List&lt;String&gt; res = Arrays.asList(new Wrapper(&quot;do&quot;), new Wrapper(&quot;something&quot;), new Wrapper(&quot;wrong&quot;)).stream().                                             map(Wrapper::getValue).collect(Collectors.toList());         System.out.println(String.join(&quot; &quot;,res));          System.out.println(&quot;Classes from project classpath. For example &quot;+MavenClassLoader.class.getName());          System.out.println(PhantomJsDowloader.getPhantomJsPath());     } } <\/code><\/pre>\n<p>  <b>pom.xml<\/b>  <\/p>\n<pre><code class=\"xml\">&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;          xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd&quot;&gt;      &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;     &lt;groupId&gt;com.github.igor-suhorukov&lt;\/groupId&gt;     &lt;artifactId&gt;janino-commons-compiler-ecj-example&lt;\/artifactId&gt;     &lt;packaging&gt;jar&lt;\/packaging&gt;     &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;     &lt;properties&gt;         &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;         &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;     &lt;\/properties&gt;     &lt;dependencies&gt;         &lt;dependency&gt;             &lt;groupId&gt;com.github.igor-suhorukov&lt;\/groupId&gt;             &lt;artifactId&gt;janino-commons-compiler-ecj&lt;\/artifactId&gt;             &lt;version&gt;1.0&lt;\/version&gt;             &lt;exclusions&gt;&lt;exclusion&gt;&lt;groupId&gt;*&lt;\/groupId&gt;&lt;artifactId&gt;*&lt;\/artifactId&gt;&lt;\/exclusion&gt;&lt;\/exclusions&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;com.github.igor-suhorukov&lt;\/groupId&gt;             &lt;artifactId&gt;mvn-classloader&lt;\/artifactId&gt;             &lt;version&gt;1.3&lt;\/version&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;junit&lt;\/groupId&gt;             &lt;artifactId&gt;junit&lt;\/artifactId&gt;             &lt;version&gt;4.12&lt;\/version&gt;             &lt;scope&gt;test&lt;\/scope&gt;         &lt;\/dependency&gt;     &lt;\/dependencies&gt; &lt;\/project&gt; <\/code><\/pre>\n<h2>Debug java \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h2>\n<p>  \u041e\u0442\u043b\u0430\u0434\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0430 java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0420\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u0447\u043a\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430 \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430:  <\/p>\n<pre><code class=\"java\">simpleCompiler.setDebuggingInformation(true,true,true); <\/code><\/pre>\n<p>  <iframe loading=\"lazy\" width=\"420\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/JSQ8aX-eLXk?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  \u041c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c java \u043a\u043e\u0434 \u0438\u0437 java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u0447\u0435\u043a. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0437 maven \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u0435\u0432 \u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u043a\u043e\u0434\u0430 \u0432 IDE.<\/p>\n<p>  \u041f\u043e\u0434\u0445\u043e\u0434 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c groovy \u0434\u043b\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 java \u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0432\u0440\u0430\u0436\u0434\u0435\u0431\u043d\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0433\u0440\u0443\u0432\u0438 \u0438 \u0441 \u044d\u0442\u0438\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0440\u043e AST\/\u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0447\u0442\u043e groovy \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0440\u0430\u0432\u044b, \u0432 java \u0441 \u044d\u0442\u0438\u043c \u043d\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0440\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 AST java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0430\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 &quot;<a href=\"http:\/\/habrahabr.ru\/post\/269129\/\">\u0420\u0430\u0437\u0431\u043e\u0440 Java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/a>&quot;. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0441 \u043c\u0435\u0442\u0440\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f\u0445<\/p>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430 \u00ab\u0447\u0438\u0441\u0442\u043e\u0439\u00bb java \u0438 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u043e\u0442\u0438\u0432\u044b, \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 <b>Java \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 Groovy<\/b>, \u0447\u0435\u043c \u00abJava \u043f\u0440\u043e\u0442\u0438\u0432 Groovy\u00bb.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/273683\/\"> http:\/\/habrahabr.ru\/post\/273683\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412\u0434\u0440\u0443\u0433 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0443\u0436\u043d\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0438\u043b\u0438 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f? <br \/>  \u041d\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0433\u0440\u0443\u0432\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u044c\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441 \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u0438\u0432\u043e\u043c. \u0418 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0435\u0449\u0435 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u043f\u0440\u0438\u0447\u0438\u043d \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0433\u0440\u0443\u0432\u0438 \u0432 \u043a\u043e\u0434. \u0425\u043e\u0442\u044c groovy \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u043b\u0438\u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u0437\u043d\u0430\u044e\u0449\u0435\u043c\u0443 java, \u0447\u0435\u043c \u0442\u0430 \u0436\u0435 scala. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/869\/d88\/762\/869d88762a294e60a72ad3942253e957.png\"\/><\/p>\n<p>  \u041d\u043e \u0434\u0430\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c java \u043a\u043e\u0434 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0432 jvm. \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442. \u0414\u0430 \u0438 \u0435\u0449\u0435 \u0431\u044b \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u0434\u0435\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c tools.jar \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u0433\u0440\u0430\u043c\u043c\u0435.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-270891","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/270891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=270891"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/270891\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=270891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=270891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=270891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}