Git Product home page Git Product logo

Comments (4)

potoo0 avatar potoo0 commented on July 28, 2024

it seems jshell not load any annotation processor (such as lombok and mapstruct, etc).

https://bugs.openjdk.java.net/browse/JDK-8213600

from ijava.

potoo0 avatar potoo0 commented on July 28, 2024

We can compile source code in shell, then import those bytecode class files:

  1. edit java source code, eg TestVO:

    package vo;
    
    @lombok.Data
    public class TestVO {
        private String name;
        private Integer age;
    }
  2. download lombok.jar(https://projectlombok.org/downloads/lombok.jar) to libs;

  3. compile: cd vo; javac -cp libs/lombok.jar TestVO.java;

  4. add to classpath, eg: add vo parent folder to env's IJAVA_CLASSPATH(restart jupyter):
    export IJAVA_CLASSPATH="/home/jupyter/notebooks/0-Java:$IJAVA_CLASSPATH";

  5. import in jupyter cell, eg: import vo.*;

from ijava.

xdewx avatar xdewx commented on July 28, 2024

Very useful.
But it seems a little troublesome. It will be great if ijava-kernel could compile and setup by itself.
Thank u for your reply.

from ijava.

potoo0 avatar potoo0 commented on July 28, 2024

We could compile at runtime by ourselves.

eg:

// 1. compiler output, use System.err if null
StringWriter out = new StringWriter();
// 2. a diagnostic listener; if null use the compiler's default method for reporting diagnostics
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
// 3. a file manager; if null use the compiler's standard file manager
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
// 4. compiler options, null means no options
List<String> options = buildCompileOptions(compileOptions);
// 5. the compilation units to compile, null means no compilation units
Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjectsFromFiles(Collections.singletonList(sourceFile));

CompilationTask task = compiler.getTask(out, fileManager, diagnostics, options, null, compilationUnit);
Boolean isCompileSuccess = task.call();
fileManager.close();

I built a cell magic for compile, here is source code:

  1. compile utils: RuntimeCompiler
  2. cell magic: CompilerMagics
  3. usage:
    image

from ijava.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.