I have a JAR file that contains a series of .java files/stub code. I need to include the JAR into a NetBeans project and call the various methods contained within. I've attempted Solaris as well, but no luck there either.
At the moment, the entirety of my Main.java (the only src file in the project) is:
package TestApplication;
import edu.university.department.ws.DiscoveryServices;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
The exact error is:
C:\code\Projects\WebServiceTest\TestApplication\src\testapplication\Main.java:3: package edu.university.department.ws does not exist
import edu.university.department.ws.DiscoveryServices;
1 error
I added the JAR file by going to libraries, clicking Add JAR/Folder, and selecting the JAR. Once it was added, I can drill down into it in NetBeans and see all the stub code, including edu.university.department.ws.DiscoveryServices.java, but yet it can't seem to import it.
I also tried going to Tools -> Libraries then adding the JAR to the classpath there. It didn't change anything.
Is it possible the JAR file wasn't created correctly? I can see the code in NetBeans, so I don't think anything is wrong with the JAR, but I'm new at this and not sure what I should be looking for.
Thanks!
Try this:
http://gpraveenkumar.wordpress.com/2009/06/17/abc-to-import-a-jar-file-in-netbeans-6-5/
Hope help.
Does your Jar really contain .java files? It looks unusual, because java-files should be compiled to .class files before packing to Jar.
Maybe http://docs.oracle.com/javase/tutorial/deployment/jar/ can help you.
Haven't you seen some warnings while installing the jar?
I have seen that message when I had erroneously the same jar installed twice - as compile library and as a test library.
As the result, many of packages became invisible.
After removing the jar from compile libraries everything become visible.
One can understand, why the such a problem may comes from.
I have had this problem, when used in Netbeans IDE the java SOURCE code using
pasting code from the other internet source by Ctrl-C Ctrl-V key combination.
(Pasting from other IDE).
The reserching of prombled showed that the problem is of absence of
statement "package nameofpackage" in code, that you want to use as library.
So, to correct the mistake you need to insert the statement package in project you want to use as library.
Perhaps, you need also to delete and link library in Netbeans again.
To link library I used the the menu point "Add library as JAR file" from tree menu item in project "Libraries" and rignt-mouse click - then "add library"
Related
I have a java project: simple telegram bot. It worked while I didn't tried deploy it on Heroku. I did a backup for stable version, but Eclipse keeps showing me this ERROR. IDK what's wrong with it, I tried a lot of stuff, like what's the problem? I have src folder, classes also, I have main... Maybe problem in .gitignore file?
But I deleted from it *.class, it's still not working. Help
It's not a duplicate, because I'm workin in Eclipse and it worked earlier. Added my folder properties. I need short answer, not just a wiki of possible problems because it doesnt help.
Folder props
Screenshot error and folders
Your project configuration is very bizarre; you have class files in a directory named 'SRC'. It's hard to tell what you did to manage to create a project def this bizarre. Some ideas:
You've compiled this on the command line. You should probably look into build systems like maven or gradle to build your code. Even if not, use the -d switch on javac to ensure the class files end up in a directory named 'bin' or 'build'.
You've turned off eclipse's autocompile function. Turn it back on.
Right click your Point.java file (not Point.class) and pick 'run...' from the context menu. Assuming autocompile is on this will work.
Generally, use packages. Stuff in the default package is unrunnable in various scenarios. From what I can tell you're not in one of those 'default package is not runnable' scenarios but perhaps I'm missing something.
I'm having difficulty with my latest programming project. I have a program in Netbeans which relies upon an external library contained within a jar file. I am expected to use several imports to get the operations I need. While that's all fine and dandy, it also means I can't debug this code to make sure it works. I did see something on StackOverflow about doing a copy-pasta on the jar file into my code, but it uses so many commands and so much code that it would be more helpful to import the whole jar file, if possible.
How do I get Netbeans to recognize that I have an external jar file somewhere that it needs to read from in order to get its information?
Furthermore, I am expected to read in a file via the args[], and I am not sure how to read in command line arguments in Netbeans. How do I do this, and where am I expected to put the file to be read in?
I have figured out my issues and am going to answer this for future reference to anybody with this exact same problem. When you have a NetBeans project, you can open the project hierarchy and get a list of your source packages, test packages, libraries, and test libraries. The Libraries folder is where I needed the jar file.
I can right click on the libraries tab to add a jar/folder. Doing so gave me a file explorer to navigate to where I had my jar saved, and adding it fixed all the warnings for external library imports. The program now knows where to look for all the external libraries. Presumably, I'd have to repeat this if I ever moved the jar file.
As for adding the arguments, I found this under Run>Set Project Configuration>Customize. This brings up a window with the project properties. One of the text boxes will be for "Arguments," and filling this in with your commands will give you those commands as your Args[].
I have three .class files that I'm supposed to black-box test. They are under a package named one.two.three. I'm having difficulty accessing them. I started a new java project in eclipse and created a package with the same name. I then proceeded to add the three .class files to bin/one/two/three. If I try using the classes Eclipse can't find them and I get compiler errors. I'm using the appropriate package header. Any help is greatly appreciated, thanks.
assuming bin/ is your output folder in the Eclipse project settings. Simply dropping the class files under bin/one/two/three will not work as eclipse will either delete them (on clean build) or just ignore these extra artifacts. Do as #Ray Tayek says- keep them in a different directory and edit project classpath and add this as class folder. This should work.
another problem. I have already placed my Jython.jar into what my computer recognizes as the Java CLASSPATH. This done, importing anything from Org.Python is not found by the compiler! Do I need to have the Jar in the same folder as the java code as well?
Thanks to anyone who replies :D
---------------------------------------------UPDATE-------------------------------------------
Still not working
within CLASSPATH I have Jython.jar.
within the location of my code and batch-compiler, I have the jar.
and I have typed "import org.python.util.*;" and nothing else are the beginning of my code
and it is still giving me errors :C
Make sure that you spelled the package correctly! In java the convention is to have packages with small letters: org.python
If you are using command line to compile and run your code then you will need to add the folder containing the given Jyhton.jar file.
For more help take a look at: http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html
If you are using an IDE:
Eclipse:
Got the Properties/Java Build Path/Libraries. From there you can add external Jars.
Netbeans:
Go to the projects Properties/Libraries/Compile tab and add all the JARs that you want to be included.
I want to use the DDE with Java and after some research I decided to go with http://jdde.pretty-tools.com/
My programming platform for this project is NetBeans.
However, I have encountered a slight problem. I have imported the jar file as it supposedly should be done, i.e. right click package > Properties > Libraries > Add JAR/Folder. I also tried creating a new library and adding the jar file through this way. In both cases I have manged to import the jar and in the Libraries folder I can see the jar and the source files in that jar, which means that until this point everything went correctly. The problem starts when I try to import the package into my source file i.e.:
import com.pretty_tools.dde.client.*;
public class Main {
public static void main(String[] args) {
DDEClientConversation conversation = new DDEClientConversation();
}
The result of this is that DDEClientConversation is marked as error with a message 'cannot find symbol'. I am considering that there might be a problem with the pretty tools jar file in some weird way, since when I import a different jar from a different package all works fine.
I hope this satisfies the moderators...
I have communicated with the pretty-tools author (Alexander Kozlov) who cannot validate the library compatibility with the NetBeans IDE. I have, however, had success using the jDDE library from http://code.google.com/p/jdde/ in the NetBeans 7.0.1 IDE.
Probably the underscore in the package name was causing troubles.
See http://download.oracle.com/javase/tutorial/java/package/namingpkgs.html
Rename the jar as zip and check the paths. Probably pretty-tools (with a minus) is the culprit.
The paths are good. Another solution is to repack the jar with the compiled .class files only.
For some reason, NetBeans does not seem to like that the .java source files are packaged up with the compiled .class files. If you unpack the jar using any zip archiver, delete the .java source files, and repack as a jar as a zip and change the extension to .jar. Add this jar to your Library and it works great.