NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Specifying the Main class - netbeans.mainclass

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
kameleon527



Joined: 01 Sep 2008
Posts: 11

PostPosted: Mon Sep 01, 2008 10:58 pm    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

I've been looking at the article on how to specify a main class:

http://wiki.netbeans.org/DevFaqPlatformAppAuthStrategies

Unfortunately, there's a part of it that is not clear. It states that the main class should be "present in the startup classpath (you can put it alongside core.jar in platform8/core or similar)"

Is there a standard way of doing this? How is the startup classpath formed? Do I have to hack away at the build scripts to get my main class copied to "platform8/core" directory? Is there an easier way?

Thanks for the help.

Scott
Back to top
Tom Wheeler
Posted via mailing list.





PostPosted: Wed Sep 03, 2008 4:31 pm    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

On 9/1/08, kameleon527 <address-removed> wrote:
Quote:
I've been looking at the article on how to specify a main class:

http://wiki.netbeans.org/DevFaqPlatformAppAuthStrategies

Unfortunately, there's a part of it that is not clear. It states that the main
class should be "present in the startup classpath (you can put it alongside
core.jar in platform8/core or similar)"

Is there a standard way of doing this? How is the startup classpath formed?
Do I have to hack away at the build scripts to get my main class copied
to "platform8/core" directory? Is there an easier way?

I have not seen any documentation about how the classpath is formed,
although what is used for the platform as a whole is logged to STDERR
at startup so it's easy to see what is there.

Hacking the build scripts is pretty easy because there are a lot of
places where you can hook into the build by simply adding a target to
the suite's build.xml.

I thought of an alternative approach might work although I have not
tested it -- your feedback is welcome and I'll update the FAQ
accordingly. You can prepend an arbitrary JAR to the classpath
(regardless of its location) by adding a startup parameter like this:

--cp:p c:/path/to/mylibrary.jar

where this library is the one containing the main class you want to
use. This is how you can set the location of a look-and-feel JAR
instead of copying it to core, so I'd guess it would work for this
purpose too.

--
Tom Wheeler
http://www.tomwheeler.com/
Back to top
Wade Chandler
Posted via mailing list.





PostPosted: Thu Sep 04, 2008 1:45 pm    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

Are you sure you even need a different main class? There are many strategies for authentication in applications. Maybe you have some features you need enabled and disabled when you are or are not logged in, or maybe you don't want anything run until logged in, but a simple solution, so that you can log out and in is to use a GlassPane on the MainFrame, and you can use events in the module system to do such things. You can also use something like a central lookup, differing from the global, to allow your different modules, and their top components, to know when the user is logged in and out:
http://wadechandler.blogspot.com/2007/12/central-lookup-creating-central.html

If you need a top component library which you can use to enable and disable specific top coponents by placing a glass pane over them and some other information, you can use root pane top components:
http://wadechandler.blogspot.com/2008/04/who-says-rootpane-always-has-to-be-at.html

and if you need the sources for the root pane top component you can see:
http://hg.netbeans.org/platformx

Wade

==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org



----- Original Message ----
Quote:
From: kameleon527 <address-removed>
To: address-removed
Sent: Monday, September 1, 2008 6:58:52 PM
Subject: [openide-dev] Specifying the Main class - netbeans.mainclass

I've been looking at the article on how to specify a main class:



http://wiki.netbeans.org/DevFaqPlatformAppAuthStrategies



Unfortunately, there's a part of it that is not clear. It states that the main
class should be "present in the startup classpath (you can put it alongside
core.jar in platform8/core or similar)"



Is there a standard way of doing this? How is the startup classpath formed? Do
I have to hack away at the build scripts to get my main class copied to
"platform8/core" directory? Is there an easier way?



Thanks for the help.



Scott
Back to top
Jan Vermeulen
Posted via mailing list.





PostPosted: Tue Sep 09, 2008 8:32 am    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

I've also been struggling with this as I want to display a simple login dialog before my application starts up and this seemed like the most logical and simplest way to do things rather than trying to use the module system.

2008/9/3 Tom Wheeler <address-removed ([email]address-removed[/email])>
Quote:

On 9/1/08, kameleon527 <address-removed ([email]address-removed[/email])> wrote:
Quote:
Is there a standard way of doing this? How is the startup classpath formed?
Do I have to hack away at the build scripts to get my main class copied
to "platform8/core" directory? Is there an easier way?



I have not seen any documentation about how the classpath is formed,
although what is used for the platform as a whole is logged to STDERR
at startup so it's easy to see what is there.

I found the following useful information in the overview of the runtime infrastructure:
I would like to use %CLASSPATH% / $CLASSPATH
NetBeans ignores %CLASSPATH% / $CLASSPATH environment variables and defines its own classpath containing minimal set of classes required to start the application using -classpath parameter passed to JVM. All other classes are loaded by classloaders created during runtime and briefly described in this document. If it is really neceseary to add more classes or resources to application classloader --cp:a or --cp:p options of launcher can be used

Quote:
Hacking the build scripts is pretty easy because there are a lot of
places where you can hook into the build by simply adding a target to
the suite's build.xml.

I found that the only location in the classpath that is not in the NetBeans directory (thanks to Tom pointing out I could see it in the Output window) is ${NBPROJECT}/build/cluster/core/locale/. So I put the following to my suite's build.xml:

<copy file="MainClass/dist/MainClass.jar" todir="build/cluster/core/locale"/>

(my MainClass project directory is located inside my module suite's project directory)


Quote:
I thought of an alternative approach might work although I have not
tested it -- your feedback is welcome and I'll update the FAQ
accordingly. You can prepend an arbitrary JAR to the classpath
(regardless of its location) by adding a startup parameter like this:

--cp:p c:/path/to/mylibrary.jar

I saw this right below the section I previously quoted from the Module System runtime infrastructure overview:
Using lib/ext/ or -cp sounds much easier but someone told me not to do it
The reason is similar to why JDK documentation about setting the class path for Windows or Solaris states that -classpath is prefered over environment variables. Adding classes (resources) to lib/ext/ affects all Java applications running using this Java installation. Use of --cp affects all modules and for example prevents the possibility to have more modules depending on different version of the same library.Perhaps this caveat should also be included in the FAQ if the -cp:p option is to be discussed?

After getting this to work I'm beginning to understand why Wade suggested alternative strategies. I completely misunderstood how specifying an alternative mainclass worked. Only after finding this FAQ which seems to be a compilation of the DevFaq sections on the wiki. But interestingly I couldn't find the section that helped in the end in any Wiki article. Look at the "How to measure performance/responsiveness" section right above this section.

In short, the only way I could see to replace the mainclass is with a flag to the JVM: -J-Dnetbeans.mainclass=za.mydomain.myapp.MainClass.

To get this to work from my IDE I added the following line in my project.properties file: run.args.extra=-J-Dnetbeans.mainclass=za.mydomain.myapp.MainClass.

I realise the FAQ links to all the relevant pages that discuss these topics but for someone who has no idea what a system property is (and thinks it's a NetBeans RCP concept) the FAQs can be quite cryptic. May I update the DevFaqPlatformAppAuthStrategies page to give an example of how to specify the netbeans.mainclass system property?

That said, perhaps there's a better and more secure way of specifying a new main class?

I'm asking because from what I can see it's relatively simple to edit a plain text configuraion file and remove the parameters that point to the custom mainclass. This would then completely bypass the security feature my login dialog is trying to provide since the default org.netbeans.core.startup.Main.main(String) would be called and it would load all the modules in the suite. Unless each module that requires security somehow checks for something that the custom mainclass does and prevents itself from being loaded if the custom mainclass wasn't used.

Am I missing something?

Jan Vermeulen
--
If this belief from Heaven be sent,
If such be Nature's holy plan,
Have I not reason to lament
What man has made of man?
---------------WORDSWORTH
Lines Written in Early Spring
Back to top
kameleon527



Joined: 01 Sep 2008
Posts: 11

PostPosted: Tue Sep 23, 2008 4:17 am    Post subject: Reply with quote

Jan -

You probably want to check for authentication status in your module anyway (not sure how that would work)

However, there may be a way, perhaps painful, to achieve what you want. I looked through the source code to really understand the startup sequence. It seems overly complicated, but I'm sure there is a reason for the layers of indirection that they have. I've attached a test file with the a basic overview of what the layers are and what happens in them. You may be able to replace one of these layers.

Note that this is for a Windows platform. For Unix, I think the two .exe layers are replaced by shell scripts.

Hope this helps

Scott



NetbeansStartup.txt
 Description:

Download
 Filename:  NetbeansStartup.txt
 Filesize:  2.87 KB
 Downloaded:  565 Time(s)

Back to top
jeffreycoffield



Joined: 22 Aug 2013
Posts: 6
Location: California

PostPosted: Thu Jan 09, 2014 6:57 pm    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

Jan, (or anyone)

I also need to authenticate a network connection that many modules will use in our application and this seems the right place to do it. I basically have it working based on your post but I am wondering if this is still the best approach?

Jeff Coffield
www.digitalsynergyinc.com
Back to top
Tim Boudreau
Posted via mailing list.





PostPosted: Fri Jan 10, 2014 10:56 pm    Post subject: Specifying the Main class - netbeans.mainclass Reply with quote

That seems like a really low-level place to do it.  The more typical pattern for this is: - Have some modules which supply a UI via XML layers
 - Write a module which dynamically modifies the system filesystem and adds or removes those layers
 - Pop up a dialog on startup to log in
 - When the user logs in, add those layers in when they succeed, and the main window/menus/everything will update to include those things


You could do your authentication in a main class, but you still have to handle the case that someone yanks the network cable after startup - unless you're users are on The Nonexistent Network That Never Fails, you're going to need some behavior for that situation - this approach gives you a place to put that behavior.


-Tim
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo