PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

admin 发表于 2015-2-25 13:02:01 |阅读模式

admin 楼主

2015-2-25 13:02:01

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

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

x
DebUGging NXOpen Java with NX8 and Eclipse IDE
2 \) Y- X0 E" V5 C
5 o3 e& t  ~& F(see PDF in the ZIP file for a pictorial description)) C  N& O, ~% q. g" A* e
6 a( S! O: w& U8 z: j& i0 {' D
Installation of Java and Eclipse2 @+ v/ E! f& e% x# \" N& r3 W

% i  Y/ Z& Q8 d( n9 U# i* H1)
0 R3 _7 Y, Q5 X" wDownload and install the Java Standard Edition Developer Kit Java SE 6 (1.6.0_14 or higher) from
% R  v  S, m" g% c$ Uhttp://www.oracle.com/technetwor ... ownloads/index.html
/ f4 M& d' F* R; `" N/ a; Z) J' O
1 a' a! Y7 e# y" h2)( H) n; K9 c* `* @
Download the Eclipse IDE for Java Developers from http://www.eclipse.org/downloads
. t5 E- W' z5 wand extract the ZIP and its ‘eclipse’ directory content to your preferred path, for example “d:\eclipse”6 ?2 j' b2 T, u  v. Q, k. |

6 ^: [+ M# v& ^7 |! D0 e) O
8 s: b0 Q0 R7 X/ LCreate a project with Eclipse   0 s" v% U  T' f5 H) N

$ D/ N$ Y/ y& h3)4 A7 M5 y- G/ t9 }& M- I5 `0 s
Start the Eclipse IDE, for example “d:\eclipse\eclipse.exe”$ A8 ^8 X: Z: U% j( k
) ~4 T+ n0 P1 L+ l! P
4)9 J2 u% t$ C: {, T6 O
You will be asked for the location of your Workspace folder which is comparable to the MyProjects folder in Microsoft Visual Studio
' v, d) H. Q6 j
" N$ S; `& e6 }4 x1 Y5)
5 j2 S  Z/ l3 ]2 {Create a new Java Project by File -> New -> Java Project; a2 K* ]6 G5 d4 }! `

: H+ L, f9 g) ]/ U% ?3 ]6)! r: ~9 h$ B: s  q* G+ S) j1 ^
Enter a project name and continue with Next# i# J, Z2 [9 A

2 y6 o4 ]9 H3 R7)
- @, K% L  _5 F8 V& l( JOn the Libraries Tab add the external NXOpen Jar packages and Finish1 f8 S5 c1 o! A( E8 |7 T6 j

0 ~* B4 ?6 Q5 u: X8)
  c  G2 j6 i, X4 MIn the Package Explorer window make a right click on the project name and create a new Package (Namespace)  % i, l6 P* w) ?) i7 [, X5 i3 K7 h
6 T. v  ?, I! F' J# S
9) 0 `' c% K3 }1 I
Enter a package name and Finish# E% c7 h" M; ]% y
# I- B* R* p; k+ J# v  h9 B- O) a
10)/ L& g& \/ Z: S  _9 h, A" E
In the Package Explorer window make a right click on the Package name and create a new Class   
& @8 j7 e+ [7 _8 t
3 n' W) ?. p& ^7 K1 m4 a( N; B11)
0 r. V8 p# [! q. vEnter a Class name and uncheck all method stubs options* R9 G- g$ v$ T' Z

! u5 F( M- q3 o5 h8 ~( |* @# o5 P12)$ D: p3 a2 ?2 Q
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.
6 f7 {" Z% l6 E* dFirst we set the NX journal language to Java by Preferences -> User Interface -> Journal -> Journal Language -> Java. \* A/ C; r3 U2 R: D/ j, s
3 @3 C$ }4 Q3 X" |: I
13)% F2 c5 N5 S3 N8 `( G# `& ]! a
Start Recording by Tools -> Journal -> Record
+ M! {& ]  s- r2 i  {/ q; Y+ a* j- R/ z) Z9 h
14)
0 _( u1 |1 P- p8 s. V# d/ z: OCreate a Block and finish the journal by Tools -> Journal -> Stop Recording" G4 W! c1 Z' a' O( I
+ k0 `2 J* Y2 i) O4 E$ s" D$ e) J
15)* o6 b* x/ V2 `+ F" v- O
Open the Journal Editor by Tools -> Journal -> Edit and copy/paste the Imports and Methods to your project source file
5 W3 {2 w0 e. ?; O( T, w4 p7 q
" q- v: r+ a6 D: m16)
* Y, J$ a, D& b! W! L% ?( KMake a right click in your source window and select Source -> Format to reformat the source contents with “Eclipse rules”+ k& l2 O/ r9 k5 _" d6 i- G- i

( o/ L; V% h8 i" V17)
  s% d$ o. Y6 ?, AFinally we create the Jar file which is mandatory in case our package contains more than one class.  i( s; h. h& V- U, p3 ~& _
In the Package Explorer right click on the project name and select Export -> JAR file -> Next
# K1 z9 c5 O& j+ W: p& J/ @
3 _) B1 l/ [! }18)' f6 {( w8 P  r$ w' `" [) ?8 h
Select the correct project, turn on Export generated class files and resources and enter the destination file name of the JAR executable.
6 J6 y8 |$ P% y! N, R) h8 Y6 n9 u
19)3 S% k; ]3 h. i" ~9 ?" K" p
Then proceed with Next twice, turn on Generate the manifest file, enter the Main Class and Finish
+ S  I3 p1 j! c- ?  a2 q# U
" n0 g( X/ j) K2 I! r# p4 O
; ]- F& j# S0 Q" S/ O* X- L: y  ?1 tDebug the JAR or CLASS file with NX and Eclipse7 G9 H# |+ f7 Z- Y" `3 C$ y
5 w; Q' F2 U+ H) c3 \
20)! Q/ A: U; J4 j8 x/ J  X
If 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 .& W: L: |$ e- F% D
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.9 [+ M) Y2 D) ?' Y
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.
- d& `  @6 x5 P, A2 V1 E) w" aFrom a NX8 command prompt, we enter the following commands:
5 b) \, U( I. u  M) G$ g5 I* q( t: Z# y" b6 @2 r' D
>set UGII_JVM_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
8 k0 ^0 H3 W8 ~" l4 n4 ?0 P>ugraf.exe3 y0 J# F) K8 r( m& F/ Y* G$ _

! b; [$ l( I/ }0 I) H8 ^4 f% SThen we start the JVM once by File -> Execute -> NXOpen and selecting any *.class or *.jar file./ M* S. J8 F& e/ x6 d1 E" r
Any simple class will do the job, for example a famous HelloWorld class.
$ p& a7 {6 v/ K- P) \
& P, i5 a0 c* U/ T1 U3 n8 F; y: \21)
1 V5 V6 f; F) v" cCreate the external access to the JVM session in Eclipse by Run -> Debug Configuration.. g4 C! g+ }$ N% X2 P7 G- w( e' ?
On the Remote Java Application node make a right click and select New 2 M$ T" p0 ^: l% z3 c7 }2 T
. y9 p4 _8 a, W7 r* e7 f
22)$ I# P$ I9 g% Y6 N1 J. O; W# R1 J- m' {& G
Enter the Project you want to debug and make sure that the Port maTChes the address from UGII_JVM_OPTIONS0 i4 x$ D) p, G. \+ j+ H+ ~# w

% f) O  @3 X' Q: A5 H23)
7 y- [4 I% t% S9 W( ODon’t forget to set one or more breakpoints in your code where you want to interrupt execution% p. Q+ O6 r. G

$ @1 h0 |: b+ K0 k24)7 D8 R' l1 L/ E1 B2 _
Finally execute the JAR file or CLASS file in NX that you want to debug.
* v) f( v' a/ q3 ~% lOnce the breakpoint is hit, switch to the Eclipse application, confirm to change to the Debug Perspective View and Step through your code as desired." _$ J. _# W# v/ Y: P
: F; V& k/ X7 t& K+ Q0 r
That's it.# S; i; \; k2 P# N8 A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了