Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeaVM: how to compile jar to javascript? #296

Closed
jsfan3 opened this issue Aug 7, 2017 · 5 comments
Closed

TeaVM: how to compile jar to javascript? #296

jsfan3 opened this issue Aug 7, 2017 · 5 comments

Comments

@jsfan3
Copy link

jsfan3 commented Aug 7, 2017

Thank you very much for developing TeaVM!

TeaVM aims to make "java bytecode" to "javascript" easy, so I suppose that converting a Java app composed by three jars to a web app should be easy.

The problem is that I didn't find in the TeaVM documentation any help. I need step by step instructions, I've never used Maven before and I'd like to automatize "jar to web app" with scripting.

Thank you very much for any help :-)

@konsoletyper
Copy link
Owner

konsoletyper commented Aug 7, 2017

The one possibility is: install these jar files into Maven local repository. Another is to use system scope for your dependencies (this is deprecated in modern Maven). See this question on StackOverflow.

@jsfan3
Copy link
Author

jsfan3 commented Aug 7, 2017

My java app is composed by these three files:
Main.jar
lib/app.jar
lib/JavaSEClean.jar

and I can run it with
java -jar Main.jar

In the directory "webapp", inside my home directory, I've done:

mvn -DarchetypeCatalog=local
-DarchetypeGroupId=org.teavm
-DarchetypeArtifactId=teavm-maven-webapp
-DarchetypeVersion=0.5.0
archetype:generate

Define value for property 'groupId': com.mycompany.demos
Define value for property 'artifactId': my-first-app
Define value for property 'version': 0.1
Define value for property 'package': com.mycompany.demos

Then, according to the StackOverflow discussion you mentioned, I added the following lines to my-first-app/pom.xml:

<dependency>
<!-- My App Main file -->
<groupId>com.mycompany.demos</groupId>
<artifactId>my-first-app</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>/home/francesco/app/Main.jar</systemPath>
</dependency>

<dependency>
<!-- My App library file 1 -->
<groupId>com.mycompany.demos</groupId>
<artifactId>my-first-app-lib1</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>/home/francesco/app/lib/app.jar</systemPath>
</dependency>

<dependency>
<!-- My App library file 2 -->
<groupId>com.mycompany.demos</groupId>
<artifactId>my-first-app-lib2</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>/home/francesco/app/lib/JavaSEClean.jar</systemPath>
</dependency>

I also changed the line "com.mycompany.demos.Client" with the mainClass specified in the file /META-INF/MANIFEST.MF inside Main.jar

I removed the directory that contains source code, because in this case it's not used:
rm -Rf ./my-first-app/src/main/java

Finally:
cd my-first-app
mvn -e clean package

It worked for a while, downloading a lot of files, then it ends with the error in the attached log. I'm a newbie of Maven and TeaVM, please help me. Thank you very much.

log.txt

@konsoletyper
Copy link
Owner

I don't have your project, I event don't know what is your pom.xml, that's why I can't tell why TeaVM does not report errors properly. However, from the information in your log file, I can tell that you have to give up! Looks like your jar file uses parts of Java class library unsupported by TeaVM, java.security.AccessController, sun.awt.DebugSettings in particular. You won't be able to compile this application without modification, and, since you don't have source files, you can't modify it. You better look at another project that matches your use-case, like Doppio or CheerpJ. TeaVM merely was not designed for that. TeaVM is mostly replacement for GWT, it's useful for creating small and fast webapps from scratch, not for running fat applets without rewriting the code.

@jsfan3
Copy link
Author

jsfan3 commented Aug 7, 2017

Thank you, I realized what you wrote.

@jsfan3 jsfan3 closed this as completed Aug 7, 2017
@TorutheRedFox
Copy link

TorutheRedFox commented Aug 16, 2021

since you don't have source files, you can't modify it.

if it's not obfuscated, you can without much difficulty ;P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants