查看: 5236|回复: 0

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

[复制链接]

2477

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
DebUGging NXOpen Java with NX8 and Eclipse IDE
) @$ V6 G- u6 z6 A4 R+ W+ a) }7 o- |* \1 x9 h: g2 x  M
(see PDF in the ZIP file for a pictorial description)
2 \! \1 `. o3 w7 H- _2 J
4 O7 N/ b, D  kInstallation of Java and Eclipse9 Z  D0 Z4 y# V! y

. W: s8 b8 D  F: B$ Z1)% P. s, M* N& Y8 Z- N7 I% ]
Download and install the Java Standard Edition Developer Kit Java SE 6 (1.6.0_14 or higher) from
0 A0 j( p* [" N- b- s' ?, Shttp://www.oracle.com/technetwor ... ownloads/index.html
! J3 t" ^/ `; B1 R7 g
' |8 T- V) y9 m+ e2)
$ s% L0 Q% d% p& W4 E# q4 n$ wDownload the Eclipse IDE for Java Developers from http://www.eclipse.org/downloads 7 U6 J7 ]+ S8 \6 R
and extract the ZIP and its ‘eclipse’ directory content to your preferred path, for example “d:\eclipse”" a' T# m! ^8 L; J$ L, h; K$ u4 D1 N

3 I) P- w# P. T  v4 W9 m  X4 @
) G- K/ ~0 N( C' h; WCreate a project with Eclipse   8 P" N" |# }- f8 j- u
& V1 R) _; E$ p4 q
3)
1 n& w# i# H5 B$ P- |Start the Eclipse IDE, for example “d:\eclipse\eclipse.exe”
: a8 @) A) c% Q9 F) `7 {
1 q% a1 E, B5 P1 |! G. `* F4)% A/ ~5 d" v. L4 w% ]1 q) j4 L
You will be asked for the location of your Workspace folder which is comparable to the MyProjects folder in Microsoft Visual Studio, _) v" D, ^! U. c

  E; \5 N' H0 e/ S5)
8 ^4 P+ `$ l" q/ Z8 }1 T9 \, D  ZCreate a new Java Project by File -> New -> Java Project
, r" q8 y! j8 l7 u; j4 f7 W0 T* L# Q9 p. u1 I
6)
8 F8 r! x0 k9 h8 n2 w2 LEnter a project name and continue with Next/ u( A. [2 X. ]) E8 O3 E+ |# `0 L% Z

5 D2 ~! U8 M( ~/ l& ^4 n% _( e  y. g7)
( }7 n) q5 ]% a7 k1 A! w4 P" nOn the Libraries Tab add the external NXOpen Jar packages and Finish
2 D: A/ E, r- [) q! l
$ k$ @6 b# }, A: M9 @$ D6 ~8)
1 h, D/ S" O  }7 O2 P$ F" f# `In the Package Explorer window make a right click on the project name and create a new Package (Namespace)  
. N0 F' N/ L7 x  y# R6 ~7 T/ M9 T1 M
9)
$ @* I3 |/ u& M, G) r% ]. d* MEnter a package name and Finish8 i8 T5 r# h% X( Y+ T4 w  W! p
, v* t( L+ G0 g3 U8 v9 H
10)& K. p3 J* Q2 @3 e. B" E
In the Package Explorer window make a right click on the Package name and create a new Class   
& g/ ?# p% }7 g3 {
; y! ^" ~- ~* @1 x8 Z11)
% Q6 b6 F' t& k" tEnter a Class name and uncheck all method stubs options/ e# x2 \7 V4 ^0 c9 H, u# A4 ]
& {. t3 i, u, H8 Y: W. M6 [/ b( g
12)
# S# W2 j! H/ |' U$ G" RNow 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.
0 s% N+ x& D/ |4 n1 OFirst we set the NX journal language to Java by Preferences -> User Interface -> Journal -> Journal Language -> Java
$ x5 C/ n' D' Z0 @( X/ p& Z. {
0 l; K& m* I. I1 ~; ?& z13)5 M+ A, O1 `& K- f
Start Recording by Tools -> Journal -> Record
4 E" w! d, d. m+ W
: B/ @# L/ ]8 n6 Y. _- r3 B14) ! S/ u7 [: n& e3 D* z* A
Create a Block and finish the journal by Tools -> Journal -> Stop Recording
1 K1 W& r6 T/ ^  t' {( M" e; e3 l# `; o9 Z* Y
15)
" c1 D$ \4 h; r% J% LOpen the Journal Editor by Tools -> Journal -> Edit and copy/paste the Imports and Methods to your project source file4 v( r( w5 o* q! o! s; e8 g
; K, v) b2 c" l8 |0 m+ [! B
16)7 ^# `9 I  i! e' D2 b& l
Make a right click in your source window and select Source -> Format to reformat the source contents with “Eclipse rules”
4 p6 x" q# u6 D2 B; b( C$ j, C$ N: [& L$ Q
17)
9 g% h! D# j5 d" |9 x/ DFinally we create the Jar file which is mandatory in case our package contains more than one class.
% c8 w, N! ^/ M/ MIn the Package Explorer right click on the project name and select Export -> JAR file -> Next
; J; p" A% ?( J) v# K8 K% h/ A# d0 i2 y$ _/ ^
18)* \  d" A1 _9 i9 c( ^7 O) w. S
Select the correct project, turn on Export generated class files and resources and enter the destination file name of the JAR executable./ {8 h$ n) K9 ]
8 v( _6 e3 M/ x* r8 `
19)6 z9 e* B& h0 A5 R7 y( A' j
Then proceed with Next twice, turn on Generate the manifest file, enter the Main Class and Finish0 A: S' V( Z3 A; t/ `

, Y1 I, I* G. R% A+ a( V4 ?1 G7 J& Y3 I# K! ~9 N2 S
Debug the JAR or CLASS file with NX and Eclipse; E9 P! @( i; r; }6 w7 j8 V

4 p) C( c6 R/ M' ]20)
! B% I( L5 G' ~  A; I) u" Q7 JIf 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 S/ B' g- @6 T8 T! 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.
. e7 h/ [. x4 p6 k0 ^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.
9 F7 }4 Q' v% f8 }' tFrom a NX8 command prompt, we enter the following commands:
7 F7 I) L1 R/ b) Z3 f
' c  L$ O' q$ W+ `5 F! v1 u. Y>set UGII_JVM_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
2 v: V# ~. T% D# {# h2 m- C>ugraf.exe% P5 M9 m8 @, V" l2 t

. |& L1 ~9 r- |+ Q# LThen we start the JVM once by File -> Execute -> NXOpen and selecting any *.class or *.jar file.' Y  e" c' {, C1 `+ n8 K  {
Any simple class will do the job, for example a famous HelloWorld class.
6 `$ ^7 c; r* `6 i+ x" m9 f# U& v+ w* R: |+ x# F% f) A+ K
21)9 Y  Q& H' O, k$ @- Z) D* m. T
Create the external access to the JVM session in Eclipse by Run -> Debug Configuration.; P0 F( p/ f+ [+ _( N
On the Remote Java Application node make a right click and select New # A( v% }3 j* E, h
+ w: ]- a9 f; l; ?
22), T3 t- b& ]* t" ~
Enter the Project you want to debug and make sure that the Port maTChes the address from UGII_JVM_OPTIONS
, v# f( m, ?) K! ?- w' H+ u) E% ^# i" x, Q. O! G; c1 }
23)# l/ Q1 N3 m5 ~" _; |- n! I
Don’t forget to set one or more breakpoints in your code where you want to interrupt execution, w( O" @& {; |1 E4 B( z, M

% P/ [! k$ E$ Z& a5 r6 n24)
$ |7 }5 P/ s$ n, H* g7 qFinally execute the JAR file or CLASS file in NX that you want to debug.
' v7 v; n) Y# y3 R( QOnce the breakpoint is hit, switch to the Eclipse application, confirm to change to the Debug Perspective View and Step through your code as desired.' f" a5 g8 q6 S+ q9 ]
6 ^) P& y2 Z# a- |0 P1 \
That's it.
; L$ r1 s! \  o3 \1 s
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部