I have an application developed in Java that's almost ready for distribution. However, I have a problem switching from my development env to publishing env, and back to development. For instance, in Eclipse, if I just want to do a test run via the run button, I have to change the code so my JMenuItems show up.
In my development environment I had the following that worked well:
JMenuItem[] appItems = new JMenuItem[2];
appItems[0] = new JMenu("New");
appItems[0].setIcon(new ImageIcon(../POS_System/images/new_icon_sm.png")));
But, as I near deployment, to get this to work in the deployable JAR, I need to alter the code:
JMenuItem[] appItems = new JMenuItem[2];
appItems[0] = new JMenu("New");
appItems[0].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new_icon_sm.png")));
This is order to reach into the JAR and get the appropriate image.
I have a lot of these JMenuItems. I'd really like to be able to test the app via the run button in Eclipse, as well as create a JAR without changing the code.
Is there a simple way to do this? I thought the getResource method would still allow me to use the JMenus, JMenuItems etc, but they aren't available when I run the program from Eclipse. It seems silly that I would have to keep switching back and forth.
I appreciate any help here.
If you do not want to move your images into the src/ folder as you have suggested, then in Eclipse, you should update your Eclipse configuration under the Project Prooperties -> Java Build Path and add an additional source folder, this one pointing to where you keep your images. I believe this will fix it.
Related
I have a HelloWorld Java app called FitnessTracker that I want to clone as another name, FDE3, leaving the original website in tact. I performed the following steps an attempt to do this. Please tell me where I went wrong and/or what else I need to do.
Change Context Root
Confirm Change Context Root
Still the original "FitnessTracker" name persists and I'm not sure how to get rid of it.
If I was able to successfully clone the FitnessTracker webapp as FDE3, I should be able to access the new site as
http://localhost:8080/FDE3
But I get an invalid resource error. Instead, the site is still accessible as
http://localhost:8080/FitnessTracker
..because of reminants of the old name.
What do I need to change within Spring Tool Suite to get the web app to use only the new name? To minimize chance of corruptying the project, I'd rather do it via the STS GUI over manual modification of any system file.
I see that the following file contains the text "FitnessTracker" but I would rather not modify it manully for fear of breaking. What GUI option controls this?
Search "fitnesstracker" (2 hits in 1 file)
C:\Dev\Workspace\FDE3\.settings\org.eclipse.wst.common.component (2 hits)
Line 2: <wb-module deploy-name="FitnessTracker">
Line 7: <property name="java-output-path" value="/FitnessTracker/target/classes"/>
Sorry for being a noob.
Update:
I'm not sure what I did, maybe just clean, refresh, open/close a million time, dunno, but now when I run the web server from with the Spring IDE the site is coming up using the FDE3 path, however, I am wondering why I see a reference to Fitness in Parens in the project node.
Earlier, it just displayed "FitnessTracker" in parens, now I see a full path to a Test folder...
Update 2:
When I copied the FitnessTracker project as FDE3, I didn't expect that the new FDE3 project would have any ties to FitnessTracker project and I didn't think that the new FD3 project would be in SVN until I added it to SVN, but based on the icons I see below, it looks like it is, (I'm new to SVN, too)
It looks like my issues are related to SVN.
Why is there a tie to the original FT project and why? How should I have clone the FitnessTracker project?
Yes, your issue is indeed related to SVN. Copying an SVN working copy will copy .svn folders inside that and will be pointing to the same URL in the SVN repository. What you have to do is an SVN Export of your FitnessTracker project to FitnessTracke-Ex first in either Tortoise or Subclipse SVN client and then import that project into your STS Eclipse environment. Finally you can copy and rename the FitnessTracke-Ex project FDE2 or FDE3
See this
post on how to Export a working copy
See this post on how to Import an existing project into Eclipse
So I wrote this program in Linux and it runs perfectly when I create a jar and run it.
But for some reason when I put this jar in windows it doesnt.
Some of it works but when I try to do a simple click action event it crashes and tells me
there is an
Exception in thread "AWT-EVentQueue-0" java.lang.NoClassDefFoundError: miginfocom/layout/cc
Well anyway I got rid of certain components of it and it works but with them it doesnt.
// MigLayout layout = new MigLayout("fillx");
JPanel content = new JPanel(/*layout*/);
/*CC componentConstraints = new CC();
CC c = new CC();
componentConstraints.alignX("center").spanX();
c.alignX("center").span();
c.alignY("bottom").span();*/
content.add(label/*, componentConstraints*/);
content.add(label1/*,c*/);
// after this I add it to a Jframe etc
Everything there that is commented out is the reason it wouldnt work on windows.
But it would on Linux, I have no idea why this is...
Can anyone tell why this is or where to find out. It would be much appreciated and useful for the future :)
I assume your classpath is not correct.
So the required libs (e.g MigLayout) cannot be found.
Windows uses different Path-Seperator (in classpath) than Linux.
You would have to create an "uberjar" if you expect to distribute just one JAR file and have everything working. On your dev machine you probably have access to your JAR's dependencies, but not so when you copy just the application JAR to Windows.
I'm pretty new to Java and Eclipse coming from an iOS/xCode background. I have an iOS project that has 2 builds, 1 that uses a test server and 1 that uses a live server. In xCode this was simply a case of adding a new build target, a Preprocessor Macro, than using #ifdef in code to use separate url's for each build.
Porting this over to Android, I have this list of things I need to do each time I want to build/test between the 2 versions
TO SWITCH BETWEEN LIVE AND TEST
Rename Application Package com.mybus.myapp/com.mybus.myapptestserver (Right click, Android Tools, Rename Application Package).
Rename com.mybus.myapp folder to com.mybus.myapptestserver.
Change Map API key in manifest
Change SENDER_ID in BeginActivity.java (Notification app ID).
Search and change all references com.mybus.myapp/com.mybus.myapptestserver (Including SharedPreferences).
Change URL's in ConnectionHelper.java and PasswordResetConnection.java
Change icon and label in Manifest for Application & BeginActivity.
Remove crash reporter (ACRA) from MyApplication.java.
Change .setSmallIcon(R.drawable.ic_test_launcher) & .setContentTitle("myapptestserver") in GCMIntentService.java
Surely there is an easier way to build seperate builds and allow them both on a device at the same time?
You could use Ant script to do this. Once you customise your Ant script to handle all these changes, you can get the final output by running the ant release command.
An small example from where you could start with. I have written a post about it. This ant script, doesn't change any values in files, but what it does, is outputs the final apk, with a chosen name format, and puts it in a specified folder.
http://techdroid.kbeanie.com/2011/09/automating-builds-on-android-part-1.html
http://techdroid.kbeanie.com/2011/09/automating-builds-on-android-part-2.html
Disclaimer: These are links to my blog posts.
I may have a corruption problem in Eclipse run configurations. This happened after I dragged (or copy-pasted, I don't remember) a Java class called MyClass from project1 to project2. Then I deleted project1. When I create a new run configuration the name given is MyClass (1). In other words, it thinks there is already a run configuration called MyClass, so the new one will have to have a number appended. (Edit: There is no existing MyClass run configuration so there is no apparent reason for the appended number. In fact, I deleted all of my run configurations.)
How can I easily clean up meta-data and be able to build again with minimal manual effort?
If there is a meta-data deletion recommendation that gets rid of more than just run configurations, that probably would still be a good solution, if it does not create a lot of manual work to get set up to work again.
Edit: The problem might be caused by the fact that there is a launch configuration named MyClass - project1 visible in the export dialogue. project1 no longer exists, but this remnant lives on, tying up the class name MyClass. I am not sure if there is a difference between a run configuration and a launch configuration.
AFAIK launch configurations are stored on:
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches
Take a look to the existent configurations and remove those that are not interesting to you.
And restart Eclipse
Open Eclipse. Follow Run => Run Configurations. You will see options on the left hand side. Under the Java Applications option, you will see the list of runnable classes (the ones have a main method). These class nodes on that list are right clickable. By right clicking on your running configuration, you will see New, Duplicate and Delete options. You can delete your old running configuration via delete option. To create a new running configuration, right click on Java Applications option and click on New and then configure it.
You could try starting eclipse with the -clean command line option.
On windows the easiest way to do that is to copy your shortcut to eclipse and add the option to the arguments list, then start using the new shortcut.
I use eclipse to work on an application which was originally created independently of eclipse. As such, the application's directory structure is decidedly not eclipse-friendly.
I want to programmatically generate a project for the application. The .project and .classpath files are easy enough to figure out, and I've learned that projects are stored in the workspace under <workspace>/.metadata/.plugins/org.eclipse.core.resources/.projects
Unfortunately, some of the files under here (particularly .location) seem to be encoded in some kind of binary format. On a hunch I tried to deserialize it using ObjectInputStream - no dice. So it doesn't appear to be a serialized java object.
My question is: is there a way to generate these files automatically?
For the curious, the error I get trying to deserialize the .location file is the following:
java.io.StreamCorruptedException: java.io.StreamCorruptedException: invalid stream header: 40B18B81
Update: My goal here is to be able to replace the New Java Project wizard with a command-line script or program. The reason is the application in question is actually a very large J2EE/weblogic application, which I like to break down into a largish (nearly 20) collection of subprojects. Complicating matters, we use clearcase for SCM and create a new branch for every release. This means I need to recreate these projects for every development view (branch) I create. This happens often enough to automate.
You should be able to accomplish this by writing a small Eclipse plugin. You could even extend it out to being a "headless" RCP app, and pass in the command line arguments you need.
The barebones code to create a project is:
IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("DesiredProjectName");
project.create(progressMonitor);
project.open(progressMonitor);
Just take a look at the eclipse code for the Import Project wizard to give you a better idea of where to go with it.
Use AntEclipse
It can create eclipse projects from ant.
To create java project you can use JavaCore from org.eclipse.jdt.core.JavaCore. As a sourceProject you can use generic project item, which has been suggested by #James Van Huis
IJavaProject javaSourceProject = JavaCore.create(sourceProject);