Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is it possible to compile & run scala code dynamically within Java code.
It is possible to achieve a similar result with JS using mozilla rhino. But, I wonder if it is possible with scala?
Theoretically, yes. But you will need to do a lot of things:
ensure the user entered valid scala code
transfer that source code to the server
compile the scala code
run it from within your server (catch errors, deal with resource leaks, ...)
So, possible: yes. Reasonable: not so much.
Obviously: a lot of work
getting to a decent user experience: even more work (like: telling the user exactly where in his source code input your compilation step found a bug ... hard)
And of course: opens your system for a ton of attack vectors.
If you want your users to be able to run code on the backend server, one wonders: why don't they have admin access to that machine already, and are able to deploy there code right there on the server themselves?!
Sure, Scala has its REPL, and as that one comment pointing to an existing answer implies: it is definitely possible to do that.
But as said: we don't do things because we can, but because it makes sense doing it!
twitter util-eval library seems provide what I need, but it is discontinued.
Here is an old fork:
https://github.com/m3dev/twitter-util-eval
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
At work i often work with Spring Boot Backends. Every now and then i need to optimize methods to run faster, so that the user dont have to wait and the request doesn't time out.
After watching this video: https://youtu.be/oewDaISQpw0?t=566 . I really liked the idea of having execution time shown per line of code, rather than of the full method. I began searching for similar tools for Java, but found nothing.
So i began thinking of a own solution.
I created a class that takes a .java file and edits it in a way, that there is a time print after every line, compiles it and loads it into the code to execute it. Before execution i redirect the System.out stream to catch the time prints. This kinda works, but only for standalone classes with no dependencys, with does not really work for me with my Sring service depending on other services and repositories. So i thought about replacing the class at runtime with my edited class, which does not really work in java(?). I also tried to use a InvocationHandler to catch the method calls of my service and route them to my edited class, but i still would need the dependencys and apparently the method proxy does only really work for interfaces.
My goal would be to have method and class annotation, that would mark the classes/methods to be speedtested. When called their times would be recorded and served on an exposed endpoint as a formatted .html.
Im kinda out of ideas right now and could need some help.
Thanks in advance.
What you're looking for is a Profiler. Most can tell you execution time per method, and memory usage, identified as 'hotspots' - where either the majority of time is spent, or most memory consumed.
Netbeans has a built in Profiler feature:
https://netbeans.apache.org/kb/docs/java/profiler-intro.html
Also, take a look at VisualVM:
https://visualvm.github.io/download.html
There's other commercial products available too if you search for 'Java profiler'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I hope that someone can help me with my problem. I am quite new to stuff like Git, Spring Boot and in general Java (Maven Projects). But i want to try to modernize our archiving system for our PL/SQL scripts. Right now, we archive them by hand and zip a version with the old date to then reserv it, that no other developer can make changes at the same time. After finishing working on the script, the developer releases the script in a specific folder (release) where it gets tested. After a successful test, other developer can now finally work on the script again.
Now, i wanna try and modernize this whole procedure:
I wanna import all our PL/SQL scripts into GitLab
If some developer is working on a script and commits/pushes it, i want that a action happens, where the script gets also copied into our release-directory, where it can be tested from our consultant (in context of the specific ticket the script gets released to)
I dont excactly know if my thought fits in here but i think it would fit the modernizing concept, if a new branch would be used for this (developer/testing branch). So that after a period of 2 weeks (our scrum sprint) all changes could get merged into the master branch
I would like to know, what is the best way to realize this and how would i go forward. Because i dont know if my idea with GitLab + Spring Boot Application is the best in this scenario and even if it is, how do i manage to monitor that. Its the starting point that i am missing. Once its there i think i can handle everything but the beginning is my problem (and missing examples).
I am sorry in advance for my bad english and hope you can help me getting started with my idea :)
Thx
Steven
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a piece of java code I would like to run in my web browser and publish online. How can I do this without using applets? I have tried java vertx but I am not sure how to use it and there are no good tutorials online.
The short answer is you can't. Browsers don't "speak" Java natively, which is why applets required a plugin. As you probably know, Google is in the process of removing support for the plugin technology used by the Java plugin (NPAPI) and so soon Java won't work in Chrome at all (it already doesn't under Linux).
Your only real options are:
Provide a means of running it server-side, like http://ideone.com and various other "online" compilers do.
Translate it from Java to JavaScript (either manually or using a tool), which the browser can then run. But note that Java and JavaScript are not only markedly different languages despite a superficial similarity in syntax, but the standard environment for each is also quite different from the other.
How you do either of those is much too broad a question for SO.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I created a Java programm which works on the serverside to communicate with an Android-App over Sockets. Now I want to check wether it is secure to hacking. I also asked in the Security.SE forum but this is programming related. So what do I need to look for in my Java-program to make it heavy to be exploided?
The first thing to check would be the server it's running on. You can cerainly checkout the https://www.owasp.org/ website. It is always a good source of security threats. Then there are a lot of pentesting tools https://www.kali.org/ has many of them built in.
But the most important might be how you've designed your API, I mean you're not very specific about what you need to know but some rules that will certainly apply:
secure the communication
make sure id theft is as hard as possible
never store userpasswords yourself(use a tokenbased system like oauth)
Obfuscation via proguard makes the program harder to reverse engineer.
Obfuscation combined with Ahead-Of-Time Compilation
1) Obfuscate names and encrypt strings using the tools not relying on the application being delivered in bytecode form. Make sure to disable control/data flow obfuscations.
2) Compile the obfuscated application down to optimized native code.
see link
http://www.excelsior-usa.com/articles/java-obfuscators.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm writing small java networking programs for school; obviously RTFM is de rigueur, but in developing skeleton code is it efficient (it's obviously lazy) to just run it by the compiler to see if I've forgotten some checked exception (rather than: RTM-> manually check ...)?
One "Hack" I have done is make a script to periodically compile my c++ source file everytime I save it. Then script autoclears the terminal window and the top errors are visible. The window is also set as "always ontop". This catches semicolons and other trivial errors/typos very quickly and I can fix immediately.
I don't see why not do something similar in Java or any other language. I don't see this as lazy, it takes some effort to do, and it seams like a good tool for more than finding out if you are missing checked exceptions. You can even write a parser to be analyse the errors for you and give you copy & paste code to potentially fix some of the errors, like the checked exceptions.
For Java, eclipse does a really good job on the checked exception side, it even pre-inserts the exceptions for you when you press CTRL+1. When using eclipse I haven't had the need to do something similar as I did in c++ because eclipse does a good job parsing Java sources and putting a marker on errors such as typos and other things even before you save the file.
Yes - the compiler is an essential tool in developing anything that is more than 5 lines long. An IDE such as IntelliJ will compile real time as you type immediately highlighting errors.