SteveNadeau Posted August 16, 2011 Posted August 16, 2011 Hi, This is my frist attempt at creating a new module for ScriptMaster. I want to be able to access UPS' Webservices for the freight rates. I have already done this with FedEx in C#, so I kind of know where I'm going, but ScriptMaster gives me a hard time starting it all. I came across a well-written JAVA code that does the XML parsing (I hate that part): the project is here if anybody wants to try it. I created an account to UPS' API, and configured the java code to represent my account informations. This is where it gets messy, because I haven'T done a lot of JAVA in my career. I compiled all the .java files with javac. I then created a jar file from those .java. I imported the jar file in the ScriptMAster.fp7 file, which went fine. When I tried to run the code, it give me an import error as if the jar wasn't loaded (it is, I checked with the SM function) Here's the error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class com.millz.ups.UPSShippingUtils @ line 1, column 1. import com.millz.ups.UPSShippingUtils; ^ I wasn't expecting this project to work on the frist try, but it seems that I can't even start it! What have I been doing wrong ? Than you for your time.
Jesse Barnum Posted August 16, 2011 Posted August 16, 2011 Hi Steve, when you see an import statement in Groovy code which references something other than the built-in Java and Groovy classes, that means it's expecting to find those classes in a java library, also known as a jar file. You need to find the appropriate jar file, add it to the list of jar files in the ScriptMaster.fp7 file, and then check the box in your module indicating that it needs that jar file.
SteveNadeau Posted August 16, 2011 Author Posted August 16, 2011 As a matter of fact, I did. I also checked that it was indeed loaded (with the function "SMGetLoadedJars"), and I can see that it is. EDIT: Just to be sure, I redid the process of compiling the .java files and creating the .jar file, and I still have that same error. (I also made sure that the JAR in the .fp7 file was deleted, and I added it again)
Jesse Barnum Posted August 17, 2011 Posted August 17, 2011 Steve, I'm sorry but I don't know why this is not working. If you'd like to send me your ScriptMaster file and have me troubleshoot it, I can do that, although we'd need to bill our hourly rate for that service ($165).
SteveNadeau Posted August 18, 2011 Author Posted August 18, 2011 I thought that maybe I was going a little strong for my first test project, so I decided to go very smoothly, and try a simple "Hello World". And it's not even working... I know that I'm doing something wrong... but what exactly ? I based my process on this post, and wrote a simple class: package Steve; import java.io.*; public class test { public String test (){ return "Hello"; } } My code in the ScriptMaster file is: import Steve.*; test sn = new test(); return sn.test(); I know that the import is probably irrelevant. But the point is: I get the same error message from the ScriptMaster file: Unable to resolve class test. Once again, I checked with the function SMGetLoadedJars and I see my jar is in the list.
dansmith65 Posted August 19, 2011 Posted August 19, 2011 I think one problem could be with the name of your method; it is the same name as your class, which makes it a class constructor. http://www.javabeginner.com/learn-java/java-constructors Try the same test, but with this: package Steve; import java.io.*; public class test { public String myTest (){ return "Hello"; } }
Cabinetman Posted August 21, 2011 Posted August 21, 2011 I'm just getting into this too. I've had a good deal of luck working with Amazons MWS but they provide jar files. So far I haven't been able to compile one based on the other posts method. I get the old unable to resolve class......
SteveNadeau Posted August 22, 2011 Author Posted August 22, 2011 Good luck, I've been wasting nearly 3 days last week trying to figure out what went wrong with my process. My final thoughts are that my JAR library isn't compiled the right way, because I can import other JARs successfully.
Cabinetman Posted August 22, 2011 Posted August 22, 2011 The biggest thing I see is where the heck are the import files? Example: import com.ups.xmlschema.xoltws.ship.v1.BillShipperType; I don't have that folder in the download package. I guess not being a Java person or programmer I'm missing something...........
Jesse Barnum Posted August 24, 2011 Posted August 24, 2011 The import statement is referring to classes that should be embedded in the jar file. You don't see them as folders because they are all in the jar file. A jar file is essentially just a .zip file with some extra metadata in a META-INF directory. Try extracting the jar file on the command line this (in OS X): jar -xf YourJarFile.jar Then you'll see it extract the folders corresponding to the import path structure.
Jesse Barnum Posted August 24, 2011 Posted August 24, 2011 Dansmith is correct that you don't want to name the method the same as the class, that treats it as a constructor. Some other points: * It's not technically incorrect, but Java naming standards are to use initial caps for class names and initial lower case for everything else (methods, variables, and package names). Everything is case-sensitive. * When you wrote the class, did you use the jar utility to compress it into a jar file? If so, did you add it to the list of ScriptMaster jars? And lastly, did you go into the 'jars' tab in the test module you're writing and check the box to indicate that your module uses that jar? If none of that works, try doing 'jar -tf YourJarFile.jar' on the command line to see a list of classes in the jar file. You should see an entry that says 'Steve/test.class' One last question, did the message say exactly "Unable to resolve class test"? If so, try omitting the import statement and use 'Steve.test' as the fully qualified class name instead of relying on the import.
SteveNadeau Posted August 29, 2011 Author Posted August 29, 2011 Thank you Jesse, what you said helped me get to the bottom of this. As I suspected, it was the JAR file that was the problem. I wasn't compiling the JAR in the right directory. I found out what went wrong when I executed the 'jar -tf YourJarFile.jar' and saw that all my classes weren'T prefixed with my package name. Once again, thank you !
Recommended Posts
This topic is 4903 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now