使用eclipse进行NX二次开发的设置步骤
Debugging NXOpen Java with NX8 and Eclipse IDE(see PDF in the ZIP file for a pictorial description)
Installation of Java and Eclipse
1)
Download and install the Java Standard Edition Developer Kit Java SE 6 (1.6.0_14 or higher) from
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2)
Download the Eclipse IDE for Java Developers from http://www.eclipse.org/downloads
and extract the ZIP and its ‘eclipse’ directory content to your preferred path, for example “d:\eclipse”
Create a project with Eclipse
3)
Start the Eclipse IDE, for example “d:\eclipse\eclipse.exe”
4)
You will be asked for the location of your Workspace folder which is comparable to the MyProjects folder in Microsoft Visual Studio
5)
Create a new Java Project by File -> New -> Java Project
6)
Enter a project name and continue with Next
7)
On the Libraries Tab add the external NXOpen Jar packages and Finish
8)
In the Package Explorer window make a right click on the project name and create a new Package (Namespace)
9)
Enter a package name and Finish
10)
In the Package Explorer window make a right click on the Package name and create a new Class
11)
Enter a Class name and uncheck all method stubs options
12)
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.
First we set the NX journal language to Java by Preferences -> User Interface -> Journal -> Journal Language -> Java
13)
Start Recording by Tools -> Journal -> Record
14)
Create a Block and finish the journal by Tools -> Journal -> Stop Recording
15)
Open the Journal Editor by Tools -> Journal -> Edit and copy/paste the Imports and Methods to your project source file
16)
Make a right click in your source window and select Source -> Format to reformat the source contents with “Eclipse rules”
17)
Finally we create the Jar file which is mandatory in case our package contains more than one class.
In the Package Explorer right click on the project name and select Export -> JAR file -> Next
18)
Select the correct project, turn on Export generated class files and resources and enter the destination file name of the JAR executable.
19)
Then proceed with Next twice, turn on Generate the manifest file, enter the Main Class and Finish
Debug the JAR or CLASS file with NX and Eclipse
20)
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 .
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.
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.
From a NX8 command prompt, we enter the following commands:
>set UGII_JVM_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
>ugraf.exe
Then we start the JVM once by File -> Execute -> NXOpen and selecting any *.class or *.jar file.
Any simple class will do the job, for example a famous HelloWorld class.
21)
Create the external access to the JVM session in Eclipse by Run -> Debug Configuration.
On the Remote Java Application node make a right click and select New
22)
Enter the Project you want to debug and make sure that the Port matches the address from UGII_JVM_OPTIONS
23)
Don’t forget to set one or more breakpoints in your code where you want to interrupt execution
24)
Finally execute the JAR file or CLASS file in NX that you want to debug.
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.
That's it.
页:
[1]