PLM之家PLMHome-工业软件践行者

[原创] 使用eclipse进行NX二次开发的设置步骤

[复制链接]

2015-2-25 13:02:01 4955 0

2471

主题

1276

回帖

8万

积分

管理员

PLM之家站长

积分
82195
QQ
发表于 2015-2-25 13:02:01 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
DebUGging NXOpen Java with NX8 and Eclipse IDE
9 n  W, [, L  T# l- r, l! p1 M$ O9 V& Q% d& l
(see PDF in the ZIP file for a pictorial description)) M' |3 M+ o- j3 Q

) s# A6 @( |4 X& G) gInstallation of Java and Eclipse  x$ Y* |6 J. i, m
; P9 b8 }, X+ k8 y
1)$ s, y7 ^; d% C  z2 ~; J
Download and install the Java Standard Edition Developer Kit Java SE 6 (1.6.0_14 or higher) from, t0 U& q, C; Q( W
http://www.oracle.com/technetwor ... ownloads/index.html % w; q; @* j6 \! y2 n  Q

& A, m2 f5 @- w' I  S7 k& I2)$ m6 P* O( |+ K& {+ b! H4 t
Download the Eclipse IDE for Java Developers from http://www.eclipse.org/downloads
, K( \7 y& _1 U$ Xand extract the ZIP and its ‘eclipse’ directory content to your preferred path, for example “d:\eclipse”9 i6 S# ]8 P8 I  `/ k4 X

: `! _6 Y0 W& H- @1 w; G
4 b1 r% |% M5 G# m4 ~' f% `Create a project with Eclipse   # U' w; S9 ]" ~0 D+ U6 S
$ k# |9 c, h0 `6 ^( ^
3)4 p6 Z4 S* v# b% x0 V* u, S
Start the Eclipse IDE, for example “d:\eclipse\eclipse.exe”, z) b4 L! P8 W- l

5 ~9 v) h& f4 _- ]; c% t/ I# H4)
1 ~1 b6 U0 y5 U/ L- hYou will be asked for the location of your Workspace folder which is comparable to the MyProjects folder in Microsoft Visual Studio
5 Y6 {& @8 @1 O' s, x7 e# |+ K: _9 _, r+ n
5): S3 P, c: T) O9 c) T' p# D
Create a new Java Project by File -> New -> Java Project
$ t# T4 m3 m- y% F
: T8 a. |: k: Q, w! }6)
# C0 ?9 s4 [0 M/ R  M6 m2 Y! l9 sEnter a project name and continue with Next
4 K# n' S, S/ ]" y7 m( Y8 K  x1 b3 O  ~, k) f0 V
7)
! [  J6 C, j5 h& Q2 f- a  }5 wOn the Libraries Tab add the external NXOpen Jar packages and Finish: u: }3 Q* t# q$ V, M" `, J0 w& o

5 I" X! ~9 I, q, r3 _3 \8)3 @* y5 k- k  p- l
In the Package Explorer window make a right click on the project name and create a new Package (Namespace)  
! ]3 P/ K5 Y1 s- F, i# P2 v, k9 G: n; A
; G4 T& \$ Y5 O- b1 n' H9)
+ [# Q3 W! Y9 D2 ]% @; X: jEnter a package name and Finish6 ?" ~' _6 x, P: h, h. I

8 H6 t4 o$ P/ d8 j3 o% i10)
# `5 e& n9 r% B$ S5 M! T5 S+ u+ fIn the Package Explorer window make a right click on the Package name and create a new Class   
9 G& V/ G" X% w
7 }. B4 z7 U) d- b5 ?: o1 k  \11)
/ j+ u( q+ n& T8 Y, gEnter a Class name and uncheck all method stubs options
, r( A- T/ y4 q. W- @9 y
. U1 s7 ?0 Q# ~4 ~12)' U0 v5 b! O1 L+ T% V' c) D' r
Now you have a project created with an empty class so it’s time to complete the source code and we use the NX Journal Recording.% Z+ }% m  Q7 S: T8 H& ]
First we set the NX journal language to Java by Preferences -> User Interface -> Journal -> Journal Language -> Java3 ~7 e3 M: I' @  H7 k. O
3 Y% R* D  I$ G! J
13)
! U8 L; m  D9 A! T2 cStart Recording by Tools -> Journal -> Record
* b; Y# d; Y& ^0 A
$ t  z0 |. }# Q9 W6 B  y14) - ^2 J  F" l* `
Create a Block and finish the journal by Tools -> Journal -> Stop Recording
7 V4 j6 |0 Q2 Q5 q! S& {' i2 c$ V
" n) x+ V: P; r$ z15)$ G* |9 Y) R* L; w- V; ^7 I; C* x4 x
Open the Journal Editor by Tools -> Journal -> Edit and copy/paste the Imports and Methods to your project source file
5 S1 A' c. D) o$ d" ]2 z, v3 [5 T
16)
, _% L4 J# t4 u; ]( S; qMake a right click in your source window and select Source -> Format to reformat the source contents with “Eclipse rules”
0 q/ f% }/ b0 z7 f; o! Q
9 U7 d  \: {* O9 _8 A17)3 G+ }+ E5 j- i5 r% x
Finally we create the Jar file which is mandatory in case our package contains more than one class.2 v9 M; ]$ x' n  K1 Y& @( Y- r
In the Package Explorer right click on the project name and select Export -> JAR file -> Next" e; s, E6 j5 Q- U, D  @; T

! I* F+ E6 Z: N; d6 I! A" f% O18)
& ?# s5 P8 I7 sSelect the correct project, turn on Export generated class files and resources and enter the destination file name of the JAR executable.; b1 D( w- G8 ^' e; B+ ^& I# H& p1 I
5 F6 h# V; c- h. T) Z
19)
+ P2 r) g, C7 ~0 K1 AThen proceed with Next twice, turn on Generate the manifest file, enter the Main Class and Finish
! A5 M/ y9 d/ p; L5 k5 b
+ `  C( v" O8 k) P7 `) r( N& H" I7 \
Debug the JAR or CLASS file with NX and Eclipse
+ L" C1 _( x1 h# f# k3 t) d( q
4 p0 B& ~4 _+ a/ b# M/ T& M7 _- e# j20)
' n% ~0 i2 f$ I" OIf we want to debug a single class only, we could use the compiled Java class file which can be found automatically after saving the Java source file in workspace\projectname\bin\packagename\class .2 v4 }6 O! T" t: L' b5 n
Due to Java naming convention and limitations we don’t want to have multiple classes in one file so in that case we would use the final JAR archive file.  v; v- g1 h  R5 a, E9 }
In order to connect to the NX session, NX needs to start the JVM (Java Virtual Machine) along with some debug settings, for example the communication port between NX and Eclipse.: W/ ?/ V8 t% g
From a NX8 command prompt, we enter the following commands:1 p) p5 Z9 l/ u, e4 V

4 x, ]. N; S9 U>set UGII_JVM_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n2 s6 ~4 F& B6 w$ ~
>ugraf.exe0 P1 n- f! ]8 c6 q$ m" h6 {
- Q3 z9 x* M7 v
Then we start the JVM once by File -> Execute -> NXOpen and selecting any *.class or *.jar file.
; d/ u( g/ c: }; O+ RAny simple class will do the job, for example a famous HelloWorld class.2 z1 u# h/ Z* }, C
1 x3 E: I5 v  j# u# u7 ~& Q( e( i) s& u
21)
# B/ o( F5 N. n( W, ^Create the external access to the JVM session in Eclipse by Run -> Debug Configuration.
2 P: H1 l0 t0 {. p. }On the Remote Java Application node make a right click and select New
( p; s# R5 s( }  b7 e9 T0 q. y4 w/ p! g
22)
5 j% D5 B. [, `8 ]% H' MEnter the Project you want to debug and make sure that the Port maTChes the address from UGII_JVM_OPTIONS" V; [1 p( Y8 O1 _
; ]; [7 G" g) ^) C3 C/ s
23)) |/ _. l3 g9 E, _: N* Q& U
Don’t forget to set one or more breakpoints in your code where you want to interrupt execution
1 a' i8 y) c: z' A0 r' c( ]4 y! h
24)1 H( e) [( C) Y5 M8 |
Finally execute the JAR file or CLASS file in NX that you want to debug.
1 f% L6 B- [1 f' k! ]Once the breakpoint is hit, switch to the Eclipse application, confirm to change to the Debug Perspective View and Step through your code as desired.9 M# B* @  L! F: L# l; g7 }
6 S- ]+ X2 K* u" i
That's it." i/ \) f# K) f5 {' G
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了