Sharing resources between Java projects in Eclipse - java

I am making a game using a client-server model. Currently I have 3 projects: client, server, and common. Currently all of the resources for the game are in a folder inside the common project, which is recognised as a source folder by Eclipse.
This allows me to access the resources from within the client and server projects using:
InputStream in = SomeClass.class.getClassLoader().getResourceAsStream(filename);
The problem is that this method only works for reading the files, but I want to be able to write to these files, too (e.g. saving a level in the level editor).
I'm imagining the built project looking something like this:
Game/resources/...
Game/client.jar
Game/server.jar
Can anyone recommend a way that I can configure my project so that Eclipse will build it in this way, or in such a way that both the client and server will be able to access the shared resources?

Related

Given a JAR file, allegedly contains web server, how do I deploy it?

I've been handed a JAR file, told it contains a web application, and instructed to deploy it. I'm familiar with java as a language, but I have next to no experience with its web ecosystem. Trying to run it as an executable, I find out it has no main class, so I take a look at the contents, and find that it has a META-INF/web-fragment.xml file, along with a couple of Servlet classes and some config files referenced in the xml. It looks like there is basically everything here for a complete application, but I have no idea how to actually deploy it, and google only yields tutorials on how to build these things from scratch with IDEs and deploy using maven plugins and goals.
Assuming that building from source is out of the question and I only have standard unix and java CLI tools available, based on the information provided (And I can provide more if necessary), what is the simplest way to get this up and running?
A web applicaton should be in a WAR file, not a JAR file, and you should only need to just drop it into the webapp directory of your Tomcat, or follow the instructions for whatever other container you're using.
If it's only a fragment, as appears from the XML, (a) it isn't a webapp, only part of one, and (b) you personally can't deploy it at all. You need the whole thing.
Send the assignment back for clarification.

How can I share code between a codenameone project and a regular java project?

I have a codenameone project that is exchanging json messages via websockets with a server implemented in java.
The json messages are mapped to pojos on both sides.
I would like to define the pojos only once and reuse them on both sides.
Is there a simple way to do this ? Is there any way to do this ?
In my experience, the best way to do this is to keep your POJOs in a third project, and create a build script to "copy" them into each project that uses them.
If you would rather copy them as "binaries" rather than source, you could adjust your build script to compile them into a cn1lib and jar, copy the jar to the server classpath (or into maven), and copy the cn1lib into the client libs.

How to set up a system that reads PMML files which I create using R?

For the past few days I'm stuck at trying to pass a PMML file with .xml extension that I created using R and pmml package. After creating a iris.xml PMML file I have no where to go, actually I don't know what to look for. And then I saw Alex Guazzelli's video here, where he tells us to use ADAPA from Zementis to run the PMML files that are created from R.
What I took away from the video is,
I want to do something similar as shown, like uploading my PMML file at some place and input my test files frequently to get the corresponding predicted values.
ADAPA looks great, but looks like it also costs some money. So I would like to look for an alternative, which might not be as user friendly as ADAPA.
Then I found this page where the author says,
So the first step was to get the engine running. I experienced some small problems but Scott fixed them very fast and offered a new war file ready for deployment inside tomcat. It can be obtained under http://code.google.com/p/openscoring/. If you still encounter some problems you could also try my war file. It was built with java version “1.6.0_26” and tested under tomcat 7. After installing the war file using the management console, you could test it by sending a POST request in XML like the following to ‘http://localhost:8080/OpenScoring/Scoring’
Then I found jpmml. The problem here is the package names are very confusing, I don't know which one to install. In fact I don't know how to install each of them. I have basic knowledge of Java, apparently it isn't helpful in the current scenario.
Desperately looking forward for any kind of help.
How do the data flows in your application look like? Zementis' ADAPA is a standalone web service, which lets you do scoring in a request/response fashion. This works for web applications, but is clearly sub-optimal if you're looking to score larger amounts of data.
The JPMML project provides "PMML runtimes" for most popular big data frameworks. For example, if your application is tied to Apache Spark, then you would go for the JPMML-Spark project, if tied to Apache Hive/Pig, then for the JPMML-Pig project, etc. For a simple REST web service you should check out the Openscoring project, which is functionally identical to Zementis' ADAPA.
All JPMML projects can be built from their source checkout using Apache Maven by issuing the following command:
mvn clean install
Some JPMML projects also have their binaries distributed via the Maven Central repository. If you're looking for the Openscoring WAR file, then you need to search for "openscoring-webapp" and on the results page click the "download WAR" link (at the time of writing this, you would get openscoring-webapp-1.2.12.war). This is a standard WAR file that can be dropped to the auto deploy folder of your favourite Java web server (Tomcat?) as it is. The REST API of the web service is fully documented in the README file of the Openscoring project.

Dart: How to setup a project

Since my attempt to set up a Dart project myself I think I miss something fundamental since I didn't succeeded. So I still need the help of the community.
Coming from GWT I am used to a single application forming a single JS file which is ran and will augment a HTML element once it is recognized by the application.
There will be usually two JS files, one for the user-frontend and the web applications backend application.
I want a solution with an incremental build during development time (which I guess Dart offers when used in Dartium)
I have an inhouse web framework that I want to be started and used to send the Dart files for the Dartium session. How this will integrate and interfere with the debug sessions?
Update regarding web framework:
The web framework is a component based rendering engine, including database and uses its own resource management including everything http related like setting the cache flags etc. Its about 1.5 MB with 1200+ tests. Its simply everything you need starting with a simple servlet. Its also using an embedded jetty.
The relevance here is that I need to know how the debugger connects to Dartium and how it finds the files once an instance is running and delivered a html file containing dartium sources, so how can I start my own web server at a given port and still have dartium debug capabilities?
Update regarding the former answers:
I tried it but after two days gave up to learn more and do some other stuff. I just don't know why it is just not possible to add a simple file to the root package of my Dart module like the good old package.html (javadoc) fil. I then just add the Dart libaries to my project and the Dart plugin adds the required Dart nature to the project and creates a builder entry, done. Why do I have to do all the fuzz. Or even better why cant I just annotate my Module's main class to form a module and so I can replace the extra file completely?
I guess the Dart plugin has a model of the Dart code already so discovery is done on the fly in Eclipse.
I also do not know why I cant put my dart code in a dart source folder like src/dart/main and src/dart/test.
Or is this possible? I am still trying to get this done. I will use a fresh Eclipse 3.8 install and check if I can get Dartium to work. Just installing the plugin seams not to do the trick.
Update regarding the JS generation:
I cannot understand why Dart is not offering an incremental build of JS files. Even if it is a single file. It should not be that hard to debundle the given compile steps. I guess it will be something like compile each source file independently and link those together, do some tree shaking and done. Would be awesome if this can be made possible. Remember one can hold a model of the output file in memory (or on disk) and know what part of the js relates to what source file. Then just look up the link symbol tables and write back the part that has changed.
For me the killer feature for Dart would be the ease of configuration as I outlined and the incremental build of JS files making co-developing in JS a no-brainer. I guess in the end both JS files will be just about 750kb combined. So all the stuff with additional compression would not force me to upgrade my 8GB memory or will stress my SSD at all (350MB/sec for writes in burst mode).
Is there any work planed on this? Would be great to have Dart as the final solution for JS creation but to be honest I do not understand why GWT is the way to create JS this way. An incremental build and easy setup for GWT would be also welcome.
Seems not to be a question ...
In Dart you have usually one JS file because Dart on the server runs native (without transpiling)
With Dartium you don't have a build at all because it also runs Dart natively.
You build to JavaScript only for deployment (and of course to test the build output before deployment).
The debugging is done by Dartium itself (you can use the Chrome DevTools debugger without DartEditor if you want). DartEditor access the debugger API of Dartium and acts as a remote display/control.
Debugging web clients loaded from other webservers is supported.
What might cause some work is setting up your custom web server so that it forwards requests to source files to pub serve the web server used by DartEditor (or standalone).
pub serve runs transformers (on the fly code transformations/generation). Some framework depend on transformers being run on the code to make it functional.
I have no idea what this means but I don't use Eclipse/Dart plugin.
[Update regarding the former answers] I tried it but after two
days gave up to learn more and do some other stuff. I just dont
know why it is just not possible to add a simple file to the
root package of my module like the good old package.html file
for the java docs and then all i do is add the Dart libaries
to my project and the Dart plugin adds the nature to it and
creates a builder entry, done. Why do I have to do all the fuzz.
Or even better why cant I just annotate my Module's main class
to form a module and so I can replace the extra files?
To integrate Dart with your Java project create the Dart project independent from your project and move the Dart build output to a directory where you have your other static files.
While development configure your web server to forward to pub serve as explained above.
As already stated in my first answer, this
[Update regarding the JS generation] I can not understand why
dartium is not offering an incremental build of JS files. Even
if it is a single file. It should not be that hard to debundle
the given compile steps. I guess it will be something like
compile a single file and link those then the magical tree
shake and done
is irrelevant. You don't do anything with JavaScript while developing.
If you load the page with a non-Dartium browser pub serve will serve
built JavaScript instead of Dart. Incremental build is in the works
to improve responsiveness. But incremental build is not available
for file generation (would make sense anyway IMHO).

Dart in Existing Eclipse Java Project

When I add simple dart files anywhere in my existing Eclipse project, what do I have to do and what will be the limitiations and work arounds in order to make it work.
Update:
Some additional information might be helpful. What I use is a custom web server serving dart and js as simple files (dynamically on request). So I can not simply follow the dart way of things. The dart files would be rather sources only being used during development and converted to js files before the actual check in of the new version.
Therefore I would like to add the dart files in exactly the same mannor I add my other source. So i would love to have something like src/main/dart and src/test/dart or something.
I would also like being able to run dart in the stand alone vm (stand alone application) instead of the web / browser to simplify some development steps like the development of the model / business layer and add simplified testing. Also we want to evaluate if there is the possibility to start dart side processes on the server for additional simplification.
So the scenario is:
Put dart files anywhere (especially in the source tree)
The web framework is non-standard programmer friendly, we can simply add resources from anywhere under virtual directories (src/main/dart -> localhost/dart/)
The dart files will be converted to js prior to checkin
Dart should be able to pickup the right files on debug
Testing and debugging should be possible in standalone mode and in using Dartium
So how can I do this what should I be able to configure.
Update2:
Dart will be used as a JavaScript replacement here. So in the end this is a mid-size web project where the JS/Dart code provides the glue to make the pages functional. It also will drive the backend application which might be single paged but its not decided yet. Best would be to see the dart application as of two applications at once where the backedn application is distinct from the front end functionality that is dynamically added as needed.
For the compilation process to JS I would not mind to create a simple program copying files, compile and recopy files and done. Wouldnt take that long since it would be only needed once or twice a day.
You need to create a Dart pub package.
That is a directory containing the file pubspec.yaml.
You can put the Dart script and HTML files in the web and or lib subdirectory of the Dart package.
When you run pub build the deployable output is generated in the build/web subdirectory.
This deployable files can be served by your web server like any other static web content like HTML, CSS, JavaScript files.
update
I can't think of a way doing this
Dart isn't like JavaScript where you add some event handler script here and there.
I can't see how this would make sense anyway. More information about what you want Dart do for you is necessary to answer this - see my comment above.
You need the build step prior to serve generated JavaScript.
A Dart app is built entirely at once not file by file.
this is what pub build does. The output is written to my_dart_package/build/web
You can debug Dart as Dart (in Dartium, DartEditor or any other IDE that supports debugging Dart code) or after the build step using source maps in a browser like Chrome, FireFox, ...
You can debug non-web code standalone using the debugger of DartEditor, WebStorm, ...
You can create unit tests that invoke methods on Dart classes (model classes, PODO, ...) without a browser.
When you want to debug code that depends on the dart:html package you can only do it using a browser.
update2
You could create three packages
- server
- client
- shared
Dynamically loading functionality is already supported. The functionality has to be available at build time but can be loaded 'deferred' at first access or on request but this has nothing to do with the server part of Dart this is client-only functionality. Any web server can be used for that (for example Apache).
The server usually provided some data APIs (HTTP, REST, WebSocket, ...) for the client.

Categories