- 浏览: 2488359 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Build the iOS Things with J2Objc
1. Install the J2Objc
Get the latest file from here https://j2objc.googlecode.com/files/j2objc-0.7.zip.
Unzip and put in the tool directory. Link it to the work directory.
>cd /opt
>sudo ln -s /Users/carl/tool/j2objc-0.7 ./j2objc-0.7
>sudo ln -s ./j2objc-0.7 ./j2objc
Add that directory to the bash path
>vi ~/.profile
export PATH=/opt/j2objc:$PATH
>. ~/.profile
2. Try the Sample
Follow the document, try a JAVA class hello world.
public class Hello {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
Compile the Java source code
>javac Hello.java
I got the class file Hello.class
Run the java class file based on JVM
>java Hello
Translate the JAVA source code to Object-C
>j2objc Hello.java
translating Hello.java
Translated 1 file: 0 errors, 0 warnings
I got 2 files, Hello.m and Hello.m
Compile the Object C source codes
>j2objcc -c Hello.m
Then there is a Hello.o file then.
Generate the executable file
>j2objcc -o hello Hello.o
Then there is a executable file named hello
Try to run that
>./hello
2013-04-11 13:52:44.019 hello[41640:707] hello, world
3. How to make that work with Maven
<build>
...
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <inherited>false</inherited> <executions> <execution> <id>gen-objc</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>./gen-objc.sh</executable> <arguments> <argument>${project.artifactId}</argument> </arguments> </configuration> </execution> </executions>
</plugin>
</build>
This make the execution of the shell script during the package phase
>mvn package
Here are the shell script gen-objc.sh
#!/bin/bash
# call this shell script with the project artifactId
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` artifactId"
exit
fi
ARTIFACT_ID=$1
J2OBJC_OUT_DIR=gen-objc
SRC=target/${ARTIFACT_ID}-*-sources.jar
J2OBJCFLAGS="--no-package-directories -use-arc --prefixes sdk-core-prefixes.properties"
# Set this to point to j2objc home
J2OBJC_DISTRIBUTION=/opt/j2objc
J2OBJC=${J2OBJC_DISTRIBUTION}/j2objc
if [ ! -e "$J2OBJC" ]; then
echo "***************************************************"
echo "***************************************************"
echo " ERROR ... ERROR ... "
echo " --> could not find ${J2OBJC} "
echo " please install before continuing..."
echo "***************************************************"
echo "***************************************************"
exit
fi
rm -rf ${J2OBJC_OUT_DIR}
${J2OBJC} -d ${J2OBJC_OUT_DIR} ${J2OBJCFLAGS} ${SRC};
cd ${J2OBJC_OUT_DIR}
rm I*.m
for y in `ls *`;
do
sed -f ../objc_post_processing.sed $y > temp; mv temp $y;
done
# this is the customer things, if you do not need that, that is fine
# Replace SxxError with NSError *
rm SxxError.h
cd ..
In the file, sdk-core-prefixes.properties, they are the packages I think.
com.sillycat.easyrestapi.core:
com.sillycat.easyrestapi.core.impl:
Something like that.
For the file objc_post_pressing.sed, that maybe just get rid of some lines in the source codes.
# 0. generic preprocessing .. remove comments..
s/\(\/\/.*Created by \).*/\1 Xxxxxxx Compiler/g
# 1. j2objc generates fooWithNSString:(NSString *)name; for Java method
# foo(String name). We want foo:(NSString *)name;
s/With.*:(/:(/g
# 2. Replace JavaUtilDate with NSDate
s/JavaUtilDate/NSDate/g
s_#import "java/util/Date.h"__g
s/@class NSDate;//g
# 3. Replace JavaUtilList with NSArray *
s/id<JavaUtilList>/NSArray */g
s_#import "java/util/List.h"__g
s/@protocol JavaUtilList;//g
# 4. Replace JavaUtilSet with NSSet *
s/id<JavaUtilSet>/NSSet */g
s_#import "java/util/Set.h"__g
s/@protocol JavaUtilSet;//g
# 5. Replace XxxxxError with NSError *
s/id<XxxxxError>/NSError */g
s/@protocol XxxxxError;//g
# 6. Remove JreEmulation
s/#import "JreEmulation.h"//g
# 7. Replace 'withXxx' with 'with'
s/withXxx/with/g
4. Eclipse Plugin
http://j2objc-updatesite.hsapkota.com.au/4.2
Choose the directory of the installation j2obc and select a output directory. It works.
References:
https://code.google.com/p/j2objc/
http://hsapkota.com.au/index.php/projects/20-j2objc-eclipse-plugin-howto
1. Install the J2Objc
Get the latest file from here https://j2objc.googlecode.com/files/j2objc-0.7.zip.
Unzip and put in the tool directory. Link it to the work directory.
>cd /opt
>sudo ln -s /Users/carl/tool/j2objc-0.7 ./j2objc-0.7
>sudo ln -s ./j2objc-0.7 ./j2objc
Add that directory to the bash path
>vi ~/.profile
export PATH=/opt/j2objc:$PATH
>. ~/.profile
2. Try the Sample
Follow the document, try a JAVA class hello world.
public class Hello {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
Compile the Java source code
>javac Hello.java
I got the class file Hello.class
Run the java class file based on JVM
>java Hello
Translate the JAVA source code to Object-C
>j2objc Hello.java
translating Hello.java
Translated 1 file: 0 errors, 0 warnings
I got 2 files, Hello.m and Hello.m
Compile the Object C source codes
>j2objcc -c Hello.m
Then there is a Hello.o file then.
Generate the executable file
>j2objcc -o hello Hello.o
Then there is a executable file named hello
Try to run that
>./hello
2013-04-11 13:52:44.019 hello[41640:707] hello, world
3. How to make that work with Maven
<build>
...
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <inherited>false</inherited> <executions> <execution> <id>gen-objc</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>./gen-objc.sh</executable> <arguments> <argument>${project.artifactId}</argument> </arguments> </configuration> </execution> </executions>
</plugin>
</build>
This make the execution of the shell script during the package phase
>mvn package
Here are the shell script gen-objc.sh
#!/bin/bash
# call this shell script with the project artifactId
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` artifactId"
exit
fi
ARTIFACT_ID=$1
J2OBJC_OUT_DIR=gen-objc
SRC=target/${ARTIFACT_ID}-*-sources.jar
J2OBJCFLAGS="--no-package-directories -use-arc --prefixes sdk-core-prefixes.properties"
# Set this to point to j2objc home
J2OBJC_DISTRIBUTION=/opt/j2objc
J2OBJC=${J2OBJC_DISTRIBUTION}/j2objc
if [ ! -e "$J2OBJC" ]; then
echo "***************************************************"
echo "***************************************************"
echo " ERROR ... ERROR ... "
echo " --> could not find ${J2OBJC} "
echo " please install before continuing..."
echo "***************************************************"
echo "***************************************************"
exit
fi
rm -rf ${J2OBJC_OUT_DIR}
${J2OBJC} -d ${J2OBJC_OUT_DIR} ${J2OBJCFLAGS} ${SRC};
cd ${J2OBJC_OUT_DIR}
rm I*.m
for y in `ls *`;
do
sed -f ../objc_post_processing.sed $y > temp; mv temp $y;
done
# this is the customer things, if you do not need that, that is fine
# Replace SxxError with NSError *
rm SxxError.h
cd ..
In the file, sdk-core-prefixes.properties, they are the packages I think.
com.sillycat.easyrestapi.core:
com.sillycat.easyrestapi.core.impl:
Something like that.
For the file objc_post_pressing.sed, that maybe just get rid of some lines in the source codes.
# 0. generic preprocessing .. remove comments..
s/\(\/\/.*Created by \).*/\1 Xxxxxxx Compiler/g
# 1. j2objc generates fooWithNSString:(NSString *)name; for Java method
# foo(String name). We want foo:(NSString *)name;
s/With.*:(/:(/g
# 2. Replace JavaUtilDate with NSDate
s/JavaUtilDate/NSDate/g
s_#import "java/util/Date.h"__g
s/@class NSDate;//g
# 3. Replace JavaUtilList with NSArray *
s/id<JavaUtilList>/NSArray */g
s_#import "java/util/List.h"__g
s/@protocol JavaUtilList;//g
# 4. Replace JavaUtilSet with NSSet *
s/id<JavaUtilSet>/NSSet */g
s_#import "java/util/Set.h"__g
s/@protocol JavaUtilSet;//g
# 5. Replace XxxxxError with NSError *
s/id<XxxxxError>/NSError */g
s/@protocol XxxxxError;//g
# 6. Remove JreEmulation
s/#import "JreEmulation.h"//g
# 7. Replace 'withXxx' with 'with'
s/withXxx/with/g
4. Eclipse Plugin
http://j2objc-updatesite.hsapkota.com.au/4.2
Choose the directory of the installation j2obc and select a output directory. It works.
References:
https://code.google.com/p/j2objc/
http://hsapkota.com.au/index.php/projects/20-j2objc-eclipse-plugin-howto
发表评论
-
ionic UI(5)UI and Backend
2016-12-02 03:22 564ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 865Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 947Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 943IOS7 App Development Essentia ... -
IOS7 App Development Essentials(3)NSUserDefaults
2014-04-11 02:58 969IOS7 App Development Essentia ... -
IPhone and Location(2)Documents Region Monitoring and Region Sample
2013-10-18 05:10 1698IPhone and Location(2)Documents ... -
IPhone and Location(1)Documents User Location
2013-10-18 03:50 1278IPhone and Location(1)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 895Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 967Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 907Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 992Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 926Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1076Learn Object C(1) Learn Objec ... -
APNS(4)Recall the Process and Learn Java APNS
2013-04-18 02:48 3430APNS(4)Recall the Process and L ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1608APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1500APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1266Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1062Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1288MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1892Android Talker(1)MAC Environmen ...
相关推荐
赠送jar包:j2objc-annotations-1.1.jar; 赠送原API文档:j2objc-annotations-1.1-javadoc.jar; 赠送源代码:j2objc-annotations-1.1-sources.jar; 赠送Maven依赖信息文件:j2objc-annotations-1.1.pom; 包含...
如果无法运行 查看J2OBJC_HOME是否正确; 查看Build Phases中的JRE.framework是否引入 相关的博客 http://blog.csdn.net/coooliang/article/details/79346001
赠送jar包:j2objc-annotations-1.3.jar; 赠送原API文档:j2objc-annotations-1.3-javadoc.jar; 赠送源代码:j2objc-annotations-1.3-sources.jar; 赠送Maven依赖信息文件:j2objc-annotations-1.3.pom; 包含...
赠送jar包:j2objc-annotations-1.1.jar; 赠送原API文档:j2objc-annotations-1.1-javadoc.jar; 赠送源代码:j2objc-annotations-1.1-sources.jar; 赠送Maven依赖信息文件:j2objc-annotations-1.1.pom; 包含...
The type com.google.j2objc.annotations.ReflectionSupport$Level cannot be resolved. It is indirectly referenced from required .class files
该文件为J2OBJC的demo,可以将Java功能模块转化为OC的代码。
Gradle依赖:【***.jar Gradle依赖信息(可用于项目build.gradle).txt】 源代码下载地址:【***-sources.jar下载地址(官方地址+国内镜像地址).txt】 # 本文件关键字: 中文-英文对照文档,中英对照文档,java,jar包...
java运行依赖jar包
只用来下载WSDL2Objc第三方开发代码包的,用于iOS的websevrice
这是一个示例,展示了如何在使用 J2ObjC 的 iOS 应用程序中使用黑白棋游戏引擎。 最初的游戏奥赛罗由 Mats Luthman 编写,可从 他的网站获得。Mats 将其设计为既可以用作 Swing 应用程序,也可以用作命令行应用程序...
可直接将java语言翻译成obj-c语言工具
J2objc入门套件入门工具包是使用入门的好方法。 它包括一个简单的演示,向您... 假设在Mac上, $ln -s /path_to/j2objc/dist/j2objc /usr/bin/j2bjc$ln -s /path_to/j2objc/dist/j2objcc /usr/bin/j2objcc 通过键入以下
这是关于如何在 Xcode 中将 J2ObjC 设置为静态库的分步指南。 完成本指南后,您将能够在 Xcode 中设置 j2objc 并准备好工作。 共享的 java 文件被添加到 Xcode 中进行跟踪,它们生成的代码被编译到一个静态库中,并...
使用j2objc实现iOS调java的demo
github地址: https://github.com/LLSkittles/cocos2d-iphone-demo
j2objc:Java转成Objective-C的用于移植Android库到iOS
j2objc-匕首 使用 J2Objc 对 Dagger2 进行测试翻译 笔记 您必须将 bash 文件中的正确路径设置为 j2objc 的正确位置。
J2ObjC Gradle插件使Java源代码成为iOS应用程序构建的一部分,因此您可以用Java编写应用程序的非UI代码(例如应用程序逻辑和数据模型),然后由Android应用程序(本机为Java)和iOS共享应用程序(使用J2ObjC)。...
Java转Objective-C工具 J2ObjC ,J2ObjC 是一个来自 Google 的开源命令行工具,用于将 Java 代码转成 iOS 平台上...