Hi everyone !
I'm facing a problem since I'm migrating my app from Java6 to Java8 for MacOS (and other OS but with windows/linux there is NO problem !).
When I was using Java6 I used MacOS APP "App Bundler" to do the package.
This tools reference to a plist file that contains all package information and provide the ability to add an option "WorkingDirectory" and a variable $APP_PACKAGE to set the working directory of the package inside the package like that:
<key>WorkingDirectory</key>
<string>$$APP_PACKAGE/Contents/Resources/Java</string>
Unfortunately, this option "WorkingDirectory" does not exist with the bundler appbundler that provides support for Java 6 superior versions.
So I googled a lot and found this issue; Apple Issue
So I added <option value="-Duser.dir=$APP_ROOT/Contents/Resources"/> to my plist file via ant task like that:
<key>JVMOptions</key>
<array>
<string>-Xdock:icon=Contents/Resources/${bundle.icon}</string>
<string>-Duser.dir=$APP_ROOT/Contents/Resources</string>
</array>
And I tied also this:
<option value="-Duser.dir=$APP_ROOT/Contents/Java" />
<argument value="-Duser.dir=$APP_ROOT/Contents/Java"/>
Without success :-(
And I added a big "verrue" on early start of my Java application like that (as said here):
String os = System.getProperty("os.name").toLowerCase();
System.out.println("os:" +os);
if (os.indexOf( "mac" ) >= 0){
try {
System.setProperty("user.dir", new File(".").getCanonicalPath());
System.out.println("user dir:" +System.getProperty("user.dir"));
System.out.println(new File(".").toURI());
System.out.println("Working directory: "+(new File(".").getCanonicalPath()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
But nothing works; when I was creating file from the previous Java application they were created into the application working dir like /Applications/MyApp.app/Content/Java, but know when I create a file/folder it is created under /Users/MyUserName
I also follow this PATCH (I post a question) and compile a new jar but the <string>-Duser.dir=$APP_PATH/Contents/Java</string> does not do the job, the env variable is not user system created and used!
It's driving me silly... Any idea ? Regards !!
[EDIT1] As a workaround and because it is also simple but too bad I just changed all my relative paths (some at least !) like that:
String path = new File(".").getCanonicalPath();
File myFile = new File(path+File.separator+"MyFile");
It acts similar to set the working directory variable but I have to change a lot of my code rather than use a single option (and on Linux and Windows I do not have this type of problem) :-( Anyway thanks to Trejkaz to have answer on my issue... and sorry for my misspellings and my poor English.
Another time, Regards !!
[EDIT2] So I edited all my relative paths but I had a second problem with the appbundle: Every ProcessBuilder commands fails when launched by the bundle but succeed when clicking on the jar so I used "desktop" intead like this:
DesktopApi desktopApi = new DesktopApi();
desktopApi.open("path-to-my-jar"+File.Separator+"MyJar.jar");
I use the class 'DesktopApi' found here coded by MightyPork (Regards !!) as sometimes desktop command provided by JRE fails...
So I'm done with this fu***** packaging now !!! Regards !!
Related
I have just setup Android Studio and started a simple application. Well started is an over statement, I got stuck on first few lines and am unable to import JFrame into android studio.
I have the latest SDK installed aling with LibGDX. I am still not able to setup JFrame. I have searched the net/youtube and no solutions have been found.
I can see the javax and swing in my external libraries but just cannot import.
Any ideas what I am doing wrong or not doing?
I am not looking for a "how to tutorial", I just a pointer where I should go hunting for the answer.
wow, not huge amount of response.
Please advise if I have asked a stupid question or difficult question.
public hungryDog() {
JFrame jframe = new JFrame();
Timer timer = new Timer(20, this);
renderer = new Renderer();
rand = new Random();
jframe.add(renderer);
jframe.setTitle("Hungry Dog");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(WIDTH, HEIGHT);
jframe.addMouseListener(this);
jframe.addKeyListener(this);
jframe.setResizable(false);
jframe.setVisible(true);
dog = new Rectangle(WIDTH / 2 - 10, HEIGHT / 2 - 10, 20, 20);
columns = new ArrayList<Rectangle>();
addColumn(true);
addColumn(true);
addColumn(true);
addColumn(true);
timer.start();
}
You can't use Swing on Android. Android has its own UI framework which is different, and Swing isn't supported. To see what Java APIs are supported on Android look at the API docs at http://developer.android.com/reference/packages.html
I used to have the same problem; here's how to solve it.
You see, we were trying to use swing lib in a totally wrong context, that is, within an Android app. As Scott Barta pointed out, Android has its own mechanisms for doing what we wanted to achieve and that's why IntelliJ didn't let us import anything that would interfere with Android API.
Hence, do NOT use Android app when, say, simply learning how to code in Java or, on a more advanced level, when testing/debugging your algorithms. Instead, build a standalone Java program (yes, in Android Studio). This very topic is covered here: Can Android Studio be used to run standard Java projects? , "Tested on Android Studio 0.8.6 - 1.0.2" by idunnololz). A few clarifying remarks to this solution:
1) wnen preparing your configuration (Run | Edit Configurations...), use your new Java module name and its main class in the appropriate fields.
2) before clicking Run make sure you selected same configuration.
Incidentally, there indeed IS a way to import swing library into any Android app: based on http://www.youtube.com/watch?v=fHEvI_G6UtI. Specifically, add a new line to build.gradle file for your Module:app:
compile files ('<path_to_your_jdk's_rt.jar>')
Like this:
compile files ('C:/Program Files/Java/jdk1.8.0_31/jre/lib/rt.jar')
Note single quotes and forward slashes. Then click Sync Gradle icon and enjoy the view.
In our particular case, however, the program won't run. The code itself will be clean, there'll be no errors; with swing lib well in place and connected, IntelliJ won't suspect a thing; the project WILL compile... but then we'll get a runtime error. Now your know why. On the other hand, this method works like magic when we do not interfere with Android API --- which we shouldn't in the first place.
That's all there is to it.
Yes you can. As addition to Igor's answer here are the steps:
Create new Android Studio project: File -> New -> New Project -> Phone and Tablet -> Add No Activity, select Java (not Kotlin) as language obviously.
Add new Java module: File -> New -> New Module -> Java Library
Remove Android module: File -> Project Structure -> Modules -> app, click - button.
NOTE: step 5 is probably not needed. Try without it first.
Edit build.gradle of your java module, and add in dependencies implementation fileTree pointing to the JRE you need.
Example of build.gradle:
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree ('/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre/lib/rt.jar')
}
sourceCompatibility = "6"
targetCompatibility = "6"
Now code completion works and you can even run the app:
Click on Add Configuration: near run button
Click on + -> Application
Select your Main Class
At Use classpath of module: select your java module there (not project's)
My developer friend who has the luxury of developing in a non-Windows environment has been raving about Compass. I finally decided I wanted to give it a try. I'm tired of trying to keep up with all of the intricacies of cross-browser CSS.
So, I found it on NuGet, and installed it.
I installs to my solutions root directory in the packages directory:
$(SolutionDir)packages\Ruby.Compass.0.12.2.3\
It comes with a Readme that states the following message:
Ruby Compass v. 0.12.2
Compass is installed in its own NuGet package dir, and available by
'compass' command in "packages\Ruby.Compass.0.12.2.3" folder.
To compile Compass files during build, add the next line to the
project pre-build events:
"$(SolutionDir)packages\Ruby.Compass.0.12.2.3\compass" compile
"$(ProjectDir)."
So, I placed the line in my pre-build events, saved, and tried to build my project. However, I get an error as follows:
The command
""$(SolutionDir)packages\Ruby.Compass.0.12.2.3\compass" compile "$(ProjectDir)."" exited with code 1.
Notice: It actually shows the full path to the ProjectDir and SolutionDir as it's supposed too in the error message. I replaced them with the tokens to keep the project name unanimous.
Let me mention that I tried variations of the suggestion pre-build line:
"$(SolutionDir)packages\Ruby.Compass.0.12.2.3\compass" compile "$(ProjectDir)"
"$(SolutionDir)packages\Ruby.Compass.0.12.2.3\compass" compile "$(ProjectDir)css"
"$(SolutionDir)packages\Ruby.Compass.0.12.2.3\compass" compile "$(ProjectDir)css\test.scss"
The first one just removed that trailing .. The second one pointed it to the directory where all my css files are stored. The third one pointed it to the exact file I was trying to compile was located.
I opened up compass.cmd which is the file it is calling, and it looks like the following:
#echo off
"%~dp0ruby\bin\compass" %*
I'm assuming this calls the compass file in the ruby/bin folder, which looks like this:
#!C:/downloads/ruby-2.0.0-p247-x64-mingw32/ruby-2.0.0-p247-x64-mingw32/bin/ruby.exe
#
# This file was generated by RubyGems.
#
# The application 'compass' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'compass', version
load Gem.bin_path('compass', 'compass', version)
From there, I'm not sure what is going on. I'm not a Ruby person.
Is there an issue that I'm overlooking here?
Has anyone else been able to install Ruby.Compass via NuGet?
How can I get this working in Visual Studio without having to fight with Ruby?
From: http://codewith.us/automating-css-generation-in-visual-studio-using-sasscompass/
"Note that, if there are issues with your SCSS files, you will receive some variation of the error below.
Error 36 The command "del "C:Projectspubliccss*.css" /S
compass compile "C:Projectspublic" --force" exited with code 1.
Open your Output window (click View -> Output or press Ctrl+W, O), and select “Build” in the “Show output from:” menu. Scroll up until you find your command in the log and you should get a little more insight into what portion of the command failed."
I have an Android project called my.android.project, and in my src directory, I have a few sub-packages called my.android.projectGUI, my.android.projectClasses, my.android.projectOthers.
I wish to change my package name to com.android.project instead. I have successfully done this with Android Tools->Rename Application Package. However, this didn't take care of my sub packages in my src directory. I wish to rename them to com.android.project.gui, com.android.project.classes, and com.android.project.others
In my.android.projectOthers, I have a java file AccessJNI.java that loads a JNI library that is linked to jni/myjnifiles/myjni.c
When I try to change the sub-packages individually via Refactor->Rename, it works for the all except for my.android.projectOthers. Once I rename this sub-package, Eclipse throws me an error for several JNI symbols, saying they could not be resolved. This happens despite me changing all JNI function calls in myjni.c from Java_my_android_projectOthers_AccessJNI_functionName() to Java_com_android_project.others_AccessJNI_functionName()
The strange thing is, ndk-build still builds the library correctly, but Eclipse cannot seem to resolve the JNI symbols.
Am I missing anything while renaming my sub-packages?
Thanks!
This happens despite me changing all JNI function calls in myjni.c from Java_my_android_projectOthers_AccessJNI_functionName() to Java_com_android_project.others_AccessJNI_functionName()
You should replace all JNI prefixes by Java_com_android_project_others_ and not Java_com_android_project.others_
I currently have Java ME SDK 3.0.5 installed and am running a MIDLET from Eclipse.
When I run the app under the emulator device I get the following data in the console:
Syntax:
emulator [arguments]
In order to get commands supported by given device run:
emulator.exe -Xdevice:<device name> -Xquery
Generic list of arguments is:
-version Display version information about the emulator
-help Display list of valid arguments
-classpath, -cp The class path for the VM
-D<name>=<value> Set a system property
-Xdebug Use a remote debugger
-Xrunjdwp:[transport=<transport>,address=<address>,server=<y/n>,
suspend=<y/n>]
Debugging options
-Xdevice:<device> Select a device skin for the emulator
-Xdomain:<domain_name>
Set the MIDlet suite's security domain
-Xmain:<main class name>
Run the main method of a Java class, as in Java SE
-Xquery Print device information
Everything seems to be alright, but I can't get any form of emulation to appear.
here is the code of my MIDLET, although I don't think the problem lies here.
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class Hello extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private Form screen;
public Hello() {
display = Display.getDisplay(this);
exitCommand = new Command ("Exit", Command.EXIT, 2);
screen = new Form ("Hello World");
StringItem strItem = new StringItem ("","Hello World");
screen.append (strItem);
screen.addCommand (exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {
// TODO Auto-generated method stub
}
public void destroyApp(boolean unconditional) {
// TODO Auto-generated method stub
}
public void commandAction (Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp (false);
notifyDestroyed();
}
}
}
The output is pretty simple, it's telling you that the command line syntax to the emulator is incorrect.
Go to the Java ME device settings and edit the emulator command line / start options to suit.
Switching IDE's may work for you as a short-term fix, but it's always better to get to the root of the issue. Plus it'll help you understand the emulator framework.
I switched over to Netbeans, which has integrated support for J2ME (as opposed to having to install a 3rd party plugin for Eclipse) and it now works perfectly.
I had a similar problem while running a basic JavaMe app on eclipse, "Corrupt JAR, error while reading". It worked for me after I followed this series for starters http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.mtj.doc.user/html/gettingstarted/prepare_workbench.html (try not to miss anything mentioned here).
Note, when you launch the app, use "Launch as emulated Java ME JAD"(-in the top right "Running" section on the page) from the "Application descriptor" (-from left menu.)
This is a late reply but might just help someone in future.
If you are adventurous and want to develop / run JavaME application without IDE's than I have some ray of hope, write a batch script (or shell script for linux system) to manually run the emulator with specific jad
Batch Script (run.bat)
"<javame-3.0-sdk-root-folder>\bin\emulator.exe"
-Xdescriptor:"<jad-filename-with-extension>" >> logs.txt
pause
exit
save the above script in the same folder as the application jad/jar. The console prints will be available in log.txt file.
Here is post how to run jar from emulator (Java ME SDK 3.0.5)
(How to run MIDLET in Java ME SDK 3.0.5 ::http://madhukaudantha.blogspot.com/2012/10/how-to-run-midlet-in-java-me-sdk-305.html
I have installed Eclipse 3.5.2 and today's Scala plugin from /update-current (that's Scala 2.8 final.) I can compile and run Scala projects consisting of a single singleton object that implements main().
But, if a project contains more classes, I receive the "Could not find the main class" error.
I have tried searching for the solution and I discovered:
Eclipse is correctly looking for the Main$ class, not the Main class
* under Debug Configurations, my main class is correctly identified as mypackage.Main
* my plugin is up to date and recommended for my version of Eclipse
* cleaning, restarting etc. doesn't help.
The same project will compile with scalac.
Thanks for any ideas on how to solve this.
EDIT: MatthieuF suggested I should post the code.
This snippet produces an error. It's not the most idiomatic code, but I wrote it that way to test my environment. I tried it as a single file and as separate files. It DOES work with scalac.
import swing._
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
object Hello {
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
BUT, if I nest the definition of HelloFrame within Hello, it works. This snippet runs perfectly:
import swing._
object Hello {
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
For me, the problem was that there was a build error (see Problems tab) which was preventing compilation; oops! The reason you see the error is that the run macro proceeds despite the failed compilation step, and attempts to run class files it expects to be there; they don't exist because there was a build error preventing compilation, so it says it can't find Main (not compiled).
Problem goes away when build can complete successfully, i.e. errors are fixed.
I guess, theoretically, there may be more complicated reasons your build is not completing successfully that are not listed in Problems.
One possibility is that you are trying to launch using ctrl-F11, but from a different class.
The Scala Eclipse plugin does not obey the defaults for Java launching. In Preferences->Run/Debug->Launching, there are some options Launch Operation->Always Launch the previously selected application, etc. This currently does not work in the Scala eclipse plugin. To launch a specified main, you need to launch it from the editor for the class.
There has been a bug raised for this. http://scala-ide.assembla.com/spaces/scala-ide/tickets/1000023-scala-launch--does-not-follow-jdt-behaviour
EDIT: This is now (mostly) fixed.
For me it was Eclipse specific problem. I noticed that .class file wasn't built at all. So bin directory doesn't have compiled classes.
When I manually compiled *.scala file using *.sbt and copied it to bin directory it was working as expected.
I tried different tips and tricks and it wasn't worked until I reinstalled Scala plugin in Eclipse .
I'd solve similar problem by executig "Project->Clean.." with next automatically building.
I had the same error message with a Java application made by myself.
The problem was that I deleted (though inside Eclipse) a jar that belonged to the Java build path, without deleting it from the Java build path (project's Properties window). When I did it the class could compile and run again.
Make sure that the .class files exist, usually below the bin directory.
In particular, if you have errors in unrelated files in the same project then the compilation may fail, and no .class files will be produced.
There can be the case of projects, containing errors, added to the build path of the application which prevents the completion of successful compilation. Make sure you remove any such project from the build path before running the application.
Removing these projects solved the problem for me.
Do you have a proper build tool setup? Like sbt have you installed it?
You can check its version by $sbt --version
If it is not setup you can download from here http://www.scala-sbt.org/download.html
You might have to restart your eclipse after installation.
Just copy your XXX.scala file code. Remove the package and create a new Scala Class. Paste your XXX.scala code. (If you are using maven, do a maven clean and build.) Run configuration again. This works for me.
I have faced this issue. I have just deleted the package name, created scala class, Written the same code, Set Build to "Build Automatically". Finally, It works perfectly fine.
Check scala-ide.log
For me the issue was that there were errors on:
AppData\Local\Temp\sbt_10d322fb\xsbt\ClassName.scala:16: error: not found: value enteringPhase
enteringPhase(currentRun.flattenPhase.next) { s fullName separator }
If you are using Intellij, mark directory as source root