1

I'm attempting to transpile Java model classes to JavaScript using JSweet. The model classes contain JPA annotations like @Column. The transpilation fails as soon as it encounters import javax.persistence.Column. The JPA annotations are irrelevant in JavaScript and should not be transpiled. Can this be done without changing the Java code?

More generally, is there a way to have JSweet ignore import statements, e.g., when all references to the imported packages are in @Erased methods?

warakawa
  • 628
  • 1
  • 7
  • 14

1 Answers1

0

Normally, JSweet just erases unknown annotations, so your code should transpile fine.

First thing to check: do you have a JPA jar in your classpath or in your Maven dependencies? JSweet uses javac, which requires all types to be in the classpath. I guess that the @Column annotation should be in there: https://mvnrepository.com/artifact/javax.persistence/persistence-api/1.0.2

As for the second part of your question, JSweet v2 provides an API to tune the generation of the code. See the specs. In the PrinterAdapter API, you can override the needsImport method to return null when the import is not needed. However I believe that you don't need this for your case since annotations are erased automatically.

Renaud Pawlak
  • 531
  • 5
  • 7
  • Thank you. Indeed, I forgot to mention javax.persistence in the pom, since we're not using Maven for the regular build process. Is the Eclipse plugin the only alternative if I don't want to use Maven? – warakawa Sep 18 '17 at 13:58
  • You can also use Ant with the command line launcher. I think that there is a build.xml in the jsweet-examples projet: https://github.com/cincheo/jsweet-examples (but you can handle your dependencies manually rather than with Maven). – Renaud Pawlak Sep 19 '17 at 14:17