创建 frege.jar 并包括中间 .java 文件(用于 J2ObjC)
Creating frege.jar and including intermediate .java files (for use with J2ObjC)
有没有办法将 Frege 运行时和库编译成它们的 .java 中间体?我正在尝试通过 J2ObjC 将弗雷格用作 iOS 应用程序的一部分,它无法解析 .class 文件。
根据一些测试,以下将起作用:
# get the project
git clone https://github.com/Frege/frege.git
cd frege
# make a current frege compiler available and build a new one
cp ~/Downloads/frege3.23.370*.jar fregec.jar
make runtime fregec.jar
# optionally, remove the class files
find build/ -type f -name '*.class' -exec rm {} ';'
此时,您在 fregec.jar
中有一个可运行的编译器,java 源对应于 build/frege/
下那个 jar 中的 类
重要的是,您仅将 此编译器 与您自制的 java 源一起使用。因为,假设 foo
在某些模块中已被替换为 bar
,并且您的 frege 源代码引用了 foo
。然后你可以用一个旧的 fregec.jar 编译它,但是你不能编译生成的 java 文件(其中仍然有 foo
)和你的 java 源代码在那里没有foo
,只有bar
.
除此之外,您现在可以根据需要随时使用这些资源来创建独立的 frege library/application。
下面我将介绍如何制作独立的控制台应用程序,请根据您的需要进行调整。假设是:
- 项目在兄弟目录中
standalone
- 主要功能在模块
my.fine.App
中
我们开始:
# go to project directory and make a directory for the generated code
cd ../standalone
mkdir -p generated
# compile the Frege code into generated/
java -jar ../fregec.jar -d generated -O -make my/fine/App.fr
# at this point, we could already run it, but had to supply fregec.jar
# in the classpath.
java -cp generated/:../fregec.jar my.fine.App
# remove class files
find generated/ -type f -name '*.class' -exec rm {} ';'
# now generate minimal standalone code, the idea being that javac
# gets the source files it needs automatically
javac -d bin -sourcepath generated:../frege:../frege/build generated/my/fine/App.java
java -cp bin my.fine.App
# jar it up
jar -cvf App.jar -C bin .
jar -uvfe App.jar my.fine.App
java -jar App.jar
Ingo 的回答非常适合创建 Java 中间文件。
只是想添加我自己的答案以澄清 Frege 有很多与 J2ObjC 不兼容的依赖项,因此不能与 J2ObjC 一起使用。
有没有办法将 Frege 运行时和库编译成它们的 .java 中间体?我正在尝试通过 J2ObjC 将弗雷格用作 iOS 应用程序的一部分,它无法解析 .class 文件。
根据一些测试,以下将起作用:
# get the project
git clone https://github.com/Frege/frege.git
cd frege
# make a current frege compiler available and build a new one
cp ~/Downloads/frege3.23.370*.jar fregec.jar
make runtime fregec.jar
# optionally, remove the class files
find build/ -type f -name '*.class' -exec rm {} ';'
此时,您在 fregec.jar
中有一个可运行的编译器,java 源对应于 build/frege/
下那个 jar 中的 类
重要的是,您仅将 此编译器 与您自制的 java 源一起使用。因为,假设 foo
在某些模块中已被替换为 bar
,并且您的 frege 源代码引用了 foo
。然后你可以用一个旧的 fregec.jar 编译它,但是你不能编译生成的 java 文件(其中仍然有 foo
)和你的 java 源代码在那里没有foo
,只有bar
.
除此之外,您现在可以根据需要随时使用这些资源来创建独立的 frege library/application。
下面我将介绍如何制作独立的控制台应用程序,请根据您的需要进行调整。假设是:
- 项目在兄弟目录中
standalone
- 主要功能在模块
my.fine.App
中
我们开始:
# go to project directory and make a directory for the generated code
cd ../standalone
mkdir -p generated
# compile the Frege code into generated/
java -jar ../fregec.jar -d generated -O -make my/fine/App.fr
# at this point, we could already run it, but had to supply fregec.jar
# in the classpath.
java -cp generated/:../fregec.jar my.fine.App
# remove class files
find generated/ -type f -name '*.class' -exec rm {} ';'
# now generate minimal standalone code, the idea being that javac
# gets the source files it needs automatically
javac -d bin -sourcepath generated:../frege:../frege/build generated/my/fine/App.java
java -cp bin my.fine.App
# jar it up
jar -cvf App.jar -C bin .
jar -uvfe App.jar my.fine.App
java -jar App.jar
Ingo 的回答非常适合创建 Java 中间文件。 只是想添加我自己的答案以澄清 Frege 有很多与 J2ObjC 不兼容的依赖项,因此不能与 J2ObjC 一起使用。