Support / Discussion for CheerpJ has been migrated to Discord https://discord.leaningtech.com
Hi.
I'm testing a executable jar which uses *javax.imageio.ImageIO" to read image files. When I deploy it on the web, it failed to display any graphics. And I find command line logs like this:
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] code 404, message File not found
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] "HEAD /META-INF/services/javax.imageio.spi.ImageOutputStreamSpi HTTP/1.1" 404 -
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] code 404, message File not found
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] "HEAD /META-INF/services/javax.imageio.spi.ImageReaderSpi HTTP/1.1" 404 -
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] code 404, message File not found
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] "HEAD /META-INF/services/javax.imageio.spi.ImageWriterSpi HTTP/1.1" 404 -
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] code 404, message File not found
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] "HEAD /META-INF/services/javax.imageio.spi.ImageTranscoderSpi HTTP/1.1" 404 -
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] code 404, message File not found
::ffff:127.0.0.1 - - [13/Jul/2022 12:55:06] "HEAD /META-INF/services/javax.imageio.spi.ImageInputStreamSpi HTTP/1.1" 404 -
Does it means javax.imageio.ImageIO is not supported? How can I fix the problem? I'm using Java 8 and CheerpJ 2.3
Hello,
Should I expect, that I can compile pretty much all jar
to js, using CheerpJ
?
Today I decided to try this solution. I created a simple app with lucene-core:9.3.0
. When I compile my jar
, I see the following log:
~/cheerpj_2.3$ python3 ./cheerpjfy.py /mnt/c/Users/povaloh830/IdeaProjects/Test-Java11/build/libs/Test-Java11-1.0-SNAPSHOT.jar
Compiling jar /mnt/c/Users/povaloh830/IdeaProjects/Test-Java11/build/libs/Test-Java11-1.0-SNAPSHOT.jar
compiling Main.class ...
Failure compiling Main.class
command: /home/povaloh830/cheerpj_2.3/bin/cheerpj -llvm -llvm-exceptions -cp /tmp/tmp_sadxwot/rt.jar.dir/ Main.class
Using legacy codegen for Main.class
But in the end I get my js
file. Than I use html
page from https://docs.leaningtech.com/cheerpj/Tutorial and try to run it. I get the following log:
CheerpJ is initializing
CheerpJ runtime ready
Unhandled exception N4java4lang20NullPointerException / loader.js:2403:12
Uncaught (in promise) org/apache/lucene/analysis/standard/StandardAnalyzer loader.js:551:28
Of course, I can run this program, when I use regular JVM.
The code of program:
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
static StandardAnalyzer analyzer = new StandardAnalyzer();
static Directory memoryIndex = new ByteBuffersDirectory();
public static List<Document> searchIndex(String inField, String queryString) throws ParseException, IOException {
Query query = new QueryParser(inField, analyzer)
.parse(queryString);
IndexReader indexReader = DirectoryReader.open(memoryIndex);
IndexSearcher searcher = new IndexSearcher(indexReader);
TopDocs topDocs = searcher.search(query, 10);
List<Document> documents = new ArrayList<>();
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
documents.add(searcher.doc(scoreDoc.doc));
}
return documents;
}
public static void main(String[] args) throws IOException, ParseException {
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
IndexWriter writter = new IndexWriter(memoryIndex, indexWriterConfig);
Document document = new Document();
document.add(new TextField("title", "title", Field.Store.YES));
document.add(new TextField("body", "bodyefw", Field.Store.YES));
writter.addDocument(document);
writter.close();
List<Document> documents = searchIndex("title", "title");
System.out.println(documents.get(0).get("body"));
}
}
P.S. I also tried to run hello world app, and it works fine.
lucene-core
from 9.3.0
to 8.11.2
. After this change, I've managed to run my program with regular JVM. However, I am still getting the same error, when run it from browser (loader.js:551 Uncaught (in promise) org/apache/lucene/analysis/standard/StandardAnalyzer
)
Well, I did a few steps:
for f in lucene-queries-8.11.2.jar lucene-sandbox-8.11.2.jar lucene-core-8.11.2.jar lucene-queryparser-8.11.2.jar
do
~/cheerpj_2.3/cheerpjfy.py --deps lucene-queries-8.11.2.jar:lucene-sandbox-8.11.2.jar:lucene-core-8.11.2.jar:lucene-queryparser-8.11.2.jar $f
done
python3 ~/cheerpj_2.3/cheerpjfy.py --deps /mnt/c/Users/povaloh830/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-queryparser/8.11.2/1886e3a27a8d4a73eb8fad54ea93a160b099bc60/lucene-queryparser-8.11.2.jar:/mnt/c/Users/povaloh830/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-core/8.11.2/57438c3f31e0e440de149294890eee88e030ea6d/lucene-core-8.11.2.jar:/mnt/c/Users/povaloh830/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-queries/8.11.2/c86c8bbd6dddfb6870fc2f59989cb89d50290d5a/lucene-queries-8.11.2.jar:/mnt/c/Users/povaloh830/.gradle/caches/modules-2/files-2.1/org.apache.lucene/lucene-sandbox/8.11.2/5ff823b4a429ccf842386a008b08bddfa88d9f87/lucene-sandbox-8.11.2.jar /mnt/c/Users/povaloh830/IdeaProjects/Test-Java11/build/libs/Test-Java11-1.0-SNAPSHOT.jar
cheerpjRunMain("Main", "/app/Test-Java11-1.0-SNAPSHOT.jar:/app/lucene-queries-8.11.2.jar:/app/lucene-sandbox-8.11.2.jar:/app/lucene-core-8.11.2.jar:/app/lucene-queryparser-8.11.2.jar");
$ ls *.js
Test-Java11-1.0-SNAPSHOT.jar.js lucene-queries-8.11.2.jar.js lucene-sandbox-8.11.2.jar.js
lucene-core-8.11.2.jar.js lucene-queryparser-8.11.2.jar.js
Now I get one more line of logs, but at the end of story I am still getting errror, another one:
CheerpJ is initializing
CheerpJ runtime ready
Run main for Main <-- new one
loader.js:2447 Uncaught (in promise)
sorry for name of project, I switched to jdk8, but didn't change names.
lib jars:
app:
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
</head>
<body>
</body>
<script>
cheerpjInit();
cheerpjRunMain("Main", "/app/Test-Java11-1.0-SNAPSHOT.jar:/app/lucene-queries-8.11.2.jar:/app/lucene-sandbox-8.11.2.jar:/app/lucene-core-8.11.2.jar:/app/lucene-queryparser-8.11.2.jar");
</script>
</html>
async cheerpJWarmStartTests({ commit, state }) {
console.info("warm starting tests");
// Store console logs in a global buffer called console.logs
if (state.cheerpJ.warmStarted) {
console.info("already started");
return;
}
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function () {
let args = Array.from(arguments);
// OPTIONAL: Filtering on which messages are stored in console.logs
// if (String(args[0]).includes("WARM")) {
// console.logs.push(args);
// }
console.logs.push(args);
console.stdlog.apply(console, arguments);
};
commit("INCREMENT_CHEERPJ_PACKAGE_ID");
var packageName = "javafiddle" + state.cheerpJ.packageId.toString();
cheerpjAddStringFile(
"/str/Main.java",
"package " +
packageName +
'; public class Main {public static void main(String[] args) {System.out.print("Hello World!");}}'
);
cheerpjAddStringFile(
"/str/MainTest.java",
"package " +
packageName +
'; \
import java.io.ByteArrayOutputStream; \
import java.io.PrintStream; \
import org.junit.jupiter.api.Assertions; \
import org.junit.jupiter.api.Test; \
import org.junit.jupiter.api.AfterEach; \
public class MainTest { \
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); \
private final PrintStream originalOut = System.out; \
@Test public void testOutput() { \
System.setOut(new PrintStream(outContent)); \
Main.main(new String[0]); \
Assertions.assertEquals("Hello World!", outContent.toString()); \
} \
@AfterEach \
public void tearDown() { \
System.setOut(originalOut); \
} \
}'
);
console.logs.length = 0;
cheerpjRunMain(
"com.sun.tools.javac.Main",
"/app/tools.jar:/files/:/app/junit-platform-console-standalone-1.8.2.jar",
"-cp",
"/app/junit-platform-console-standalone-1.8.2.jar",
"/str/MainTest.java",
"/str/Main.java",
"-d",
"/files/"
)
.then((r) => {
console.info("THEN");
console.info(r);
// Non-zero exit code means that an error has happened
if (r == 0) {
cheerpjRunMain(
"org.junit.platform.console.ConsoleLauncher",
"/app/junit-platform-console-standalone-1.8.2.jar",
"--classpath",
"/files/",
"-c",
packageName + ".MainTest"
).then(() => {
commit("SET_CHEERPJ_WARM_STARTED");
console.logs.length = 0;
});
}
})
.catch((r) => {
console.info("CATCH");
console.info(r);
})
.finally(() => {
console.info("FINALLY");
});
}