GWT project and Eclipse linked resources - java

I have to use a Javascript file in my GWT Project. This Javascript is in a common library project and I deploy it together with my GWT Project using ANT.
So, I have no problem in production environment: but I cannot test it in development phase.
I tried to create an Eclipse link to Javascript resource but seem that GWT "can't see it".
Some behavior with other kind of resources (images, css etc.).
Is it a bug or is there another way to do?
I'm using Eclipse Juno, GWT 2.5.0 and Debian 7.0.
Thank you.

Can you just use script tag in your project's .html file?

If you're using some kind of source control, it usually has a way to make a link to a dependent project or file. Simply include that link in your GWT Project, and reference the file through there.
If you can't or don't want to do it through your source control, do it through your OS. Since you're using Linux, simply make a symbolic link to the common file/folder using ln -s (if you were using Windows, you'd need to run mklink from the command line), and reference the file that way.
In either case - source control or OS - you'll be able to see the file(s) when you refresh your project in Eclipse, and modifying one will modify the other in its own directory.
Edit - information on symbolic links in CVS
I haven't played with CVS in quite some time, so can't speak much about its capabilities for symbolic links. A bit of googling said it's not supported, though there are workarounds. One workaround is to add script files that run during checkout. That sounds like it may still be tough to make OS-agnostic. I did find one site that mentioned using module aliases to get the same result. Maybe that will give what you need. An excerpt from the site follows:
One common way to handle situations like this in CVS is to alias the
collection in a modules file rule. -Checkout the "CVSROOT" module and
you'll find the "modules" file; simply change it and check it in like
anything else, with the exception that when you check in CVSROOT files
they "activate" at the same time. The example below may look a little
kludgy, and it is because AFAIK you can't redefine a directory and alias
it at the same time, sadly. I'll use a typical Java situation as its
package system lends itself well to this kind of thing:
Real module directories are "a", "b", and "common"
Directory alias for all common srouce
_common_src_all -d src/com/mycompany/common common/src/com/mycompany/common
Full "A" project including common
a_all &a &_common_src_all
Full "B" project including common
b_all &b &_common_src_all

Related

How to make Eclipse package ONLY required libraries?

After developing a java app in Eclipse, I would like to deploy it by packaging it into a runnable .jar with only the minimum necessary by the main method and its dependencies.
I have several packages in my workspace I work with too, but do not need to be in the resulting .jar file.
When I try to export, it clearly says that the required libs will be there, but also the other independent packages are inside too. (With the Export option happen exactly the same)
I choose to export only the Main class of the com.project... package, but also the test.project... has been packaged.
In the project I have both com... and test... packages obviously.
How could I force it to truly package only the required ones?
Thanks in advance.
TEMPORARY ANSWER (2019-07-03):
Seems that, for now, there is no way to achieve this automatically, thus the answer from #arnonuem seems a good workaround.
If better news, please feel free to improve this thread.
Thank you all.
I would create an ANT file for this specific task. There you can freely customize which packages should be compiled into the jar and which not.
Please inspire yourself reading this example.
For a general overview what i am talking about you could take a quick look into this.
https://howtodoinjava.com/ant/ant-build-jar-file-example/
Please focus on
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath"
includes="src/path/to/TheClassToBeIncluded.java" />
For more detailed information on how to include or exclude files or packages you should refer to the documentation over here:
https://ant.apache.org/manual/Tasks/javac.html
At the bottom of this page there is a list with valid build parameters.
First of all, we have to distinguish build and export.
Build transfers .java source code into .class byte code and mostly copies other resources. While doing that it usually merges all source folders into a single bin folder.
Export runs a build (or relies on Build Automatically) and then modifies the resulting .class files and other resources. Usually it packages them into one or more .jar files.
Therefore, our solution includes two steps:
build everything that is unwanted for export into a separate folder (or more)
export from a specific folder (or more)
For step 1, refer to this answer on Stack Overflow.
In a nutshell: Go to Project Properties > Java Build Path > Source tab > Allow output folder for source folders. This enables you to configure a specific output folder for each source folder in the centered viewer.
For step 2, we need to understand that eclipse's Runnable Jar File Export relies on a Launch Configuration.
So before exporting, go to Run > Run Configurations..., select the Classpath tab, remove the default User Entries and hit Advanced.... Now you can Add Folders containing your built classes.
You might want to use separate Run Configurations for internal testing and exporting.
I have struggled with this problem on and off for years, supposing it was just me who was failing to find the right solution. Possible solutions always seem to involve detailed manual configuration e.g. configuration of the build path, or selection of the folders from which classes are exported into a jar, or learning ant, but which still requires manual configuration. The problem is that the inter-dependencies between classes (and packages) are complex - imagine drawing a network diagram from import statements. Manual configuration is time-consuming, error-prone and, I think, infeasible except in simple cases. I am a bit stunned. If there is no automatic solution for selecting necessary classes, I suppose people are regularly exporting their entire code base and that the world is full of bloated jars ... (and, incidentally, without obfuscation, the entire source code base is thereby made available through reverse engineering).

Packaging Java/Netbeans project for easy end user usage

(I guess this is less a question than a report/personal experience looking for critique or whatever. The project described contains an external library.)
Many users need more than all the help they can get in trying to execute a Java project. I'm describing ways that come to mind for getting a project to a user--none particularly foolproof--and wonder if I'm missing some much-easier method.
One way: Do what the dist folder README says: "To distribute this project, right click to zip up the dist folder (including the lib folder) and distribute the ZIP file" and, I'll add, hope the user has the skill to extract and then find the executable jar. And to go get a JRE if need be.
A seamless way: use Netbeans 7.4 Native Java Packaging, which produces a self-extracting executable (an "EXE installer"; an .EXE file) and runs whether or not user has JRE installed. It can be executed from Windows Search box (and can be uninstalled via Control Panel). Method assumes NO JRE available; humongous (30MB) .EXE was produced. [See ((this link))
Unhappy medium: forget the admirable use of an external library; just add the package containing the library's source code. This produces a .jar that runs if JRE is present; otherwise user still has to get involved.
None of the above are exactly ideal ways of providing an app for a tech-challenged user.
I was going to include Webstart as a fourth and what I hoped best alternative, but for no apparent reason, I can't get a compilation that works inside my own Netbeans IDE. Calls to the utility modules--now included in the GUI part of the project; external in NO WAY--never pop up the dialogs they should.

How to debug Java code when it is out of sync?

One of the problems I'm running into is that my jar files and my source files don't match.
I'd like to:
Be Notified when when source and binary don't match (I think Visual Studio can do something like this...)
Set break points not by line, but by function. For example, set a break point at the entry of function foo().
I use eclipse mainly; so Solutions for eclipse would be most appreciated, but any IDE (or command line debugger) will do.
Thanks!
When developing just use and link to .class files that are saved by your IDE.
If your project starts to grow to a point where it's really useful to link to a .jar you're better off treating the jar's as separate projects.
Go to Project tab in Eclipse and then
click clean: Project->Clean…
click build automatically: Project->Build automatically
Use method breakpoints instead of line breakpoints. They can be set to halt on entering/exiting a method. You get them by double clicking the left editor side in a line containing a method declaration.
The debug information is limited to line numbers in the source file... I do agree that having a warning that the lines are wrong would be nice, but that would require more meta data in the jar than I think is available...
You might want to consider addressing the challenge with a change in your build process. This isn't exactly answering your question, but hopefully it will give you a strategy that will address the underlying problem.
When you generate the jar for deployment, also generate a jar with the binary AND source. For investigating the source code of a stack trace on the live server, set up a separate project in eclipse and have the binary+source jar be on the classpath. You may have to explicitly set the source code location back to the same jar (though I think Eclipse will just do this automatically).
Then you just have to add copying of the binary+source jar into the appropriate location in your workspace as you do your deployments (preferably with a deployment script).
If it's your server, you may want to even consider deploying the binary+source jar to the live server - that way you will always be able to get at the source.

How to refer a jar outside exe in Java desktop application?

I have a Java application installed. The jar is bundled into an .exe file using Launch4J. Now I want to create a patch for this application.
If I create another jar containing only updated files, how can I refer it in the original code?
I have java application installed. ..Now I want to create a patch for this application.
This is one of the strengths of the Java Web Start launch technology that comes with the J2SE. Simply update the Jar on the server, and the next time the app. launches, it will be updated.
The update can be honed for your use-case, configured to be done lazily or eagerly, before or after launch, or even programatically controlled using the JNLP API's DownloadService.
..And the jar is bundlled into an .exe file ..
'Unfortunately', JWS works on Windows, ..and Mac., and *nix - so you may have to expand your horizons.
BTW - I have no idea how to do the same with Launch4J, but then, that is really the wrong question. I aim to provide an answer to the right question, which is "How do I deploy & update a Java rich client?". ;)
I've never worked with Launch4J, however I think you should try to affect the classpath. JRE always loads the classes from the classpath. From this point of view, jars have no added value and just serve as a containers for your *.class files and resources.
Now, if you succeed to configure your tool to do something like:
classpath = C:\Temp\my_patch_path;$your_current_classpath
then its enough to put your changed files into C:\Temp\my_patch_path (of course preserving the package structure). JRE will load your classes first in this case.
Hope, this helps
Mark
It is might not be possible to do this without changing the contents of the exe.

lambdaj installation

we have downloaded jar files for lambdaj and its dependencies which are again jar files.
we do not know how to go about it. we have copied these files in the
C:\Program Files\Java\jre6\lib\ext
have set the class path in environment variales as:
variable: classpath
path: C:\Program Files\Java\jre6\lib\ext
but we do not know how to go further. we want to run some lambdaj programs.
can anyone suggest how to run lambdaj programs?
You would run a Java program that requires lambdaj in exactly the same way you'd run any other java program with an external dependency, i.e. by invoking the java executable passing in the fully-qualified name of the Main class, or the JAR with an appropriate manifest, or by deploying it in a servlet container, etc. Additionally you should be putting the LambdaJ JAR on the classpath for this invocation, not in the lib folder for your entire JVM.
What have you tried so far and why/how is it not working? Your question at the moment is a bit analogous to "I want to use Microsoft Word to view some Word documents, how do I do this?".
Update for comment 1: You said "it's not working". That doesn't help anyone address your problem as it gives no clue what you expected to happen and what you observed, only that they were different. As for where JAR files can be stored - you can put them in any directory, so long as that directory is on the classpath (or you add it to the classpath) of the Java application that runs. The canonical place to put external dependencies is in a folder called lib below the root of your project, but the important thing is that you choose somewhere consistent and sensible.
It sounds like you don't quite grok Java and classpaths yet. If you have followed some tutorials and are still stuck, ask for help to let you understand. Adding more detail to your question, including the layout of your files, the commands you issued, and the response that came back would be useful too.
If you are using Netbeans create a project and right click on the Libraries folder within the desired project. Click Add JAR/Folder...

Categories