How to create .jar from specific package (without main) in Netbeans? - netbeans

There are a lot of similar questions, but none for this specifically. I have a Netbeans project with a bunch of packages. Only one has Main. I'd like to be able to create a .jar from just one of the packages (and all the classes it contains, of course), which doesn't have main.
Is this feasible without having to put that package in another project or without having to screw around with build.xml? If the latter, any easy way or good rtfm links?
The point is i'm developing part of an application for college, each group member is developing a module of sorts. If each could provide their .jar the main project can just include jars and use them. I'm guessing all the mains in the jars wouldn't really hurt? But still...

You can use the project properties to customize your project's jar file content. This screenshot shows what it looks like for a Java Class Library project.

Related

Recommended way of placing dependent jars in ContentNavigator

we have some dependent/common jars of the plugin which we are currently placing in .lib of ContentNavigator application and referring the same in build.xml of ContentNavigator. while we placed the jars in local and tried to give the local path in build.xml it didn't worked out.Can anyone suggest what is the recommended way of doing it?
I've applied the following approaches:
Embed/extract all the content(.class files) of the dependency-jars within the navigator plugin. While the upside is that you have a nice bundle containing all your dependency-classes, it might cause some problems with signed jar's. Or on files that are duplicate amongst your dependencies.
Make use of the "Shared Library" concept. You basically "attach" jar's to the classloader of your server/JVM, Application(ear) or module(war). In your case you would probably attach the shared-library to the navigator.ear, allowing all plugins to access the dependencies you register as a sharedlibrary. One huge downside is (in my experience) that you need to reboot websphere every time you update one of the library-jars.
A third option is to move the functionality out of your ICN Plugin, and let another EAR/EJB do the work (and reference to it from the plugin using a jndi lookup).
I personally prefer option 3 because it's the cleanest way to bundle your functionality&dependencies in an EAR. But option 2 will be a good call when libraries are truely common and won't be updated often.
p.s. In your question you mention the build aspect of your software as well (e.g. "how to correctly reference the dependencies"). You might want to look into the concepts of "dependency management" (using Ant, IVY is a good choice, but i would suggest moving to Maven, or Gradle)

Multiple Xtext DSLs in single Eclipse project

I would like to know if there is a way to organize multiple DSLs inside a single Eclipse project. More specifically, I would like to organize all five Xtext projects of a DSL in some top-level "project folder".
The background is that we manage complexity and enable reuse by making smaller reusable DSLs, e.g. one reusable for expressions and other one for more domain-specific or application-specific aspects. However, each Xtext DSL results in 5 projects, causing a lot of clutter in the Package Explorer when multiple DSLs are involved. A strongly related question has been asked before:
Xtext: define 2 DSL's in one project
The answer there is that multiple DSLs are not needed inside the project for that specific use-case. My use-case is different because I want to be able to easily view the different DSLs and potentially co-develop them.
We are using Xtext in an environment managed by Gradle. We are using the Gradle Eclipse plugin, which creates a lot of Eclipse project files everywhere. As a result, when choosing to "Open Project from File System" in Eclipse, I not only get the option to import the five projects related to the DSL, but also the option of opening the parent folder as a project. This means I can have each DSL (all its five projects) organized neatly in a "project folder". This is exactly what I want! ...
BUT ...
it does not actually work. The figure below shows my package explorer with the five projects of my ExperimentDSL included in the bottom. This DSL works. On top, it shows the folder structure I get when including the project file generated by Gradle, resulting in a "project folder" that can potentially contain multiple DSLs.
As you can see, GenerateExperimentDSL is flagged red and refuses to run. It seems Eclipse somehow treats it as a Java project, but I do not know how to change this or and if this would help solve my problem. Secondly, I would not know how to set up such a project by hand, since the project file in this failing case was generated by Gradle.
Long story short, does anyone know how to get this kind of folder structure to work so that I can keep all my DSLs in the workspace without clutter?
What you try to do is currently not possible. Have a look at the concept of WorkingSets in Eclipse that let you achieve something similar

eclipse - folders for classes

I have a android app in eclipse, and by the time I have more and more classes in it.
As you can see, its pretty messy.
In visual studio I know how to add sub folders in the project, and organize the classes in a more ordered way (for example Interfaces folder, Client folder etc).
How can I do it in eclipse without messing with the namespaces or causing any errors? do I add packages?
thanks!
Yes, you need to create package inside of "com.example.tremp" by right-clicking it.
I think it should have a name including the parent package name (e.g. "com.example.tremp.activities"), but I have tried naming it without parent package name (e.g. "activities") and it worked fine by me.
I think the only way is to create new packages and then assign each class to a package .

How to show shortened project names in the Eclipse package explorer?

I work for a big company that has standards on Java project names. Long standards:
com.company.department.subdepartment.stream.project
Rather than let the package explorer take up a sizable portion of my screen, I'm looking for a way to shorten the project names. Mousing over project names shows the full name, but it's still very slow to determine which project I want to look at next with the incredibly long names. As has been answered before, package names can be shortened. I've got a rule set up, but it only works for packages:
com.company.department.subdepartment={department}
Is there a way to do an analogous thing for project names in Eclipse?
Package explorer uses the org.eclipse.jdt.internal.ui.packageview.PackageExplorerLabelProvider class to provide the view labels. Going through the source of this I don't see any support for shortening the project names.
The following ideas depend on how your eclipse workspaces are setup. If you're lucky and you just import project from your VCS, these could work for you.
If you're using maven, Eclipse project names are usually derived from your GAV. The Import as Maven project wizard has options for what pattern to use for the project name based on your maven GAV.
Otherwise, you can sometimes just right click the project -> rename. YMMV if you have any scripts or such that have the project name hardcoded. If you have these constraints, find those scripts and use variables rather than hardcoding.

NetBeans importing classes package problems

I have created a class in Java that I need to import into NetBeans and use in a GUI. What I have done so far is add the jar file containing the classes to the library in my project. I can look inside the jar file and see the classes I need inside the . I have looked around online and know that the best to way import these classes is to move them to another package that isn't the .
My problem is that I do not know how to do this. I saw that I can create a package in netbeans, but it is gray when it appears and I can't seem to do anything with it. I basically have no idea how to create packages that I can use to import classes If someone could please walk me through step by step I would greatly appreciate it. I have looked at the other posts on this site and other places online, but they seem to skip over somethings I am not sure about. My teacher didn't mention anything about packages either, so I am really in the dark.
You can copy your source files (*.java) in your project's src folder, then use refactoring to change the package.
Right-click your java file, then select Refactor > Move and type your new package name.