Create a class library in NetBeans - java

This it's probably going to be a question with a very easy answer... But I've been googling for a while and I didn't find any.
I'm working on a project that requires some classes to be used in more NetBeans projects (and EJB deployed on Glassfish and a client to call it).
Now, to make it work, I just imported the whole EJB project into the client project as a library, but everytime I launch the client, Netbeans redeploys the whole client and that takes a lot of time.
That's why I'd like to extract just those few interfaces I need from the server project, package them in a .jar and link that to the client.
In Eclipse it was easy enough (right click on your classes, export as jar). Here I can't really find anything of the sort. The only export option I see is used to export the whole project as a .zip.
(Copy pasting the .java files in the client project would also work but a .jar would be cleaner I think)

Not sure I understand the problem.
I use shared classes a lot, and package them into their own project.
Possible process:
Create new project, "Java class library".
Move the required classes to that project.
In your main project, open Properties, Libraries and "Add Project" to link to your library project.

Related

From .jar to importable package... How?

I have a .jar file that is sitting in one of my folders after I downloaded it from a tutorial website. This .jar file includes all of the necessary packages needed to be imported to a specific program I wish to run (i.e., it is a client that allows me to communicate with the server I need to use for this project), but I don't know how to transfer the .jar file into a package so that I can directly import the necessary packages for this project. Do I have to transfer the file into a Maven repository (which I have no idea how to do) or do I have to use some hidden technique to transfer the file over so I can import directly from the file? Or is it a really quick fix that just takes two minutes?
F.Y.I.:
I am using NetBeans IDE 8.1 for the said-Java project.
I am not heavily experienced with all the ins-and-outs of the IDE, so I need simple instructions.
I barely understand what a Maven repository is or does. I only have heard of a Maven repo through "Help" websites.
I have tried multiple "Help/fix-it" sites but only got vague answers, like "run 'make'".
My response: How does one 'make'? Their response: ...

Java Eclipse: Read the code of a class imported from a library

I'm working in a project environment Eclipse Luna Service Release 2 (4.4.2) in which I am using classes imported from some libraries. Currently I have to build a class diagram of the work done so far and to do that, I'm using the "ObjectAid Explorer Eclipse UML plugin" without problems. Unfortunately I can not create it anyway integrating relationships to classes imported and then I was planning to re-create them in a package so that you can create this class diagram. How can I read the code of a class imported from a jar library?
Thanks so much !
If you want to read just the method signatures, inside Eclipse from Project Explorer, navigate where the .jar is located and expand it; you will be able to view the classes and their methods.
If however you want to read the entire code of every class, you need the .jar that attaches the sources on it. Developers usually package a Java Project without the sources files and create separate JARs that contain them. Look for the a JAR named <library_name>-src.jar.

Domino Designer : Eclipse Project Loses External Jar References

I'me developping a java agent with Designer 8.5 with external jars in the project.
It works fine except when I close and reopen the project.
Then something quite strange happens: in the project build properties the references to jars are present but not taken in account, so there are compilation errors.
Then if I save a source file and come back to the project properties the references have gone.
So I must use the button "Add external jars" to redeclare them.
Has someone had this problem?
Mikkel Heisterberg has a great summary of the options available to you in regards to Managing external Java dependencies in Domino Designer
Basically, it boils down to:
Include the classes in the agent/web service you are writing
Put the classes in a Java script library and include the script library
Use the JavaUserClasses notes.ini setting
Put the classes in the jvm/lib/ext folder
Was that the information you were looking for? If not, please describe where/how you are using the external jars (Agents, Xpages, Managed Bean, ...).

Importing an API in Java (eclipse)

I'm trying to import an API that I found online - joda time - into my program.
I've downloaded the files, stuck them in my source folder, but obviously since it isn't integrated into my program they won't work.
I've spent a lot of time googling around for different methods (maybe I'm searching for the wrong thing?) as well as just randomly doing a bunch of different things inside eclipse (I'm developing with eclipse) that include the word "package" or "import", to no avail.
I don't know if it's worth mentioning but my program is being built with the google app engine, and all their stuff is organized in a nice com.xxx.xxxx format, which I think is ultimately what I need to get my stuff into - I just don't know how.
Anyway, sorry if this is a ridiculously trivial question, and thanks in advance to anyone that helps.
You should just have to put the joda-time jar file inside the WEB-INF/lib folder of your project. This folder contains all the libraries that must be delivered with your application, and are automatically added to the build path of your project by Eclipse.
Since you are using Eclipse, you can use the library functions to add in external packages.
Right click on your project, and then choose Build Path --> Configure Build Path.
Click on the Libraries button at the top, and then click the Add External JARs... button.
Select the JAR file in your JODA directory.
If you are using the Eclipse deployment tools, this will automatically package your JAR file in to your web application. If it doesn't do that automatically, add that same JAR file in to your WEB-INF/lib directory (copy it in to your project).

JavaEE compiling files

I feel like a 4-year old who has a slice of bread with pb and a slice with jelly and is asking how to make a sandwich..
I've been given the responsibility of maintaining a javaEE website that was done by our parent company that no loner supports us. I'm relatively new to JavaEE and I'm trying to figure out how to recompile the files that need to be modified from within the root folder of the site.
I downloaded NetBeans to help me with this, but still can't figure it out. My problem is that the java files can't find any of the packages and resources they are dependent on. As far as I know, the resources are there.. although, I do see some packages starting with "com." and "javax.", and I don't see a 'com' or 'javax' folder anywhere.. I believe my problem has something to do with setting the class path in the project properties in NetBeans.. I tried that but either I'm not doing it right, or its not working. This whole Java compilation is so foreign to me, it'd be really great if someone could lead me in the right direction of getting this website compiled.
I posted a pick of the folder hierarchy of the website to help:
I'm trying to compile the RecordAdd.java file here specifically at the moment. Some of the packages it is trying to import come from its parent folder, asp, of the folder it is in, easp. The file is also trying to import com.icesoft.faces.component.*; where '*' consists of several different imports of the parent packages. I don't see a com folder like I mentioned, but I do see icefaces.jar files in the lib folder in WEB-INF folder. I've tried putting these folders in NetBeans Library-Compile category classpath, but that didn't do anything.
I'm not doing something right, that is probably a basic knowledge of compiling java projects, but I'm just not getting it. I really appreciate any help, just please don't be too harsh. Thanks!
Try to find out which IDE the original devs used. I see a nbproject folder which indicated Netbeans (unless that was created by you) so try opening the project in Netbeans as a Java EE project. I'd also try to open it in Eclipse, it has good importing capabilities and can sometimes figure out the classpath on it's own. Download the Java EE version of Eclipse and install the Web Tools Project. You can also try to see if there is a build file that will compile and generate a war file for you (something like build.xml).
It should be simple if the project was created in netbeans. Just go to File -> Open Project. Navigate to where the project is located. You will know if the folder is a project, because netbeans recognizes it and a different icon is displayed instead of a regular folder icon. Once you open your project, you can right click compile the project.
You don't use java compiler yourself to compile java files in a project. Compiling and building are done by tools like ant, maven... It's automated.
Importing existing projects into netbeans is a great way to loose a half a day.
I'm assuming that since there's a nbproject directory, this was built through netbeans, which should give you a leg up.
In the "Open Project" wizard, the top level of your application (not necessarily the sources) should have a friendly globe icon for a web application (.war) or a triangle for EE application (.ear). Open the triangle if there is one. Web applications can be packaged with EE applications through netbeans, so if the Web App you're trying to compile belongs to one, some of the build properties may be associated with it.
Looking at the file nbproject/build-impl.xml should give you hints about where your libraries folder was located. Make sure this path matches in your project properties under the Libraries header. These libraries can be shared among projects and therefore likely out of this projects directory structure and referenced or native to this project alone in which case jars are copied in to your lib folder.
There may be additional reference or server issues that netbeans detects (and gives a paltry error message for) which can be found in the project context menu under "Resolve Reference Issues" or "Resolve Missing Server". In netbeans projects are built against the servers they're run on right in the IDE. Check that you have the servers you want configured under Tools-> Servers, then ensure that server is linked in your project properties under Run.
This may not solve all your problems, but is a good start. Good Luck!

Categories