1

I try to use the Maven project throw downloading the tamplate from web side. I have already use below command to create the gui files and had succeed.

 mvn cn1:create-gui-form -DclassName=com.example.myapp.MyGUI

Then, I use below command to show the GUI builder tool and add two buttons.

 mvn cn1:guibuilder -DclassName=com.example.myapp.MyGUI

Third, I program as below in main app but the buttons do not show.

 public class MyApp extends Lifecycle {
   // Resources theme = UIManager.initFirstTheme("/theme");
    @Override
    public void runApp() {
//        Form hi = new Form("Hi World", BoxLayout.y());
//        Button helloButton = new Button("Hello World");
//        hi.add(helloButton);
//        helloButton.addActionListener(e -> hello());
//        hi.getToolbar().addMaterialCommandToSideMenu("Hello Command",
//        FontImage.MATERIAL_CHECK, 4, e -> hello());
       
        // 使用GUI Builder
        MyGUI hi = new MyGUI();
        hi.show();
    }

Below is my project structure:

enter image description here

Could any body help me?

Yao Chang
  • 31
  • 4
  • 1
    Did you press the save button in the GUI builder? When you press save it should update the code in the IDE, do you see the changes in the java source file of `MyGUI`? Do you see any output in the Maven console? – Shai Almog Nov 22 '22 at 03:19
  • Sir, thanks first. I had saved the gui builder. The strange thing is I got two MyGUI file. One is in the guibuilder\com\example\myapp another one is in the java\com\example\myapp. I used the Netbeans IDE. The auto generated code will update the MyGUI.java in guibuilder below one and the other one will not be updated auto. – Yao Chang Nov 23 '22 at 06:28
  • Both are good. One is an XML file containing the structured data. The other is your source file which in netbeans gets updated when you build the project. How are you building/running the project? Do you see warnings in the output related to GUI? – Shai Almog Nov 24 '22 at 03:27
  • Iget below warning: 'Some problems were encountered while building the effective model for com.example.myapp:myapp-javase:jar:1.0-SNAPSHOT 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.codenameone:codenameone-core:jar -> duplicate declaration of version (?) @ line 60, column 19 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.codenameone:codenameone-javase:jar -> duplicate declaration of version (?) @ line 70, column 19 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing – Yao Chang Nov 25 '22 at 04:31
  • @ShaiAlmog, I also get below warning: 'Dependency for proguard defined twice! This may lead to unexpected results: swing-worker:1.1 | swing-worker:1.1 Dependency for proguard defined twice! This may lead to unexpected results: sisu-guice:3.2.5 | sisu-guice:2.1.7 Dependency for proguard defined twice! This may lead to unexpected results: codenameone-cef:84.4.1-M3 | codenameone-cef:84.4.1-M3' – Yao Chang Nov 25 '22 at 06:21
  • Those aren't [ a problem](https://stackoverflow.com/a/73841730/756809). What's the command you use to run/build? Does it generate the source code for the GUI? There should be a printout in the build output. – Shai Almog Nov 26 '22 at 03:47
  • @ShaiAlmog, I used the command "mvn cn1:create-gui-form -DclassName=com.example.myapp.MyGUI" to create the two GUI files. Below warning is showen:[WARNING] Some problems were encountered while building the effective model for com.example.myapp:myapp-javase:jar:1.0-SNAPSHOT [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.codenameone:codenameone-core:jar -> duplicate declaration of version (?) @ line 60, column 19 – Yao Chang Nov 28 '22 at 00:23
  • [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.codenameone:codenameone-javase:jar -> duplicate declaration of version (?) @ line 70, column 19 [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. – Yao Chang Nov 28 '22 at 00:24
  • 1
    Yes but create GUI form will just create the files. When you save the XML is generated but the Java code isn't updated. When you run the project it should read the XML and generate the java sources in the GUI file. So you should see an applicable message in the run command. – Shai Almog Nov 28 '22 at 03:18
  • Sir,after I run the project nothing error except above I mention. Do you mean below info? --- codenameone-maven-plugin:7.0.86:generate-gui-sources (generate-gui-sources) @ myapp-common --- Generating GUI sources timeStr=1.0.0-1669598723903-1669594240205, lastTime=1.0.0-1669598723903-1669594240205 MyGUI.java unmodified, skipping – Yao Chang Nov 28 '22 at 07:27
  • Yes. That's odd. What's the content of the GUI file? It's an XML file. That means that when you change the UI in the GUI builder the file should update every time you save and include your changes. If not we need to figure out why not. Does the GUI builder print something to console as you save that might indicate the file it's writing to? Also, are there spaces or special non-latin characters in your path? The tools might have an issue with that. – Shai Almog Nov 29 '22 at 03:08
  • Sir, I try to add a button and save it and the console do not show anything. The XML file will auto generate the button. Then, I run the project. The button will auto add to MyGUI.java below the guibuilder folder but do not auto generate the code in another MyGUI.java below the source packages. The output console show as below: Generating GUI sources timeStr=1.0.0-1669598723903-1669787158291, lastTime=1.0.0-1669681504251-1669681320690 Processing GUI builder file: D:\NetBeansProject\MyApp\myapp\common\src\main\guibuilder\com\example\myapp\MyGUI.java – Yao Chang Nov 30 '22 at 06:00
  • Attempting to generate GUI sources for D:\NetBeansProject\MyApp\myapp\common\src\main\guibuilder\com\example\myapp\MyGUI.gui with System JAXB 11��� 30, 2022 1:47:15 銝�� javax.xml.bind.ContextFinder getDeprecatedSystemProperty WARNING: Using non-standard property: javax.xml.bind.context.factory. Property javax.xml.bind.JAXBContextFactory should be used instead. The path are not any space or special characters. – Yao Chang Nov 30 '22 at 06:00
  • The location of the .java source file should be in the `src/java` hierarchy if the file is generated outside of there it might be ignored by the compiler. Did you run maven in the right location? In the common or the main project directory? Are you using a package for the GUI class? Notice you MUST have a package! – Shai Almog Dec 01 '22 at 03:16
  • @ShaiAlmog, Sir, I do not know how to describe my project structure correctly. I past an picture in the topic content. Is it right hierarchy? I run maven in the main project directory. I have two GUI class, one is in the /java another one is in the /guibuilder just like the picture show. – Yao Chang Dec 02 '22 at 05:51
  • 1
    Gotcha, that looks like a bug in the GUI builder. I'm looking into it and will get back to you. – Shai Almog Dec 03 '22 at 05:49
  • @ShaiAlmog How is the case going? Is solved already? – Yao Chang Jan 10 '23 at 08:51
  • Last I checked Steve says the problem relates to the GUI builder in production being out of date. I'm not sure if this was fixed. Looking into this. – Shai Almog Jan 11 '23 at 04:17

1 Answers1

0

This should be fixed now. To force a new version you can do one of the following:

  • Run the cn1:update maven target to force an update

  • Delete the CodeNameOneBuildClient.jar from ~/.codenameone. Notice that ~ stands for your home directory

This should fix the problem and the GUI should generate into the right place.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • I do the mvn cn1:update in the project path. The result is the same. The GUI still can not generate into the right place. – Yao Chang Feb 07 '23 at 05:34
  • That's odd. What's the size of the guibuilder.jar file under your home directory? – Shai Almog Feb 08 '23 at 02:50
  • Did you also delete the CodeNameOneBuildClient.jar? – steve hannah Feb 08 '23 at 03:38
  • @stevehannah After i delete the jar file, I could not run the project. error is "Failed to execute goal com.codenameone:codenameone-maven-plugin:7.0.86:generate-gui-sources (generate-gui-sources) on project myapp-common: Execution generate-gui-sources of goal com.codenameone:codenameone-maven-plugin:7.0.86:generate-gui-sources failed: Plugin com.codenameone:codenameone-maven-plugin:7.0.86 or one of its dependencies could not be resolved: Could not find artifact com.codenameone:codenameone-buildclient:jar:8.0 at specified path C:\Users\Raden/.codenameone/CodeNameOneBuildClient.jar -> [Help 1]" – Yao Chang Feb 09 '23 at 06:55
  • @ShaiAlmog guibuilder.jar is 12.6MB. – Yao Chang Feb 09 '23 at 06:58
  • @YaoChang Can you check the size in bytes? The right size one should be 13303174 bytes which is 12.6mb but the size difference might be small. – Shai Almog Feb 10 '23 at 03:45
  • @ShaiAlmog 13,303,174 bytes is the file size. I think the size is correct. – Yao Chang Feb 13 '23 at 00:52
  • @stevehannah it seems the version matches the one on the servers... – Shai Almog Feb 13 '23 at 03:18